-
-
Notifications
You must be signed in to change notification settings - Fork 262
Expand file tree
/
Copy pathsetup.ts
More file actions
36 lines (28 loc) · 971 Bytes
/
setup.ts
File metadata and controls
36 lines (28 loc) · 971 Bytes
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
import { exec as originalExec } from 'node:child_process';
import util from 'node:util';
import type { TestProject, TestSpecification } from 'vitest/node';
const exec = util.promisify(originalExec);
function buildProject() {
return exec('pnpm run build');
}
function isBuildRequired(testFiles: TestSpecification[]) {
for (const file of testFiles) {
if (file.project.name === 'e2e' || file.project.name === 'smoke') {
return true;
}
}
return false;
}
export default async function setup(project: TestProject) {
// @ts-expect-error not typed
const pattern: string[] | undefined = project.vitest.filenamePattern;
const testFiles = await project.vitest.getRelevantTestSpecifications(pattern);
if (isBuildRequired(testFiles)) {
await buildProject();
}
project.onTestsRerun(async (testFiles) => {
if (isBuildRequired(testFiles)) {
await buildProject();
}
});
}