-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest-examples.js
72 lines (63 loc) · 1.69 KB
/
test-examples.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
"use strict";
const { readdirSync, statSync, readFileSync } = require("fs");
const { resolve, join } = require("path");
const { exec } = require("child_process");
let faastjsPackage;
async function execCmd(cmd, options) {
await new Promise((resolve, reject) =>
exec(cmd, options, (err, stdout, stderr) => {
if (err) {
console.log(stdout);
if (stderr) {
console.log(stderr);
}
reject(err);
}
resolve();
})
);
}
async function runTest(test) {
try {
await execCmd("npm install", { cwd: test });
if (faastjsPackage) {
await execCmd(`npm install ${faastjsPackage}`, { cwd: test });
}
const pjs = JSON.parse(readFileSync(join(test, "package.json")));
if (pjs.scripts && pjs.scripts.build) {
await execCmd("npm run build", { cwd: test });
}
await execCmd("npm run test", { cwd: test });
console.log(`[pass] ${test}`);
} catch (err) {
console.log(`[fail] ${test}: ${err}`);
process.exit(1);
}
}
let queue = [];
async function work() {
const dir = queue.pop();
if (dir === undefined) {
return;
}
console.log(`testing ${dir}`);
await runTest(dir);
await work();
}
async function main() {
queue = readdirSync(".").filter(
entry =>
entry !== "aws-top-packages" &&
entry[0] !== "." &&
statSync(entry).isDirectory()
);
work();
work();
work();
work();
}
if (process.argv[2]) {
faastjsPackage = resolve(process.argv[2]);
console.log(`resolved ${faastjsPackage}`);
}
main();