@vitest/browser
Advanced tools
Comparing version 1.5.3 to 1.6.0
@@ -5,2 +5,3 @@ import { fileURLToPath } from 'node:url'; | ||
import { coverageConfigDefaults } from 'vitest/config'; | ||
import { slash } from '@vitest/utils'; | ||
import MagicString from 'magic-string'; | ||
@@ -15,3 +16,54 @@ import { esmWalker } from '@vitest/utils/ast'; | ||
} | ||
const _UNC_REGEX = /^[/\\]{2}/; | ||
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/; | ||
const _DRIVE_LETTER_RE = /^[A-Za-z]:$/; | ||
const normalize = function(path) { | ||
if (path.length === 0) { | ||
return "."; | ||
} | ||
path = normalizeWindowsPath(path); | ||
const isUNCPath = path.match(_UNC_REGEX); | ||
const isPathAbsolute = isAbsolute(path); | ||
const trailingSeparator = path[path.length - 1] === "/"; | ||
path = normalizeString(path, !isPathAbsolute); | ||
if (path.length === 0) { | ||
if (isPathAbsolute) { | ||
return "/"; | ||
} | ||
return trailingSeparator ? "./" : "."; | ||
} | ||
if (trailingSeparator) { | ||
path += "/"; | ||
} | ||
if (_DRIVE_LETTER_RE.test(path)) { | ||
path += "/"; | ||
} | ||
if (isUNCPath) { | ||
if (!isPathAbsolute) { | ||
return `//./${path}`; | ||
} | ||
return `//${path}`; | ||
} | ||
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path; | ||
}; | ||
const join = function(...arguments_) { | ||
if (arguments_.length === 0) { | ||
return "."; | ||
} | ||
let joined; | ||
for (const argument of arguments_) { | ||
if (argument && argument.length > 0) { | ||
if (joined === void 0) { | ||
joined = argument; | ||
} else { | ||
joined += `/${argument}`; | ||
} | ||
} | ||
} | ||
if (joined === void 0) { | ||
return "."; | ||
} | ||
return normalize(joined.replace(/\/\/+/g, "/")); | ||
}; | ||
function cwd() { | ||
@@ -350,5 +402,2 @@ if (typeof process !== "undefined") { | ||
function replacer(code, values) { | ||
return code.replace(/{\s*(\w+)\s*}/g, (_, key) => values[key] ?? ""); | ||
} | ||
var index = (project, base = "/") => { | ||
@@ -382,2 +431,4 @@ const pkgRoot = resolve(fileURLToPath(import.meta.url), "../.."); | ||
}); | ||
let indexScripts; | ||
let testerScripts; | ||
server.middlewares.use(async (req, res, next) => { | ||
@@ -400,5 +451,8 @@ if (!req.url) | ||
if (url.pathname === base) { | ||
if (!indexScripts) | ||
indexScripts = await formatScripts(project.config.browser.indexScripts, server); | ||
const html2 = replacer(await runnerHtml, { | ||
__VITEST_FAVICON__: favicon, | ||
__VITEST_TITLE__: "Vitest Browser Runner", | ||
__VITEST_SCRIPTS__: indexScripts, | ||
__VITEST_INJECTOR__: injector | ||
@@ -412,5 +466,8 @@ }); | ||
const tests = decodedTestFile === "__vitest_all__" || !files.includes(decodedTestFile) ? "__vitest_browser_runner__.files" : JSON.stringify([decodedTestFile]); | ||
if (!testerScripts) | ||
testerScripts = await formatScripts(project.config.browser.testerScripts, server); | ||
const html = replacer(await testerHtml, { | ||
__VITEST_FAVICON__: favicon, | ||
__VITEST_TITLE__: "Vitest Browser Tester", | ||
__VITEST_SCRIPTS__: testerScripts, | ||
__VITEST_INJECTOR__: injector, | ||
@@ -550,3 +607,18 @@ __VITEST_APPEND__: ( | ||
} | ||
function replacer(code, values) { | ||
return code.replace(/{\s*(\w+)\s*}/g, (_, key) => values[key] ?? ""); | ||
} | ||
async function formatScripts(scripts, server) { | ||
if (!scripts?.length) | ||
return ""; | ||
const promises = scripts.map(async ({ content, src, async, id, type = "module" }, index) => { | ||
const srcLink = (src ? (await server.pluginContainer.resolveId(src))?.id : void 0) || src; | ||
const transformId = srcLink || join(server.config.root, `virtual__${id || `injected-${index}.js`}`); | ||
await server.moduleGraph.ensureEntryFromUrl(transformId); | ||
const contentProcessed = content && type === "module" ? (await server.pluginContainer.transform(content, transformId)).code : content; | ||
return `<script type="${type}"${async ? " async" : ""}${srcLink ? ` src="${slash(`/@fs/${srcLink}`)}"` : ""}>${contentProcessed || ""}<\/script>`; | ||
}); | ||
return (await Promise.all(promises)).join("\n"); | ||
} | ||
export { index as default }; |
{ | ||
"name": "@vitest/browser", | ||
"type": "module", | ||
"version": "1.5.3", | ||
"version": "1.6.0", | ||
"description": "Browser running for Vitest", | ||
@@ -46,3 +46,3 @@ "license": "MIT", | ||
"webdriverio": "*", | ||
"vitest": "1.5.3" | ||
"vitest": "1.6.0" | ||
}, | ||
@@ -63,3 +63,3 @@ "peerDependenciesMeta": { | ||
"sirv": "^2.0.4", | ||
"@vitest/utils": "1.5.3" | ||
"@vitest/utils": "1.6.0" | ||
}, | ||
@@ -74,6 +74,6 @@ "devDependencies": { | ||
"webdriverio": "^8.32.2", | ||
"@vitest/ui": "1.5.3", | ||
"@vitest/runner": "1.5.3", | ||
"@vitest/ws-client": "1.5.3", | ||
"vitest": "1.5.3" | ||
"@vitest/runner": "1.6.0", | ||
"@vitest/ui": "1.6.0", | ||
"@vitest/ws-client": "1.6.0", | ||
"vitest": "1.6.0" | ||
}, | ||
@@ -80,0 +80,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
900109
4540
6
+ Added@vitest/expect@1.6.0(transitive)
+ Added@vitest/runner@1.6.0(transitive)
+ Added@vitest/snapshot@1.6.0(transitive)
+ Added@vitest/spy@1.6.0(transitive)
+ Added@vitest/utils@1.6.0(transitive)
+ Addedvite-node@1.6.0(transitive)
+ Addedvitest@1.6.0(transitive)
- Removed@vitest/expect@1.5.3(transitive)
- Removed@vitest/runner@1.5.3(transitive)
- Removed@vitest/snapshot@1.5.3(transitive)
- Removed@vitest/spy@1.5.3(transitive)
- Removed@vitest/utils@1.5.3(transitive)
- Removedvite-node@1.5.3(transitive)
- Removedvitest@1.5.3(transitive)
Updated@vitest/utils@1.6.0