-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathvitest.config.ts
More file actions
134 lines (128 loc) · 3.71 KB
/
Copy pathvitest.config.ts
File metadata and controls
134 lines (128 loc) · 3.71 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { cpus } from 'node:os';
import path from 'path';
import { defineConfig } from 'vitest/config';
const isCI = !!process.env.CI;
const cpuCount = cpus().length;
const MAX_CI_THREADS = 12;
const MAX_LOCAL_THREADS = 16;
// Calculate optimal threads based on environment
// CI: Cap at 12 threads, use 85% of available CPUs (min 4) to avoid over-subscription
const ciThreads = Math.min(
MAX_CI_THREADS,
Math.max(4, Math.floor(cpuCount * 0.85)),
);
// Local: Cap at 16 threads, use 100% of available CPUs (min 4) for maximum speed
const localThreads = Math.min(MAX_LOCAL_THREADS, Math.max(4, cpuCount));
export default defineConfig({
resolve: {
alias: [
{
find: 'razorpay',
replacement: path.resolve(__dirname, './__mocks__/razorpay.ts'),
},
{
find: 'utils/useLocalstorage',
replacement: path.resolve(__dirname, './__mocks__/useLocalstorage.ts'),
},
{
find: 'components/Loader/Loader',
replacement: path.resolve(__dirname, './__mocks__/Loader.tsx'),
},
{
find: 'components',
replacement: path.resolve(__dirname, './__mocks__/components_mock'),
},
{
find: /^@apollo\/client$/,
replacement: path.resolve(
__dirname,
'./__mocks__/apollo-client-proxy.ts',
),
},
{
find: '~/src/graphql/builder',
replacement: path.resolve(__dirname, './__mocks__/builder.ts'),
},
{
find: '~/src/utilities/TalawaGraphQLError',
replacement: path.resolve(
__dirname,
'./__mocks__/TalawaGraphQLError.ts',
),
},
{
find: /^~\/(.*)$/,
replacement: path.resolve(__dirname, './$1'),
},
{
find: '~',
replacement: path.resolve(__dirname, './'),
},
],
},
test: {
globals: true,
environment: 'node',
include: [
'test/**/*.{test,spec}.{js,jsx,ts,tsx}',
'plugins/**/test/**/*.{test,spec}.{js,jsx,ts,tsx}',
],
exclude: [
'**/node_modules/**',
'dist/**',
'coverage/**',
'docs/**',
'**/*.d.ts',
'plugin-zips/**',
],
setupFiles: ['test/setup/globalMocks.ts', 'test/setup/reactTestSetup.ts'],
// Vitest v4 Migration: poolOptions removed, replaced by top-level worker options
maxWorkers: isCI ? ciThreads : localThreads,
isolate: true,
maxConcurrency: isCI ? ciThreads : localThreads,
fileParallelism: true,
sequence: {
shuffle: false,
concurrent: false,
},
coverage: {
provider: 'v8',
reporter: ['text', 'lcov', 'html', 'json'],
reportsDirectory: './coverage/vitest',
exclude: [
'node_modules/**',
'dist/**',
'coverage/**',
'docs/**',
'**/*.d.ts',
'**/*.{test,spec}.{js,ts,tsx,jsx}',
'plugin-zips/**',
'scripts/docs/**',
'scripts/githooks/**',
'**/*.config.{js,ts}',
'**/index.{js,ts}',
'test/**',
'**/__mocks__/**',
'**/testUtils.{ts,tsx}',
'**/setupTests.ts',
],
thresholds: {
lines: 80,
functions: 70,
branches: 78,
statements: 80,
},
},
// Test timeouts - configurable via env vars
// CI environments can be slower; local runs typically complete in <1s per test
// Packaging tests do actual zip operations which can vary in duration
testTimeout: parseInt(
process.env.VITEST_TEST_TIMEOUT || (process.env.CI ? '30000' : '10000'),
10,
), // 10s default, 30s on CI unless VITEST_TEST_TIMEOUT overrides
hookTimeout: parseInt(
process.env.VITEST_HOOK_TIMEOUT || (process.env.CI ? '10000' : '5000'),
10,
), // 5s default, 10s on CI
},
});