@dereekb/vitest 13.6.5 → 13.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +57 -1
- package/src/config.d.ts +55 -0
- package/src/config.js +186 -0
- package/src/config.js.map +1 -0
- package/src/setup-angular.d.ts +4 -0
- package/src/setup-angular.js +72 -0
- package/src/setup-angular.js.map +1 -0
- package/src/setup-firebase.d.ts +7 -0
- package/src/setup-firebase.js +44 -0
- package/src/setup-firebase.js.map +1 -0
- package/src/setup-nestjs.d.ts +6 -0
- package/src/setup-nestjs.js +7 -0
- package/src/setup-nestjs.js.map +1 -0
- package/src/setup-node.d.ts +6 -0
- package/src/setup-node.js +7 -0
- package/src/setup-node.js.map +1 -0
- package/src/setup-typings.d.ts +10 -0
- package/src/setup-typings.js +2 -0
- package/src/setup-typings.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,17 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/vitest",
|
|
3
|
-
"version": "13.6.
|
|
3
|
+
"version": "13.6.7",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
+
"@analogjs/vite-plugin-angular": ">=2.0.0",
|
|
6
|
+
"@analogjs/vitest-angular": ">=2.0.0",
|
|
7
|
+
"@angular/compiler": ">=19.0.0",
|
|
8
|
+
"@angular/core": ">=19.0.0",
|
|
9
|
+
"@angular/platform-browser": ">=19.0.0",
|
|
10
|
+
"@nx/vite": ">=20.0.0",
|
|
5
11
|
"@vitest/expect": "4.1.0",
|
|
6
12
|
"axe-core": "^4.11.1",
|
|
7
13
|
"date-fns": "^4.0.0",
|
|
14
|
+
"resize-observer-polyfill": "^1.5.0",
|
|
15
|
+
"vite": ">=6.0.0",
|
|
8
16
|
"vitest": "4.1.0",
|
|
9
17
|
"vitest-axe": "^0.1.0"
|
|
10
18
|
},
|
|
11
19
|
"peerDependenciesMeta": {
|
|
20
|
+
"@analogjs/vite-plugin-angular": {
|
|
21
|
+
"optional": true
|
|
22
|
+
},
|
|
23
|
+
"@analogjs/vitest-angular": {
|
|
24
|
+
"optional": true
|
|
25
|
+
},
|
|
26
|
+
"@angular/compiler": {
|
|
27
|
+
"optional": true
|
|
28
|
+
},
|
|
29
|
+
"@angular/core": {
|
|
30
|
+
"optional": true
|
|
31
|
+
},
|
|
32
|
+
"@angular/platform-browser": {
|
|
33
|
+
"optional": true
|
|
34
|
+
},
|
|
35
|
+
"@nx/vite": {
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
12
38
|
"axe-core": {
|
|
13
39
|
"optional": true
|
|
14
40
|
},
|
|
41
|
+
"resize-observer-polyfill": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"vite": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
15
47
|
"vitest-axe": {
|
|
16
48
|
"optional": true
|
|
17
49
|
}
|
|
@@ -28,6 +60,30 @@
|
|
|
28
60
|
"./a11y": {
|
|
29
61
|
"types": "./src/a11y.d.ts",
|
|
30
62
|
"default": "./src/a11y.js"
|
|
63
|
+
},
|
|
64
|
+
"./config": {
|
|
65
|
+
"types": "./src/config.d.ts",
|
|
66
|
+
"default": "./src/config.js"
|
|
67
|
+
},
|
|
68
|
+
"./setup-node": {
|
|
69
|
+
"types": "./src/setup-node.d.ts",
|
|
70
|
+
"default": "./src/setup-node.js"
|
|
71
|
+
},
|
|
72
|
+
"./setup-nestjs": {
|
|
73
|
+
"types": "./src/setup-nestjs.d.ts",
|
|
74
|
+
"default": "./src/setup-nestjs.js"
|
|
75
|
+
},
|
|
76
|
+
"./setup-firebase": {
|
|
77
|
+
"types": "./src/setup-firebase.d.ts",
|
|
78
|
+
"default": "./src/setup-firebase.js"
|
|
79
|
+
},
|
|
80
|
+
"./setup-angular": {
|
|
81
|
+
"types": "./src/setup-angular.d.ts",
|
|
82
|
+
"default": "./src/setup-angular.js"
|
|
83
|
+
},
|
|
84
|
+
"./setup-typings": {
|
|
85
|
+
"types": "./src/setup-typings.d.ts",
|
|
86
|
+
"default": "./src/setup-typings.js"
|
|
31
87
|
}
|
|
32
88
|
},
|
|
33
89
|
"types": "./src/index.d.ts",
|
package/src/config.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ViteUserConfigFn } from 'vitest/config';
|
|
2
|
+
import { loadEnv } from 'vite';
|
|
3
|
+
type VitestTestConfig = NonNullable<Awaited<ReturnType<ViteUserConfigFn>>['test']>;
|
|
4
|
+
export interface DbxComponentsVitestPresetConfigOptions {
|
|
5
|
+
readonly type: 'angular' | 'firebase' | 'nestjs' | 'node';
|
|
6
|
+
readonly pathFromRoot: string;
|
|
7
|
+
readonly projectName: string;
|
|
8
|
+
/**
|
|
9
|
+
* The workspace root directory.
|
|
10
|
+
*
|
|
11
|
+
* Defaults to `process.cwd()`, which is the workspace root when Nx runs vitest.
|
|
12
|
+
*/
|
|
13
|
+
readonly rootDir?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Additional project-specific setup files to include.
|
|
16
|
+
*/
|
|
17
|
+
readonly projectSpecificSetupFiles?: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Additional model path ignore patterns.
|
|
20
|
+
*/
|
|
21
|
+
readonly modelPathIgnorePatterns?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* Optional prefix for the junit file name.
|
|
24
|
+
*/
|
|
25
|
+
readonly junitFilePrefix?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Whether or not to print the console trace.
|
|
28
|
+
*
|
|
29
|
+
* Defaults to true.
|
|
30
|
+
*/
|
|
31
|
+
readonly printConsoleTrace?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether or not firebase is used.
|
|
34
|
+
*
|
|
35
|
+
* Will also assert that the firebase environment is properly configured at runtime.
|
|
36
|
+
*/
|
|
37
|
+
readonly requiresFirebaseEnvironment?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Overrides the test configuration directly.
|
|
40
|
+
*/
|
|
41
|
+
readonly test?: Partial<Omit<VitestTestConfig, 'environment' | 'include' | 'exclude' | 'setupFiles' | 'reporters' | 'coverage' | 'name' | 'env' | 'coverage'>>;
|
|
42
|
+
/**
|
|
43
|
+
* Optional function to configure the environment.
|
|
44
|
+
*/
|
|
45
|
+
readonly configureEnv?: () => ReturnType<typeof loadEnv>;
|
|
46
|
+
/**
|
|
47
|
+
* Configures the JUnit reporter.
|
|
48
|
+
*/
|
|
49
|
+
readonly junitConfig?: () => {
|
|
50
|
+
suiteName?: string;
|
|
51
|
+
outputFilePrefix?: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export declare function createVitestConfig(options: DbxComponentsVitestPresetConfigOptions): import("vitest/config").ViteUserConfigFnObject;
|
|
55
|
+
export {};
|
package/src/config.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/// <reference types='vitest' />
|
|
2
|
+
import angular from '@analogjs/vite-plugin-angular';
|
|
3
|
+
import { defineConfig } from 'vitest/config';
|
|
4
|
+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
5
|
+
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
|
|
6
|
+
import { createRequire } from 'module';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
/**
|
|
9
|
+
* Map from setup entry point names to root-level shim file names.
|
|
10
|
+
*
|
|
11
|
+
* Vitest (particularly with the Angular vite plugin) requires setup files to be
|
|
12
|
+
* within or relative to the project tree. Direct absolute paths to package source
|
|
13
|
+
* files outside the project root are not loaded. The root-level shims re-export
|
|
14
|
+
* from `@dereekb/vitest/*` via vite's module resolution (which has tsconfig paths),
|
|
15
|
+
* so the actual code still lives in the package.
|
|
16
|
+
*/
|
|
17
|
+
const SETUP_SHIM_FILES = {
|
|
18
|
+
'setup-node': 'vitest.setup.node.ts',
|
|
19
|
+
'setup-nestjs': 'vitest.setup.nestjs.ts',
|
|
20
|
+
'setup-firebase': 'vitest.setup.firebase.ts',
|
|
21
|
+
'setup-angular': 'vitest.setup.angular.ts'
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Resolves a `@dereekb/vitest/*` setup file entry point to an absolute file path.
|
|
25
|
+
*
|
|
26
|
+
* When `@dereekb/vitest` is installed from npm, resolves directly to the package
|
|
27
|
+
* in `node_modules`. During workspace development, resolves to the root-level shim
|
|
28
|
+
* file which re-exports from the package source via vite's tsconfig path resolution.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // When @dereekb/vitest is installed from npm:
|
|
33
|
+
* // returns '/path/to/node_modules/@dereekb/vitest/src/setup-firebase.js'
|
|
34
|
+
* //
|
|
35
|
+
* // During workspace development:
|
|
36
|
+
* // returns '/path/to/workspace/vitest.setup.firebase.ts'
|
|
37
|
+
* resolveVitestSetupFile('setup-firebase', rootDir, pathFromRoot);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function resolveVitestSetupFile(name, rootDir, pathFromRoot) {
|
|
41
|
+
const _require = createRequire(path.resolve(rootDir, 'noop.js'));
|
|
42
|
+
const pathToRoot = path.relative(pathFromRoot, rootDir);
|
|
43
|
+
let result;
|
|
44
|
+
try {
|
|
45
|
+
result = _require.resolve(`@dereekb/vitest/${name}`);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
const shimFile = SETUP_SHIM_FILES[name];
|
|
49
|
+
if (shimFile) {
|
|
50
|
+
// Use a relative path from the project to the root shim.
|
|
51
|
+
// Vitest (particularly with the Angular vite plugin) requires setup files
|
|
52
|
+
// to be referenced via relative paths, not absolute paths.
|
|
53
|
+
result = path.join(pathToRoot, shimFile);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
result = path.join(pathToRoot, `packages/vitest/src/${name}.ts`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
export function createVitestConfig(options) {
|
|
62
|
+
const { configureEnv, type, pathFromRoot, projectName, projectSpecificSetupFiles, modelPathIgnorePatterns, test: testConfig, junitConfig, requiresFirebaseEnvironment, printConsoleTrace } = options;
|
|
63
|
+
const rootDir = options.rootDir ?? process.cwd();
|
|
64
|
+
const pathToRoot = path.relative(pathFromRoot, rootDir);
|
|
65
|
+
let environment = 'node';
|
|
66
|
+
let isolate = false;
|
|
67
|
+
let maxWorkers;
|
|
68
|
+
let pool;
|
|
69
|
+
const plugins = [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])];
|
|
70
|
+
const setupFiles = [];
|
|
71
|
+
let usesFirebase = requiresFirebaseEnvironment ?? false;
|
|
72
|
+
switch (type) {
|
|
73
|
+
case 'angular':
|
|
74
|
+
plugins.push(angular(), nxCopyAssetsPlugin(['*.md']));
|
|
75
|
+
// Angular setup must be loaded via a project-local setup file (projectSpecificSetupFiles)
|
|
76
|
+
// due to a limitation in the Angular vitest plugin that prevents setup files outside the
|
|
77
|
+
// project root from being processed correctly.
|
|
78
|
+
if (!projectSpecificSetupFiles?.length) {
|
|
79
|
+
throw new Error('projectSpecificSetupFiles is required for angular projects. The setup file should import from @dereekb/vitest/setup-angular.');
|
|
80
|
+
}
|
|
81
|
+
environment = 'jsdom';
|
|
82
|
+
isolate = true;
|
|
83
|
+
break;
|
|
84
|
+
case 'firebase':
|
|
85
|
+
environment = 'node';
|
|
86
|
+
usesFirebase = true;
|
|
87
|
+
setupFiles.push(resolveVitestSetupFile('setup-firebase', rootDir, pathFromRoot));
|
|
88
|
+
break;
|
|
89
|
+
case 'nestjs':
|
|
90
|
+
environment = 'node';
|
|
91
|
+
setupFiles.push(resolveVitestSetupFile('setup-nestjs', rootDir, pathFromRoot));
|
|
92
|
+
break;
|
|
93
|
+
case 'node':
|
|
94
|
+
environment = 'node';
|
|
95
|
+
setupFiles.push(resolveVitestSetupFile('setup-node', rootDir, pathFromRoot));
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (usesFirebase) {
|
|
99
|
+
const isWatchMode = process.argv.includes('--watch');
|
|
100
|
+
const configuredMaxWorkers = testConfig?.maxWorkers;
|
|
101
|
+
const useMultipleWorkers = !isWatchMode && configuredMaxWorkers != null && Number(configuredMaxWorkers) > 1;
|
|
102
|
+
if (useMultipleWorkers) {
|
|
103
|
+
/**
|
|
104
|
+
* Use forks pool so each worker gets its own process with isolated process.env.
|
|
105
|
+
*
|
|
106
|
+
* The firebase test infrastructure calls rollNewGCloudProjectEnvironmentVariable() which
|
|
107
|
+
* writes to process.env (GCLOUD_PROJECT, GCLOUD_TEST_PROJECT, FIREBASE_CONFIG) during
|
|
108
|
+
* each test suite's setup. With the default threads pool, worker_threads share process.env,
|
|
109
|
+
* causing workers to clobber each other's project IDs and Firestore clients.
|
|
110
|
+
*
|
|
111
|
+
* See: https://github.com/firebase/firebase-tools-ui/issues/996#issuecomment-3954367815
|
|
112
|
+
*/
|
|
113
|
+
pool = 'forks';
|
|
114
|
+
}
|
|
115
|
+
// TODO: Also check that Firebase is currently running via env variables
|
|
116
|
+
}
|
|
117
|
+
if (projectSpecificSetupFiles) {
|
|
118
|
+
setupFiles.push(...projectSpecificSetupFiles);
|
|
119
|
+
}
|
|
120
|
+
const exclude = [];
|
|
121
|
+
if (modelPathIgnorePatterns?.length) {
|
|
122
|
+
exclude.push(...modelPathIgnorePatterns);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Keep Jest behavior of running beforeEach/afterEach in order.
|
|
126
|
+
*
|
|
127
|
+
* See: https://vitest.dev/guide/migration.html#hooks
|
|
128
|
+
*/
|
|
129
|
+
const jestSequenceHooksBehavior = 'stack';
|
|
130
|
+
return defineConfig(() => {
|
|
131
|
+
const configuredEnv = configureEnv?.();
|
|
132
|
+
const env = {
|
|
133
|
+
...configuredEnv,
|
|
134
|
+
/**
|
|
135
|
+
* FIREBASE_CONFIG must be set before any Firebase SDK code runs.
|
|
136
|
+
* With the forks pool, forked processes may not inherit env vars set by setup files
|
|
137
|
+
* in the parent process. Setting it here via test.env ensures every worker has it.
|
|
138
|
+
*/
|
|
139
|
+
...(usesFirebase ? { FIREBASE_CONFIG: process.env['FIREBASE_CONFIG'] ?? JSON.stringify({ projectId: 'temp' }) } : {})
|
|
140
|
+
};
|
|
141
|
+
const { suiteName, outputFilePrefix: junitFilePrefix } = junitConfig?.() ?? {};
|
|
142
|
+
// https://vitest.dev/guide/reporters.html#junit-reporter
|
|
143
|
+
const reporters = ['default', ['junit', { suiteName, includeConsoleOutput: false, outputFile: `${rootDir}/.reports/junit/${junitFilePrefix ?? ''}${projectName}.junit.xml` }]];
|
|
144
|
+
return {
|
|
145
|
+
root: pathFromRoot,
|
|
146
|
+
cacheDir: `${pathToRoot}/node_modules/.vite/${projectName}`,
|
|
147
|
+
plugins,
|
|
148
|
+
server: {
|
|
149
|
+
fs: {
|
|
150
|
+
strict: false
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
test: {
|
|
154
|
+
printConsoleTrace: printConsoleTrace ?? true,
|
|
155
|
+
passWithNoTests: true,
|
|
156
|
+
watch: false,
|
|
157
|
+
globals: true,
|
|
158
|
+
pool,
|
|
159
|
+
maxWorkers,
|
|
160
|
+
...testConfig,
|
|
161
|
+
env,
|
|
162
|
+
name: projectName,
|
|
163
|
+
environment,
|
|
164
|
+
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
165
|
+
exclude,
|
|
166
|
+
setupFiles,
|
|
167
|
+
reporters,
|
|
168
|
+
/**
|
|
169
|
+
* Is is important to isolate while using --watch so that all file changes are properly processed/compiled.
|
|
170
|
+
*
|
|
171
|
+
* See: https://github.com/vitest-dev/vitest/issues/9499
|
|
172
|
+
*/
|
|
173
|
+
isolate: testConfig?.isolate ?? (process.argv.includes('--watch') ? true : isolate),
|
|
174
|
+
coverage: {
|
|
175
|
+
reportsDirectory: `${pathToRoot}/coverage/${projectName}`,
|
|
176
|
+
provider: 'v8'
|
|
177
|
+
},
|
|
178
|
+
sequence: {
|
|
179
|
+
...testConfig?.sequence,
|
|
180
|
+
hooks: jestSequenceHooksBehavior
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../packages/vitest/src/config.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,OAAO,OAAO,MAAM,+BAA+B,CAAC;AACpD,OAAO,EAAE,YAAY,EAAoB,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAE5E,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,IAAI,MAAM,MAAM,CAAC;AAiExB;;;;;;;;GAQG;AACH,MAAM,gBAAgB,GAA2B;IAC/C,YAAY,EAAE,sBAAsB;IACpC,cAAc,EAAE,wBAAwB;IACxC,gBAAgB,EAAE,0BAA0B;IAC5C,eAAe,EAAE,yBAAyB;CAC3C,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,SAAS,sBAAsB,CAAC,IAAY,EAAE,OAAe,EAAE,YAAoB;IACjF,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;IACjE,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAExD,IAAI,MAAc,CAAC;IAEnB,IAAI,CAAC;QACH,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,mBAAmB,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,QAAQ,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAExC,IAAI,QAAQ,E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BACV,SAAS;gBACT;;;;mBAIG;gBACH,OAAO,EAAE,UAAU,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;gBACnF,QAAQ,EAAE;oBACR,gBAAgB,EAAE,GAAG,UAAU,aAAa,WAAW,EAAE;oBACzD,QAAQ,EAAE,IAAa;iBACxB;gBACD,QAAQ,EAAE;oBACR,GAAG,UAAU,EAAE,QAAQ;oBACvB,KAAK,EAAE,yBAAyB;iBACjC;aACF;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vitest setup for Angular projects.
|
|
3
|
+
*
|
|
4
|
+
* Importing this file runs the full Angular test setup: firebase setup,
|
|
5
|
+
* Angular compiler + zone.js, a11y matchers, TestBed initialization,
|
|
6
|
+
* and JSDOM polyfills.
|
|
7
|
+
*
|
|
8
|
+
* Due to a limitation in the Angular vitest plugin, this must be imported
|
|
9
|
+
* from a project-local setup file (e.g., `src/test-setup.ts`) referenced
|
|
10
|
+
* via `projectSpecificSetupFiles`, not loaded directly as a `setupFile`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // src/test-setup.ts
|
|
15
|
+
* import '@dereekb/vitest/setup-angular';
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import { vi } from 'vitest';
|
|
19
|
+
import './setup-firebase.js';
|
|
20
|
+
import '@angular/compiler';
|
|
21
|
+
import '@analogjs/vitest-angular/setup-zone';
|
|
22
|
+
import '@dereekb/vitest/a11y';
|
|
23
|
+
import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing';
|
|
24
|
+
import { getTestBed } from '@angular/core/testing';
|
|
25
|
+
getTestBed().initTestEnvironment(BrowserTestingModule, platformBrowserTesting());
|
|
26
|
+
/**
|
|
27
|
+
* Must add TextEncoder/TextDecoder to the globals since it is not available in JSDOM by default.
|
|
28
|
+
*
|
|
29
|
+
* https://github.com/firebase/firebase-js-sdk/issues/7845
|
|
30
|
+
*/
|
|
31
|
+
import { TextEncoder, TextDecoder } from 'util';
|
|
32
|
+
global.TextEncoder = TextEncoder;
|
|
33
|
+
global.TextDecoder = TextDecoder;
|
|
34
|
+
// Same with these: https://github.com/jsdom/jsdom/issues/1724
|
|
35
|
+
global.fetch = fetch;
|
|
36
|
+
global.Headers = Headers;
|
|
37
|
+
global.Request = Request;
|
|
38
|
+
global.Response = Response;
|
|
39
|
+
/**
|
|
40
|
+
* Fix for lack of TransformStream in JSDOM
|
|
41
|
+
*/
|
|
42
|
+
import { TransformStream } from 'node:stream/web';
|
|
43
|
+
// Occured once @zip.js/zip.js was added to dependencies
|
|
44
|
+
global.TransformStream = TransformStream;
|
|
45
|
+
/**
|
|
46
|
+
* Fix for lack of ResizeObserver in JSDOM by default
|
|
47
|
+
*
|
|
48
|
+
* https://github.com/jsdom/jsdom/issues/3368
|
|
49
|
+
*/
|
|
50
|
+
import ResizeObserver from 'resize-observer-polyfill';
|
|
51
|
+
global.ResizeObserver = ResizeObserver;
|
|
52
|
+
// https://stackoverflow.com/questions/39830580/jest-test-fails-typeerror-window-matchmedia-is-not-a-function
|
|
53
|
+
var window;
|
|
54
|
+
if (!window) {
|
|
55
|
+
window = global;
|
|
56
|
+
}
|
|
57
|
+
if (window) {
|
|
58
|
+
Object.defineProperty(window, 'matchMedia', {
|
|
59
|
+
writable: true,
|
|
60
|
+
value: vi.fn().mockImplementation((query) => ({
|
|
61
|
+
matches: false,
|
|
62
|
+
media: query,
|
|
63
|
+
onchange: null,
|
|
64
|
+
addListener: vi.fn(), // Deprecated
|
|
65
|
+
removeListener: vi.fn(), // Deprecated
|
|
66
|
+
addEventListener: vi.fn(),
|
|
67
|
+
removeEventListener: vi.fn(),
|
|
68
|
+
dispatchEvent: vi.fn()
|
|
69
|
+
}))
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=setup-angular.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-angular.js","sourceRoot":"","sources":["../../../../packages/vitest/src/setup-angular.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC5B,OAAO,qBAAqB,CAAC;AAE7B,OAAO,mBAAmB,CAAC;AAC3B,OAAO,qCAAqC,CAAC;AAC7C,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AACjG,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,UAAU,EAAE,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,sBAAsB,EAAE,CAAC,CAAC;AAEjF;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAC/C,MAAc,CAAC,WAAW,GAAG,WAAW,CAAC;AACzC,MAAc,CAAC,WAAW,GAAG,WAAW,CAAC;AAE1C,8DAA8D;AAC7D,MAAc,CAAC,KAAK,GAAG,KAAK,CAAC;AAC7B,MAAc,CAAC,OAAO,GAAG,OAAO,CAAC;AACjC,MAAc,CAAC,OAAO,GAAG,OAAO,CAAC;AACjC,MAAc,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAEpC;;GAEG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,wDAAwD;AACvD,MAAc,CAAC,eAAe,GAAG,eAAe,CAAC;AAElD;;;;GAIG;AACH,OAAO,cAAc,MAAM,0BAA0B,CAAC;AACrD,MAAc,CAAC,cAAc,GAAG,cAAc,CAAC;AAEhD,6GAA6G;AAC7G,IAAI,MAAM,CAAC;AAEX,IAAI,CAAC,MAAM,EAAE,CAAC;IACZ,MAAM,GAAG,MAAM,CAAC;AAClB,CAAC;AAED,IAAI,MAAM,EAAE,CAAC;IACX,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE;QAC1C,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC;YACpD,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,KAAK;YACZ,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,aAAa;YACnC,cAAc,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,aAAa;YACtC,gBAAgB,EAAE,EAAE,CAAC,EAAE,EAAE;YACzB,mBAAmB,EAAE,EAAE,CAAC,EAAE,EAAE;YAC5B,aAAa,EAAE,EAAE,CAAC,EAAE,EAAE;SACvB,CAAC,CAAC;KACJ,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vitest setup for Firebase projects.
|
|
3
|
+
*
|
|
4
|
+
* Imports the NestJS setup and adds Firebase-specific error suppression
|
|
5
|
+
* for known Firestore teardown errors.
|
|
6
|
+
*/
|
|
7
|
+
import './setup-nestjs.js';
|
|
8
|
+
/**
|
|
9
|
+
* Initialize FIREBASE_CONFIG for tests to prevent a warning for firebase not being initialized.
|
|
10
|
+
*/
|
|
11
|
+
process.env['FIREBASE_CONFIG'] = JSON.stringify({ projectId: 'temp' });
|
|
12
|
+
/**
|
|
13
|
+
* Checks whether the given error is a known Firestore teardown error that can be safely suppressed.
|
|
14
|
+
*
|
|
15
|
+
* These occur when the Firebase SDK has pending internal operations during test teardown:
|
|
16
|
+
* - Client SDK (firebase/firestore): "Firestore shutting down" (FirebaseError code: 'aborted')
|
|
17
|
+
* - Server SDK (@google-cloud/firestore): "The client has already been terminated"
|
|
18
|
+
*/
|
|
19
|
+
function isFirestoreTeardownError(reason) {
|
|
20
|
+
let result = false;
|
|
21
|
+
if (reason instanceof Error) {
|
|
22
|
+
const hasAbortedCode = 'code' in reason && reason.code === 'aborted';
|
|
23
|
+
const isClientTerminated = reason.message?.includes('client has already been terminated');
|
|
24
|
+
result = hasAbortedCode || isClientTerminated;
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
process.on('unhandledRejection', (reason) => {
|
|
29
|
+
if (isFirestoreTeardownError(reason)) {
|
|
30
|
+
console.warn('[vitest.setup.firebase] Suppressed Firestore teardown unhandled rejection:', reason);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// Re-throw non-Firebase unhandled rejections so Vitest still catches real issues
|
|
34
|
+
throw reason;
|
|
35
|
+
});
|
|
36
|
+
process.on('uncaughtException', (error) => {
|
|
37
|
+
if (isFirestoreTeardownError(error)) {
|
|
38
|
+
console.warn('[vitest.setup.firebase] Suppressed Firestore teardown uncaught exception:', error);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
// Re-throw non-Firebase uncaught exceptions so Vitest still catches real issues
|
|
42
|
+
throw error;
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=setup-firebase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-firebase.js","sourceRoot":"","sources":["../../../../packages/vitest/src/setup-firebase.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,mBAAmB,CAAC;AAE3B;;GAEG;AACH,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;AAEvE;;;;;;GAMG;AACH,SAAS,wBAAwB,CAAC,MAAe;IAC/C,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,IAAI,MAAM,YAAY,KAAK,EAAE,CAAC;QAC5B,MAAM,cAAc,GAAG,MAAM,IAAI,MAAM,IAAK,MAA2B,CAAC,IAAI,KAAK,SAAS,CAAC;QAC3F,MAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,oCAAoC,CAAC,CAAC;QAC1F,MAAM,GAAG,cAAc,IAAI,kBAAkB,CAAC;IAChD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAe,EAAE,EAAE;IACnD,IAAI,wBAAwB,CAAC,MAAM,CAAC,EAAE,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,4EAA4E,EAAE,MAAM,CAAC,CAAC;QACnG,OAAO;IACT,CAAC;IAED,iFAAiF;IACjF,MAAM,MAAM,CAAC;AACf,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAY,EAAE,EAAE;IAC/C,IAAI,wBAAwB,CAAC,KAAK,CAAC,EAAE,CAAC;QACpC,OAAO,CAAC,IAAI,CAAC,2EAA2E,EAAE,KAAK,CAAC,CAAC;QACjG,OAAO;IACT,CAAC;IAED,gFAAgF;IAChF,MAAM,KAAK,CAAC;AACd,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-nestjs.js","sourceRoot":"","sources":["../../../../packages/vitest/src/setup-nestjs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-node.js","sourceRoot":"","sources":["../../../../packages/vitest/src/setup-node.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,aAAa,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AllDateMatchers } from './lib/matcher.date.js';
|
|
2
|
+
import type { AxeMatchers } from './lib/matcher.a11y.js';
|
|
3
|
+
declare module 'vitest' {
|
|
4
|
+
interface Matchers<T = any> extends AllDateMatchers {
|
|
5
|
+
}
|
|
6
|
+
interface Assertion extends AxeMatchers {
|
|
7
|
+
}
|
|
8
|
+
interface AsymmetricMatchersContaining extends AxeMatchers {
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-typings.js","sourceRoot":"","sources":["../../../../packages/vitest/src/setup-typings.ts"],"names":[],"mappings":""}
|