Skip to content

Commit 026b301

Browse files
author
Szymon.Poltorak
committed
refactor(testing): enhance documentation and Vitest configuration setup
1 parent 38b7a6e commit 026b301

File tree

6 files changed

+99
-140
lines changed

6 files changed

+99
-140
lines changed

testing/test-setup-config/README.md

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ Standardized Vitest configuration for the Code PushUp monorepo.
44

55
### Usage
66

7-
**Unit tests:**
7+
#### Unit tests:
88

99
```typescript
1010
import { createUnitTestConfig } from '@code-pushup/test-setup-config';
1111

1212
export default createUnitTestConfig('my-package');
1313
```
1414

15-
**Integration tests:**
15+
#### Integration tests:
1616

1717
```typescript
1818
import { createIntTestConfig } from '@code-pushup/test-setup-config';
1919

2020
export default createIntTestConfig('my-package');
2121
```
2222

23-
**E2E tests:**
23+
#### E2E tests:
2424

2525
```typescript
2626
import { createE2ETestConfig } from '@code-pushup/test-setup-config';
@@ -32,18 +32,3 @@ export default createE2ETestConfig('my-e2e', {
3232
testTimeout: 60_000,
3333
});
3434
```
35-
36-
### Advanced: Overriding Config
37-
38-
For edge cases, use the spread operator to override any property:
39-
40-
```typescript
41-
const baseConfig = createE2ETestConfig('my-e2e');
42-
export default {
43-
...baseConfig,
44-
test: {
45-
...(baseConfig as any).test,
46-
globalSetup: ['./custom-setup.ts'],
47-
},
48-
};
49-
```

testing/test-setup-config/src/lib/vitest-config-factory.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CoverageOptions, InlineConfig } from 'vitest';
1+
import type { CoverageOptions } from 'vitest';
22
import { type UserConfig as ViteUserConfig, defineConfig } from 'vitest/config';
33
import { getSetupFiles } from './vitest-setup-files.js';
44
import { tsconfigPathAliases } from './vitest-tsconfig-path-aliases.js';
@@ -9,8 +9,6 @@ export type E2ETestOptions = {
99
testTimeout?: number;
1010
};
1111

12-
export type VitestConfig = ViteUserConfig & { test?: InlineConfig };
13-
1412
function getIncludePatterns(kind: TestKind): string[] {
1513
switch (kind) {
1614
case 'unit':
@@ -25,10 +23,6 @@ function getIncludePatterns(kind: TestKind): string[] {
2523
}
2624
}
2725

28-
function getGlobalSetup(kind: TestKind): string[] | undefined {
29-
return kind === 'e2e' ? undefined : ['../../global-setup.ts'];
30-
}
31-
3226
function buildCoverageConfig(
3327
projectKey: string,
3428
kind: TestKind,
@@ -37,13 +31,13 @@ function buildCoverageConfig(
3731
return undefined;
3832
}
3933

40-
const defaultExclude = ['mocks/**', '**/types.ts', 'perf/**'];
34+
const exclude = ['mocks/**', '**/types.ts', 'perf/**'];
4135
const reportsDirectory = `../../coverage/${projectKey}/${kind}-tests`;
4236

4337
return {
4438
reporter: ['text', 'lcov'],
4539
reportsDirectory,
46-
exclude: defaultExclude,
40+
exclude: exclude,
4741
};
4842
}
4943

@@ -54,7 +48,7 @@ export function createVitestConfig(
5448
): ViteUserConfig {
5549
const coverage = buildCoverageConfig(projectKey, kind);
5650

57-
const config: VitestConfig = {
51+
const config: ViteUserConfig = {
5852
cacheDir: `../../node_modules/.vite/${projectKey}`,
5953
test: {
6054
reporters: ['basic'],
@@ -67,7 +61,7 @@ export function createVitestConfig(
6761
poolOptions: { threads: { singleThread: true } },
6862
environment: 'node',
6963
include: getIncludePatterns(kind),
70-
globalSetup: getGlobalSetup(kind),
64+
globalSetup: ['../../global-setup.ts'],
7165
setupFiles: [...getSetupFiles(kind)],
7266
...(options?.testTimeout ? { testTimeout: options.testTimeout } : {}),
7367
...(coverage ? { coverage } : {}),

0 commit comments

Comments
 (0)