Skip to content

Commit 0c61153

Browse files
authored
test: canary test using Verdaccio (#5984)
1 parent dcc3e0e commit 0c61153

File tree

2 files changed

+68
-8
lines changed

2 files changed

+68
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"local-publish": "node ./scripts/verdaccio-publish/index.js",
3535
"test:all": "yarn build:all && jest --coverage --passWithNoTests && lerna run test --scope '@aws-sdk/{fetch-http-handler,hash-blob-browser}' && yarn test:versions && yarn test:integration",
3636
"test:ci": "lerna run test --since origin/main",
37-
"test:e2e": "node ./tests/e2e/index.js",
37+
"test:e2e": "node ./tests/e2e/index.js && node ./tests/canary/canary",
3838
"test:e2e:legacy": "cucumber-js --fail-fast",
3939
"test:e2e:legacy:since:release": "./tests/e2e-legacy/index.js",
4040
"test:functional": "jest --passWithNoTests --config tests/functional/jest.config.js && lerna run test:unit --scope \"@aws-sdk/client-*\"",

tests/canary/canary.js

+67-7
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111

1212
const fs = require("fs");
1313
const path = require("path");
14+
const { fork } = require("child_process");
1415
const { spawnProcess } = require("../../scripts/utils/spawn-process");
1516

16-
(async () => {
17-
const jsv3_root = path.join(__dirname, "..", "..");
18-
const testWorkspace = path.join(jsv3_root, "..", "canary-aws-sdk-js-v3");
17+
let verdaccioFork;
18+
19+
const jsv3_root = path.join(__dirname, "..", "..");
20+
const testWorkspace = path.join(jsv3_root, "..", "canary-aws-sdk-js-v3");
1921

22+
(async () => {
2023
if (fs.existsSync(testWorkspace)) {
2124
await spawnProcess("rm", ["-rf", testWorkspace], {});
2225
}
@@ -27,14 +30,71 @@ const { spawnProcess } = require("../../scripts/utils/spawn-process");
2730
cwd: testWorkspace,
2831
});
2932

33+
verdaccioFork = await runRegistry(["-c", path.join(jsv3_root, "verdaccio", "config.yaml")]);
34+
await localPublishChangedPackages(jsv3_root);
35+
3036
await spawnProcess("npm", ["init", "-y"], { cwd: testWorkspace });
31-
await spawnProcess("npm", ["install", `@aws-sdk/client-sts@latest`], { cwd: testWorkspace });
32-
await spawnProcess("npm", ["install", `@aws-sdk/client-s3@latest`], { cwd: testWorkspace });
33-
await spawnProcess("npm", ["install", `@aws-sdk/client-lambda@latest`], { cwd: testWorkspace });
37+
await spawnProcess("npm", ["install", `@aws-sdk/client-sts@ci`, "--registry", "http://localhost:4873/"], {
38+
cwd: testWorkspace,
39+
});
40+
await spawnProcess("npm", ["install", `@aws-sdk/client-s3@ci`, "--registry", "http://localhost:4873/"], {
41+
cwd: testWorkspace,
42+
});
43+
await spawnProcess("npm", ["install", `@aws-sdk/client-lambda@ci`, "--registry", "http://localhost:4873/"], {
44+
cwd: testWorkspace,
45+
});
3446

3547
fs.writeFileSync(path.join(testWorkspace, "app.js"), fs.readFileSync(path.join(__dirname, "canary-test-2.js")));
3648

3749
await spawnProcess("node", ["app.js"], {
3850
cwd: testWorkspace,
3951
});
40-
})();
52+
})().finally(async () => {
53+
if (verdaccioFork) {
54+
verdaccioFork.kill();
55+
}
56+
await spawnProcess("git", ["checkout", "--", "."], {
57+
cwd: jsv3_root,
58+
});
59+
});
60+
61+
function runRegistry(args = [], childOptions = {}) {
62+
return new Promise((resolve, reject) => {
63+
const childFork = fork(require.resolve("verdaccio/bin/verdaccio"), args, childOptions);
64+
childFork.on("message", (msg) => {
65+
if (msg.verdaccio_started) {
66+
resolve(childFork);
67+
}
68+
});
69+
childFork.on("error", (err) => reject([err]));
70+
childFork.on("disconnect", (err) => reject([err]));
71+
});
72+
}
73+
74+
async function localPublishChangedPackages(root) {
75+
await spawnProcess("rm", ["-rf", "verdaccio/storage"], { cwd: root, stdio: "inherit" });
76+
77+
const args = [
78+
"lerna",
79+
"publish",
80+
"prerelease",
81+
"--force-publish",
82+
"--preid",
83+
"ci",
84+
"--exact",
85+
"--registry",
86+
"http://localhost:4873/",
87+
"--yes",
88+
"--no-changelog",
89+
"--no-git-tag-version",
90+
"--no-push",
91+
"--no-git-reset",
92+
"--ignore-scripts",
93+
"--no-verify-access",
94+
"--concurrency",
95+
"8",
96+
"--dist-tag",
97+
"ci",
98+
];
99+
await spawnProcess("npx", args, { cwd: root, stdio: "inherit" });
100+
}

0 commit comments

Comments
 (0)