forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(browser): allow custom HTML path, respect plugins `transformInde…
…xHtml` (vitest-dev#6725)
- Loading branch information
1 parent
5df7414
commit 169028f
Showing
22 changed files
with
450 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 50 additions & 48 deletions
98
packages/browser/src/client/public/esm-client-injector.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,52 @@ | ||
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); | ||
(() => { | ||
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)); | ||
moduleCache.set(promise, { promise, evaluated: false }); | ||
return promise.finally(() => moduleCache.delete(promise)); | ||
} | ||
return module; | ||
} | ||
return module; | ||
} | ||
|
||
window.__vitest_browser_runner__ = { | ||
wrapModule, | ||
wrapDynamicImport: wrapModule, | ||
moduleCache, | ||
config: { __VITEST_CONFIG__ }, | ||
viteConfig: { __VITEST_VITE_CONFIG__ }, | ||
files: { __VITEST_FILES__ }, | ||
type: { __VITEST_TYPE__ }, | ||
contextId: { __VITEST_CONTEXT_ID__ }, | ||
testerId: { __VITEST_TESTER_ID__ }, | ||
provider: { __VITEST_PROVIDER__ }, | ||
providedContext: { __VITEST_PROVIDED_CONTEXT__ }, | ||
}; | ||
|
||
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]); | ||
} | ||
|
||
window.__vitest_browser_runner__ = { | ||
wrapModule, | ||
wrapDynamicImport: wrapModule, | ||
moduleCache, | ||
config: { __VITEST_CONFIG__ }, | ||
viteConfig: { __VITEST_VITE_CONFIG__ }, | ||
files: { __VITEST_FILES__ }, | ||
type: { __VITEST_TYPE__ }, | ||
contextId: { __VITEST_CONTEXT_ID__ }, | ||
testerId: { __VITEST_TESTER_ID__ }, | ||
provider: { __VITEST_PROVIDER__ }, | ||
providedContext: { __VITEST_PROVIDED_CONTEXT__ }, | ||
}; | ||
|
||
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]); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.