-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathesm-client-injector.js
54 lines (46 loc) · 1.53 KB
/
esm-client-injector.js
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
(() => {
const moduleCache = new Map();
function wrapModule(module) {
if (typeof module === "function") {
const promise = new Promise((resolve, reject) => {
if (typeof __vitest_mocker__ === "undefined")
return module().then(resolve, reject);
__vitest_mocker__.prepare().finally(() => {
module().then(resolve, reject);
});
});
moduleCache.set(promise, { promise, evaluated: false });
return promise.finally(() => moduleCache.delete(promise));
}
return module;
}
window.__vitest_browser_runner__ = {
wrapModule,
wrapDynamicImport: wrapModule,
moduleCache,
config: { __VITEST_CONFIG__ },
viteConfig: { __VITEST_VITE_CONFIG__ },
files: { __VITEST_FILES__ },
type: { __VITEST_TYPE__ },
sessionId: { __VITEST_SESSION_ID__ },
testerId: { __VITEST_TESTER_ID__ },
provider: { __VITEST_PROVIDER__ },
method: { __VITEST_METHOD__ },
providedContext: { __VITEST_PROVIDED_CONTEXT__ },
};
window.VITEST_API_TOKEN = { __VITEST_API_TOKEN__ };
const config = __vitest_browser_runner__.config;
if (config.testNamePattern)
config.testNamePattern = parseRegexp(config.testNamePattern);
function parseRegexp(input) {
// Parse input
const m = input.match(/(\/?)(.+)\1([a-z]*)/i);
// match nothing
if (!m) return /$^/;
// Invalid flags
if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3]))
return RegExp(input);
// Create the regular expression
return new RegExp(m[2], m[3]);
}
})();