-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathvitest.config.ts
79 lines (72 loc) · 2.35 KB
/
vitest.config.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
import {defineConfig, mergeConfig} from 'vitest/config';
import config from '../shared/src/tool/vitest-config.ts';
const ci = process.env['CI'] === 'true' || process.env['CI'] === '1';
function nameFromURL(url: string) {
// importer looks like file://....../packages/NAME/... and we want the NAME
return url.match(/\/packages\/([^/]+)/)?.[1] ?? 'unknown';
}
export function configForVersion(version: number, url: string) {
const name = nameFromURL(url);
return mergeConfig(config, {
test: {
name: `${name}/pg-${version}`,
browser: {enabled: false},
silent: false,
include: ['src/**/*.pg-test.?(c|m)[jt]s?(x)'],
exclude: ['src/**/*.test.?(c|m)[jt]s?(x)'],
globalSetup: [`../zero-cache/test/pg-${version}.ts`],
coverage: {
enabled: !ci, // Don't run coverage in continuous integration.
reporter: [['html'], ['clover', {file: 'coverage.xml'}]],
include: ['src/**'],
},
},
});
}
export function configForNoPg(url: string) {
const name = nameFromURL(url);
return mergeConfig(config, {
test: {
name: `${name}/no-pg`,
include: ['src/**/*.test.?(c|m)[jt]s?(x)'],
browser: {enabled: false},
silent: true,
coverage: {
enabled: !ci, // Don't run coverage in continuous integration.
reporter: [['html'], ['clover', {file: 'coverage.xml'}]],
include: ['src/**'],
},
},
});
}
// To run tests against a custom Postgres instance (e.g. Aurora), specify
// the connection string in the CUSTOM_PG environment variable, and optionally
// limit the test runner to the "custom-pg" project:
//
// CUSTOM_PG=postgresql://... npm run test -- --project custom-pg
export function configForCustomPg(url: string) {
if (process.env['CUSTOM_PG']) {
const name = nameFromURL(url);
return [
mergeConfig(config, {
test: {
name: `${name}/custom-pg`,
browser: {enabled: false},
silent: false,
include: ['src/**/*.pg-test.?(c|m)[jt]s?(x)'],
exclude: ['src/**/*.test.?(c|m)[jt]s?(x)'],
provide: {
// Referenced by ./src/test/db.ts
pgConnectionString: process.env['CUSTOM_PG'],
},
},
}),
];
}
return [];
}
export default defineConfig({
test: {
workspace: ['vitest.config.*.ts', ...configForCustomPg(import.meta.url)],
},
});