Skip to content

Commit a72e87c

Browse files
poltorakSzymon.Poltorak
andauthored
refactor: common vitest configurations (#1107)
## Centralize and Standardize Vitest Configurations ### What Changed * New centralized configuration system: Created testing/test-setup-config package with a factory-based approach for generating Vitest configurations * Setup presets: Introduced modular setup file presets that can be composed for different test types (unit, integration, e2e) * Simplified configuration files: Refactored 6 existing Vitest config files to use the new centralized system, reducing them from verbose configurations to simple function calls ### Benefits * Eliminates duplication: Removes repetitive boilerplate across multiple vitest config files * Ensures consistency: Standardizes test configurations, coverage settings, and setup files across all packages * Improves maintainability: Changes to test configuration defaults now only need to be made in one place * Better developer experience: New configs are more readable and easier to customize with sensible defaults and preset combinations The new system provides `createUnitConfig`, `createIntConfig`, and `createE2eConfig` factory functions that automatically handle common configuration patterns while still allowing customization through override parameters. Relates to first part of #1065 --------- Co-authored-by: Szymon.Poltorak <szymon.poltorak@push-based.io>
1 parent c4b025c commit a72e87c

File tree

66 files changed

+1188
-1087
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1188
-1087
lines changed

e2e/ci-e2e/global-setup.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

e2e/ci-e2e/tsconfig.test.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"vitest.e2e.config.ts",
99
"tests/**/*.e2e.test.ts",
1010
"tests/**/*.d.ts",
11-
"mocks/**/*.ts",
12-
"global-setup.ts"
11+
"mocks/**/*.ts"
1312
]
1413
}

e2e/ci-e2e/vitest.e2e.config.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
1-
/// <reference types="vitest" />
2-
import { defineConfig } from 'vitest/config';
3-
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js';
1+
import { createE2ETestConfig } from '../../testing/test-setup-config/src/index.js';
42

