forked from krahets/hello-algo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_all.js
63 lines (51 loc) · 1.61 KB
/
test_all.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
import { bold, brightRed } from 'jsr:@std/fmt/colors';
import { expandGlob } from 'jsr:@std/fs';
import { relative, resolve } from 'jsr:@std/path';
/**
* @typedef {import('jsr:@std/fs').WalkEntry} WalkEntry
* @type {WalkEntry[]}
*/
const entries = [];
for await (const entry of expandGlob(
resolve(import.meta.dirname, './chapter_*/*.js')
)) {
entries.push(entry);
}
/** @type {{ status: Promise<Deno.CommandStatus>; stderr: ReadableStream<Uint8Array>; }[]} */
const processes = [];
for (const file of entries) {
const execute = new Deno.Command('node', {
args: [relative(import.meta.dirname, file.path)],
cwd: import.meta.dirname,
stdin: 'piped',
stdout: 'piped',
stderr: 'piped',
});
const process = execute.spawn();
processes.push({ status: process.status, stderr: process.stderr });
}
const results = await Promise.all(
processes.map(async (item) => {
const status = await item.status;
return { status, stderr: item.stderr };
})
);
/** @type {ReadableStream<Uint8Array>[]} */
const errors = [];
for (const result of results) {
if (!result.status.success) {
errors.push(result.stderr);
}
}
console.log(`Tested ${entries.length} files`);
console.log(`Found exception in ${errors.length} files`);
if (errors.length) {
console.log();
for (const error of errors) {
const reader = error.getReader();
const { value } = await reader.read();
const decoder = new TextDecoder();
console.log(`${bold(brightRed('error'))}: ${decoder.decode(value)}`);
}
throw new Error('Test failed');
}