forked from module-federation/module-federation-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.spec.js
More file actions
83 lines (77 loc) · 2 KB
/
index.spec.js
File metadata and controls
83 lines (77 loc) · 2 KB
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 fs = require("fs");
const spawn = require("cross-spawn");
const { resolve } = require("path");
const isHiddenDirectory = function (path) {
return /(^|\/)\.[^\/\.]/g.test(path);
};
const blockDir = ["node_modules", "public", "dist"];
const folders = [
"basic-host-remote",
"bi-directional",
"startup-code",
"different-react-versions",
"self-healing",
"comprehensive-demo",
"server-side-rendering",
"server-side-render-only",
"dynamic-system-host",
"shared-context",
"shared-routing",
"shared-routes2",
"typescript",
"nested",
"nextjs-sidecar",
"version-discrepancy",
"dashboard-example",
"redux-reducer-injection",
"angular-universal-ssr",
"advanced-api/dynamic-remotes",
"advanced-api/automatic-vendor-sharing",
"nextjs-bi-directional",
"vue3-demo",
"nextjs",
];
function spawnAsPromise(cmd, args, options) {
return new Promise((resolve, reject) => {
const child = spawn(cmd, args, options);
child.on("close", (code) => {
code === 0 ? resolve(true) : reject(false);
});
child.on("error", () => {
reject(false);
});
});
}
function getFiles(source) {
const result = [];
function walk(src) {
const dirents = fs.readdirSync(src, { withFileTypes: true });
for (const dirent of dirents) {
if (
dirent.isDirectory() &&
!isHiddenDirectory(dirent.name) &&
!blockDir.includes(dirent.name)
) {
const resolvedPath = resolve(src, dirent.name);
const hasPkgJson = fs.existsSync(`${resolvedPath}/package.json`);
if (hasPkgJson) {
result.push(resolvedPath);
}
walk(resolvedPath);
}
}
}
walk(source);
return result;
}
for (const folder of folders) {
describe(`${folder}`, () => {
const apps = getFiles(resolve(__dirname, "..", folder));
for (app of apps) {
it(`${app} should build`, async () => {
const result = await spawnAsPromise("yarn", ["build"], { cwd: app });
expect(result).toEqual(true);
});
}
});
}