|
1 |
| -const moduleCache = new Map(); |
2 |
| - |
3 |
| -function wrapModule(module) { |
4 |
| - if (typeof module === "function") { |
5 |
| - const promise = new Promise((resolve, reject) => { |
6 |
| - if (typeof __vitest_mocker__ === "undefined") |
7 |
| - return module().then(resolve, reject); |
8 |
| - __vitest_mocker__.prepare().finally(() => { |
9 |
| - module().then(resolve, reject); |
| 1 | +(() => { |
| 2 | + const moduleCache = new Map(); |
| 3 | + |
| 4 | + function wrapModule(module) { |
| 5 | + if (typeof module === "function") { |
| 6 | + const promise = new Promise((resolve, reject) => { |
| 7 | + if (typeof __vitest_mocker__ === "undefined") |
| 8 | + return module().then(resolve, reject); |
| 9 | + __vitest_mocker__.prepare().finally(() => { |
| 10 | + module().then(resolve, reject); |
| 11 | + }); |
10 | 12 | });
|
11 |
| - }); |
12 |
| - moduleCache.set(promise, { promise, evaluated: false }); |
13 |
| - return promise.finally(() => moduleCache.delete(promise)); |
| 13 | + moduleCache.set(promise, { promise, evaluated: false }); |
| 14 | + return promise.finally(() => moduleCache.delete(promise)); |
| 15 | + } |
| 16 | + return module; |
14 | 17 | }
|
15 |
| - return module; |
16 |
| -} |
17 |
| - |
18 |
| -window.__vitest_browser_runner__ = { |
19 |
| - wrapModule, |
20 |
| - wrapDynamicImport: wrapModule, |
21 |
| - moduleCache, |
22 |
| - config: { __VITEST_CONFIG__ }, |
23 |
| - viteConfig: { __VITEST_VITE_CONFIG__ }, |
24 |
| - files: { __VITEST_FILES__ }, |
25 |
| - type: { __VITEST_TYPE__ }, |
26 |
| - contextId: { __VITEST_CONTEXT_ID__ }, |
27 |
| - testerId: { __VITEST_TESTER_ID__ }, |
28 |
| - provider: { __VITEST_PROVIDER__ }, |
29 |
| - providedContext: { __VITEST_PROVIDED_CONTEXT__ }, |
30 |
| -}; |
31 |
| - |
32 |
| -const config = __vitest_browser_runner__.config; |
33 |
| - |
34 |
| -if (config.testNamePattern) |
35 |
| - config.testNamePattern = parseRegexp(config.testNamePattern); |
36 |
| - |
37 |
| -function parseRegexp(input) { |
38 |
| - // Parse input |
39 |
| - const m = input.match(/(\/?)(.+)\1([a-z]*)/i); |
40 |
| - |
41 |
| - // match nothing |
42 |
| - if (!m) return /$^/; |
43 |
| - |
44 |
| - // Invalid flags |
45 |
| - if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3])) |
46 |
| - return RegExp(input); |
47 |
| - |
48 |
| - // Create the regular expression |
49 |
| - return new RegExp(m[2], m[3]); |
50 |
| -} |
| 18 | + |
| 19 | + window.__vitest_browser_runner__ = { |
| 20 | + wrapModule, |
| 21 | + wrapDynamicImport: wrapModule, |
| 22 | + moduleCache, |
| 23 | + config: { __VITEST_CONFIG__ }, |
| 24 | + viteConfig: { __VITEST_VITE_CONFIG__ }, |
| 25 | + files: { __VITEST_FILES__ }, |
| 26 | + type: { __VITEST_TYPE__ }, |
| 27 | + contextId: { __VITEST_CONTEXT_ID__ }, |
| 28 | + testerId: { __VITEST_TESTER_ID__ }, |
| 29 | + provider: { __VITEST_PROVIDER__ }, |
| 30 | + providedContext: { __VITEST_PROVIDED_CONTEXT__ }, |
| 31 | + }; |
| 32 | + |
| 33 | + const config = __vitest_browser_runner__.config; |
| 34 | + |
| 35 | + if (config.testNamePattern) |
| 36 | + config.testNamePattern = parseRegexp(config.testNamePattern); |
| 37 | + |
| 38 | + function parseRegexp(input) { |
| 39 | + // Parse input |
| 40 | + const m = input.match(/(\/?)(.+)\1([a-z]*)/i); |
| 41 | + |
| 42 | + // match nothing |
| 43 | + if (!m) return /$^/; |
| 44 | + |
| 45 | + // Invalid flags |
| 46 | + if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3])) |
| 47 | + return RegExp(input); |
| 48 | + |
| 49 | + // Create the regular expression |
| 50 | + return new RegExp(m[2], m[3]); |
| 51 | + } |
| 52 | +})(); |
0 commit comments