forked from opensumi/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-tests.ts
119 lines (103 loc) · 3.17 KB
/
run-tests.ts
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// 用来 debug 某个 packages 的测试有问题
// 该模块会一个个的跑每个 package 下的测试
import { join } from 'path';
import yargs from 'yargs';
import { command } from 'execa';
import { readdirSync, writeJSONSync, mkdirSync, readJSONSync, pathExistsSync, removeSync } from 'fs-extra';
import { pSeries } from '../packages/utils/src/promises';
const argv = yargs.argv;
const packagesDir = join(__dirname, '../packages');
const cacheDir = join(__dirname, '../.tests-cache');
const packagesDirNames = readdirSync(packagesDir);
class CheckPoint {
dirPath: string;
constructor(private name: string, clean?: boolean) {
this.dirPath = join(cacheDir, name);
if (clean) {
this.clean();
} else {
if (!pathExistsSync(this.dirPath)) {
mkdirSync(this.dirPath, { recursive: true });
}
}
}
getFilePath(name: string) {
return join(this.dirPath, name + '.json');
}
set(name: string, value: any) {
writeJSONSync(this.getFilePath(name), value, {
spaces: 2,
});
}
get(name: string) {
if (!pathExistsSync(this.getFilePath(name))) {
return null;
}
return readJSONSync(this.getFilePath(name));
}
clean() {
removeSync(this.dirPath);
mkdirSync(this.dirPath, { recursive: true });
}
}
const successCheckPoint = new CheckPoint('success');
const failCheckPoint = new CheckPoint('fail', true);
if (argv.noCache) {
successCheckPoint.clean();
}
const skipList = ((argv as any).skipList ?? '').split(',') || ([] as string[]);
const testResult = {};
const funcs = packagesDirNames.map((target) => {
return async () => {
console.log(`current jest module:`, target);
const result = {};
if (skipList.includes(target)) {
console.log(`${target} is in skip list`);
result['status'] = 'skipped';
testResult[target] = result;
return;
}
await Promise.all(
['jsdom', 'node'].map((v) =>
(async () => {
const checkPointKey = `${target}-${v}`;
if (successCheckPoint.get(checkPointKey)) {
console.log(`${checkPointKey} 命中 successCheckPoint,跳过`);
return;
}
const env = {};
if ((argv as any).strictPromise) {
env['EXIT_ON_UNHANDLED_REJECTION'] = 'true';
}
let cmd = `yarn test:module --module=${target} --project=${v}`;
if ((argv as any).serial) {
cmd += ' --no-runInBand';
}
console.log('cmd:', cmd, 'env:', env);
const runResult = await command(cmd, {
reject: false,
stdio: 'inherit',
shell: true,
env,
});
const info = {
info: runResult,
};
if (!runResult.failed) {
successCheckPoint.set(checkPointKey, info);
info['status'] = 'success';
} else {
info['status'] = 'failed';
failCheckPoint.set(checkPointKey, info);
}
result[v] = info;
})(),
),
);
console.log(`end module:`, target);
testResult[target] = result;
};
});
pSeries(funcs).then(() => {
writeJSONSync(join(cacheDir, 'tests.json'), testResult);
});