Skip to content

Commit

Permalink
fix: rename removeRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Aug 6, 2024
1 parent daac5ba commit f11b6d8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/coverage-v8/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage

if (!transformResult) {
isExecuted = false
transformResult = await onTransform(removeRoot(url, FILE_PROTOCOL)).catch(() => undefined)
transformResult = await onTransform(removeStartsWith(url, FILE_PROTOCOL)).catch(() => undefined)
}

const map = transformResult?.map as EncodedSourceMap | undefined
Expand Down Expand Up @@ -500,7 +500,7 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage

async function onTransform(filepath: string) {
if (transformMode === 'browser' && project.browser) {
const result = await project.browser.vite.transformRequest(removeRoot(filepath, project.config.root))
const result = await project.browser.vite.transformRequest(removeStartsWith(filepath, project.config.root))

if (result) {
return { ...result, code: `${result.code}// <inline-source-map>` }
Expand All @@ -514,7 +514,7 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
for (const result of coverage.result) {
if (transformMode === 'browser') {
if (result.url.startsWith('/@fs')) {
result.url = `${FILE_PROTOCOL}${removeRoot(result.url, '/@fs')}`
result.url = `${FILE_PROTOCOL}${removeStartsWith(result.url, '/@fs')}`
}
else {
result.url = `${FILE_PROTOCOL}${project.config.root}${result.url}`
Expand Down Expand Up @@ -637,9 +637,9 @@ function normalizeTransformResults(
return normalized
}

function removeRoot(filepath: string, root: string) {
if (filepath.startsWith(root)) {
return filepath.slice(root.length)
function removeStartsWith(filepath: string, start: string) {
if (filepath.startsWith(start)) {
return filepath.slice(start.length)
}

return filepath
Expand Down

0 comments on commit f11b6d8

Please sign in to comment.