-
Notifications
You must be signed in to change notification settings - Fork 87
/
e2e.js
83 lines (75 loc) · 2.21 KB
/
e2e.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const { execSync } = require("child_process");
const { readdirSync, readFileSync, existsSync } = require("fs");
const BROKEN_RECIPES = [
// TODO: this broke in v18
"nx-devkit-create-own-cli",
// TODO: migrate these to Storybook v7 since v6 is not supported by Nx
"storybook-publishing-strategies-multiple-frameworks",
"storybook-publishing-strategies-single-framework",
// TODO: I don't think these ever passed?
"astro-standalone",
"deno-deploy",
"dot-net-standalone",
"fastify-postgres",
"lit",
"nestjs-prisma",
"nextjs-trpc",
"nuxt-integrated",
"pnpm-workspace",
"rust",
"storybook-compodoc-angular",
"trpc-react-express",
];
function isRecipe(file) {
const cwd = `./${file.name}`;
return file.isDirectory() &&
!BROKEN_RECIPES.includes(file.name) &&
existsSync(`${cwd}/nx.json`) &&
// TODO(caleb): this might not be true for nx wrapper repos?
existsSync(`${cwd}/package.json`)
}
function checkLockfileForLocalhost(filePath) {
const content = readFileSync(filePath, "utf-8");
if (content.includes("localhost")) {
throw new Error(`${filePath} contains localhost url. Please update it to use a public url.`);
}
}
function installPackages(cwd) {
const files = readdirSync(cwd);
if (files.includes("pnpm-lock.yaml")) {
checkLockfileForLocalhost(`${cwd}/pnpm-lock.yaml`)
execSync("pnpm i", { cwd });
} else if (files.includes("yarn.lock")) {
checkLockfileForLocalhost(`${cwd}/yarn.lock`)
execSync("yarn", { cwd });
} else {
checkLockfileForLocalhost(`${cwd}/package-lock.json`)
execSync("npm ci --legacy-peer-deps", { cwd });
}
}
function runE2eTests(cwd) {
execSync("CI=true npx nx run-many --target=e2e --parallel=1", {
cwd,
stdio: [0, 1, 2]
});
}
function processAllExamples() {
const files = readdirSync(".", { withFileTypes: true });
const failures = [];
files.forEach(file => {
if (isRecipe(file)) {
const cwd = "./" + file.name;
console.log(cwd);
try {
installPackages(cwd);
runE2eTests(cwd);
} catch (ex) {
failures.push(file.name);
}
}
});
if (failures.length > 0) {
throw new Error(`E2E Tests Failed:\n${failures.join('\n')}`);
}
}
processAllExamples();