5-
export default defineConfig({
6-
cacheDir: '../../node_modules/.vite/ci-e2e',
7-
test: {
8-
reporters: ['basic'],
9-
testTimeout: 60_000,
10-
globals: true,
11-
alias: tsconfigPathAliases(),
12-
pool: 'threads',
13-
poolOptions: { threads: { singleThread: true } },
14-
cache: {
15-
dir: '../../node_modules/.vitest',
16-
},
17-
environment: 'node',
18-
include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
19-
globalSetup: './global-setup.ts',
20-
setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'],
21-
},
3+
export default createE2ETestConfig('ci-e2e', {
4+
testTimeout: 60_000,
225
});

e2e/cli-e2e/vitest.e2e.config.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
/// <reference types="vitest" />
2-
import { defineConfig } from 'vitest/config';
3-
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js';
1+
import { createE2ETestConfig } from '../../testing/test-setup-config/src/index.js';
42

5-
export default defineConfig({
6-
cacheDir: '../../node_modules/.vite/cli-e2e',
7-
test: {
8-
reporters: ['basic'],
9-
testTimeout: 20_000,
10-
globals: true,
11-
alias: tsconfigPathAliases(),
12-
pool: 'threads',
13-
poolOptions: { threads: { singleThread: true } },
14-
cache: {
15-
dir: '../../node_modules/.vitest',
16-
},
17-
environment: 'node',
18-
include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
19-
setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'],
20-
},
3+
export default createE2ETestConfig('cli-e2e', {
4+
testTimeout: 20_000,
215
});
Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
1-
/// <reference types="vitest" />
2-
import { defineConfig } from 'vitest/config';
3-
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js';
1+
import { createE2ETestConfig } from '../../testing/test-setup-config/src/index.js';
42

5-
export default defineConfig({
6-
cacheDir: '../../node_modules/.vite/create-cli-e2e',
7-
test: {
8-
reporters: ['basic'],
9-
testTimeout: 20_000,
10-
hookTimeout: 20_000,
11-
globals: true,
12-
alias: tsconfigPathAliases(),
13-
pool: 'threads',
14-
poolOptions: { threads: { singleThread: true } },
15-
cache: {
16-
dir: '../../node_modules/.vitest',
17-
},
18-
environment: 'node',
19-
include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
20-
setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'],
21-
},
3+
export default createE2ETestConfig('create-cli-e2e', {
4+
testTimeout: 20_000,
225
});
Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
/// <reference types="vitest" />
2-
import { defineConfig } from 'vitest/config';
3-
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js';
1+
import { createE2ETestConfig } from '../../testing/test-setup-config/src/index.js';
42

5-
export default defineConfig({
6-
cacheDir: '../../node_modules/.vite/nx-plugin-e2e',
7-
test: {
8-
reporters: ['basic'],
9-
testTimeout: 80_000,
10-
globals: true,
11-
alias: tsconfigPathAliases(),
12-
pool: 'threads',
13-
poolOptions: { threads: { singleThread: true } },
14-
cache: {
15-
dir: '../../node_modules/.vitest',
16-
},
17-
environment: 'node',
18-
include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
19-
setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'],
20-
},
3+
export default createE2ETestConfig('nx-plugin-e2e', {
4+
testTimeout: 80_000,
215
});
Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
/// <reference types="vitest" />
2-
import { defineConfig } from 'vitest/config';
3-
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js';
1+
import { createE2ETestConfig } from '../../testing/test-setup-config/src/index.js';
42

5-
export default defineConfig({
6-
cacheDir: '../../node_modules/.vite/plugin-coverage-e2e',
7-
test: {
8-
reporters: ['basic'],
9-
testTimeout: 40_000,
10-
globals: true,
11-
alias: tsconfigPathAliases(),
12-
pool: 'threads',
13-
poolOptions: { threads: { singleThread: true } },
14-
cache: {
15-
dir: '../../node_modules/.vitest',
16-
},
17-
environment: 'node',
18-
include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
19-
setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'],
20-
},
3+
export default createE2ETestConfig('plugin-coverage-e2e', {
4+
testTimeout: 40_000,
215
});
Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
/// <reference types="vitest" />
2-
import { defineConfig } from 'vitest/config';
3-
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js';
1+
import { createE2ETestConfig } from '../../testing/test-setup-config/src/index.js';
42

5-
export default defineConfig({
6-
cacheDir: '../../node_modules/.vite/plugin-lighthouse-e2e',
7-
test: {
8-
reporters: ['basic'],
9-
testTimeout: 20_000,
10-
globals: true,
11-
alias: tsconfigPathAliases(),
12-
pool: 'threads',
13-
poolOptions: { threads: { singleThread: true } },
14-
cache: {
15-
dir: '../../node_modules/.vitest',
16-
},
17-
environment: 'node',
18-
include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
19-
setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'],
20-
},
3+
export default createE2ETestConfig('plugin-eslint-e2e', {
4+
testTimeout: 20_000,
215
});
Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
/// <reference types="vitest" />
2-
import { defineConfig } from 'vitest/config';
3-
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js';
1+
import { createE2ETestConfig } from '../../testing/test-setup-config/src/index.js';
42

5-
export default defineConfig({
6-
cacheDir: '../../node_modules/.vite/plugin-js-packages-e2e',
7-
test: {
8-
reporters: ['basic'],
9-
testTimeout: 120_000,
10-
globals: true,
11-
alias: tsconfigPathAliases(),
12-
pool: 'threads',
13-
poolOptions: { threads: { singleThread: true } },
14-
cache: {
15-
dir: '../../node_modules/.vitest',
16-
},
17-
environment: 'node',
18-
include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
19-
setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'],
20-
},
3+
export default createE2ETestConfig('plugin-js-packages-e2e', {
4+
testTimeout: 120_000,
215
});
Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
/// <reference types="vitest" />
2-
import { defineConfig } from 'vitest/config';
3-
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js';
1+
import { createE2ETestConfig } from '../../testing/test-setup-config/src/index.js';
42

5-
export default defineConfig({
6-
cacheDir: '../../node_modules/.vite/plugin-jsdocs-e2e',
7-
test: {
8-
reporters: ['basic'],
9-
testTimeout: 20_000,
10-
globals: true,
11-
alias: tsconfigPathAliases(),
12-
pool: 'threads',
13-
poolOptions: { threads: { singleThread: true } },
14-
cache: {
15-
dir: '../../node_modules/.vitest',
16-
},
17-
environment: 'node',
18-
include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
19-
setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'],
20-
},
3+
export default createE2ETestConfig('plugin-jsdocs-e2e', {
4+
testTimeout: 20_000,
215
});

0 commit comments

Comments
 (0)