Skip to content

Commit b81d0d2

Browse files
committed
test(canary): replace verdaccio canary test with client tests in canary mode
1 parent 37f1adc commit b81d0d2

File tree

6 files changed

+126
-155
lines changed

6 files changed

+126
-155
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ test-e2e: bundles
7272
yarn g:vitest run -c vitest.config.e2e.mts --retry=4 --test-timeout=60000
7373
make test-browser-cross-platform
7474
make test-bundlers
75+
make test-canary
7576

7677
test-x: test-browser-cross-platform
7778

@@ -89,6 +90,9 @@ reset-test-credentials:
8990
test-bundlers:
9091
(cd ./tests/bundlers && make build test)
9192

93+
test-canary:
94+
node ./tests/canary/canary-runner.js
95+
9296
build-s3-browser-bundle:
9397
node ./clients/client-s3/test/browser-build/esbuild
9498

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"pkg:changed": "node ./scripts/update-versions/getChangedPackages.mjs",
4141
"test:all": "yarn build:all && jest --passWithNoTests && lerna run test --scope '@aws-sdk/{fetch-http-handler,hash-blob-browser}' && yarn test:versions && yarn test:integration",
4242
"test:ci": "lerna run test --since origin/main",
43-
"test:e2e": "make test-e2e && node ./tests/canary/canary",
43+
"test:e2e": "make test-e2e",
4444
"test:e2e:legacy:preview": "exit 0",
4545
"test:e2e:legacy:since:release": "exit 0",
4646
"test:functional": "jest --passWithNoTests --config tests/functional/jest.config.js && lerna run test --scope \"@aws-sdk/client-*\"",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const assert = require("assert");
1+
const assert = require("node:assert");
22

33
/**
44
* This test asserts that prior to the installation of

tests/canary/canary-runner.js

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
const fs = require("node:fs");
2+
const path = require("node:path");
3+
const { glob } = require("glob");
4+
const { execSync } = require("node:child_process");
5+
6+
console.log("====", "canary runner", "====");
7+
8+
const root = path.join(__dirname, "..", "..");
9+
const canaryPath = path.join(root, "..", "canary-aws-sdk-js-v3");
10+
11+
if (fs.existsSync(canaryPath)) {
12+
fs.rmSync(canaryPath, { recursive: true });
13+
}
14+
fs.mkdirSync(canaryPath);
15+
fs.mkdirSync(path.join(canaryPath, "tests"));
16+
17+
const e2eFiles = glob.sync("clients/**/test/*.e2e.spec.ts", { cwd: root });
18+
19+
const dependencies = new Set();
20+
21+
for (const file of e2eFiles) {
22+
const content = fs.readFileSync(path.join(root, file), "utf-8");
23+
if (
24+
!content.includes('from "./') &&
25+
!content.includes('from "../') &&
26+
!content.includes('from "@aws-sdk/aws-util-test/src"')
27+
) {
28+
const dest = path.join(canaryPath, "tests", file);
29+
fs.mkdirSync(path.dirname(dest), { recursive: true });
30+
fs.copyFileSync(path.join(root, file), dest);
31+
32+
const importMatches = content.matchAll(/from ["']([^."'][^"']*)["']/g);
33+
for (const match of importMatches) {
34+
if (!match[1].startsWith("node:")) {
35+
const pkg = match[1].startsWith("@") ? match[1].split("/").slice(0, 2).join("/") : match[1].split("/")[0];
36+
dependencies.add(pkg);
37+
}
38+
}
39+
}
40+
}
41+
42+
const packageJson = {
43+
name: "canary-aws-sdk-js-v3",
44+
private: true,
45+
scripts: {
46+
canary: "vitest run --retry=4 --test-timeout=60000",
47+
},
48+
devDependencies: {
49+
...Object.fromEntries([...dependencies].sort().map((dep) => [dep, "latest"])),
50+
"@aws-sdk/config": "latest",
51+
"happy-dom": "20.8.3",
52+
vitest: "^4.0.17",
53+
},
54+
};
55+
56+
fs.writeFileSync(path.join(canaryPath, "package.json"), JSON.stringify(packageJson, null, 2));
57+
58+
const vitestConfig = `import { defineConfig } from "vitest/config";
59+
60+
export default defineConfig({
61+
resolve: {
62+
conditions: ["browser", "module", "import", "default"],
63+
mainFields: ["browser", "module", "main"],
64+
},
65+
test: {
66+
include: ["**/*.e2e.spec.ts"],
67+
exclude: [
68+
"**/*/node_modules/**/*.spec.ts",
69+
"node_modules",
70+
// doesn't support OPTIONS preflight.
71+
"tests/clients/client-data-pipeline/**/*.e2e.spec.ts",
72+
// requires .wav file.
73+
"tests/clients/client-transcribe-streaming/test/index.e2e.spec.ts",
74+
],
75+
setupFiles: ["vitest.browser.setup.mts"],
76+
environment: "happy-dom",
77+
},
78+
});
79+
`;
80+
81+
fs.writeFileSync(path.join(canaryPath, "vitest.config.mts"), vitestConfig);
82+
fs.copyFileSync(path.join(root, "vitest.nodejs.setup.mts"), path.join(canaryPath, "vitest.nodejs.setup.mts"));
83+
84+
fs.mkdirSync(path.join(canaryPath, "scripts", "browser-testing"), { recursive: true });
85+
fs.copyFileSync(path.join(root, "vitest.browser.setup.mts"), path.join(canaryPath, "vitest.browser.setup.mts"));
86+
fs.copyFileSync(
87+
path.join(root, "scripts", "browser-testing", "writeTestCredentials.mjs"),
88+
path.join(canaryPath, "scripts", "browser-testing", "writeTestCredentials.mjs")
89+
);
90+
91+
fs.copyFileSync(path.join(__dirname, "canary-preinstall.js"), path.join(canaryPath, "canary-preinstall.js"));
92+
execSync("node canary-preinstall.js", { cwd: canaryPath, stdio: "inherit" });
93+
94+
try {
95+
console.info("attempting npm install");
96+
execSync("npm install", { cwd: canaryPath, stdio: "inherit" });
97+
console.info("npm install completed");
98+
} catch (error) {
99+
// if npm installation fails, consider the issue transient.
100+
// It will be caught by a separate canary.
101+
console.error(error);
102+
console.info("letting npm installation error propagate to availability canary.");
103+
process.exit(0);
104+
}
105+
106+
execSync("node ./scripts/browser-testing/writeTestCredentials.mjs", { cwd: canaryPath, stdio: "inherit" });
107+
process.on("exit", () => {
108+
fs.rmSync(canaryPath, { recursive: true });
109+
});
110+
111+
try {
112+
console.info("attempting npm run canary");
113+
execSync("npm run canary", { cwd: canaryPath, stdio: "inherit" });
114+
console.info("canary tests completed");
115+
process.exit(0);
116+
} catch (error) {
117+
console.info("canary tests failed");
118+
console.error(error);
119+
process.exit(error.status || 1);
120+
}

tests/canary/canary-test-2.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/canary/canary.js

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)