This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestRunner.js
54 lines (46 loc) · 1.47 KB
/
testRunner.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
import fs from 'fs';
import glob from 'glob';
import { execSync } from 'child_process';
// get directories in src
const directories = fs
.readdirSync('./src/restapi', { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
/*
For each directory, run vitest sequentially.
This is done to make sure that the tests are isolated from which other.
Using no-threads parameter removes the per-module isolation as well, but
not using the no-threads parameter causes tests to fail beccause there
is no isolation at the test DB level and different tests can interefere
with each other's mutations.
*/
directories.forEach((dir) => {
glob(`./src/${dir}/*/.test.tsx`, (err, matches) => {
if (err) {
console.error(err);
return;
}
// if there are any matches, run vitest on this directory
if (matches.length > 0) {
console.log(`Running vitest on src/${dir}`);
execSync(`yarn vitest "src/${dir}/*/.test.{ts,tsx,js,jsx}"`, {
stdio: 'inherit',
});
}
});
});
directories.forEach((dir) => {
glob(`./src/restapi/${dir}/**/*.test.tsx`, (err, matches) => {
if (err) {
console.error(err);
throw Error(err);
}
// if there are any matches, run vitest on this directory
if (matches.length > 0) {
console.log(`Running vitest on src/${dir}`);
execSync(`yarn vitest run src/restapi/${dir} --no-threads`, {
stdio: 'inherit',
});
}
});
});