-
Notifications
You must be signed in to change notification settings - Fork 1
/
serve.mjs
47 lines (39 loc) · 1.05 KB
/
serve.mjs
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
import fs from "fs/promises";
import path from "path";
import { createServer } from "./util/create-server.mjs";
let onlyRunTest = process.argv.slice(2)[0];
if (!onlyRunTest) {
console.log('Please specify a test to run.');
process.exit(1);
}
if (onlyRunTest.startsWith('tests/')) {
onlyRunTest = onlyRunTest.slice(6);
}
const testCase = (await fs.readdir('./tests', { withFileTypes: true, recursive: true })).filter(dirent => {
return dirent.isFile() && dirent.name === 'style.css'
}).map(dirent => {
return path.relative('tests', dirent.path);
}).sort().find((x) => {
return x.includes(onlyRunTest);
});
if (!testCase) {
console.log('Test not found.');
process.exit(1);
}
console.log(`Testing ${testCase}...`);
const server = createServer(
['tests', ...testCase.split(path.sep)],
() => {
console.log('Image was requested.');
},
(e) => {
console.log('Server error.');
console.error(e);
},
(e) => {
console.log('Request handler error.');
console.error(e);
}
);
server.listen(8080);
console.log('Server listening on http://localhost:8080');