MCPcopy
hub / github.com/vitest-dev/vitest / replaceRoot

Function replaceRoot

test/test-utils/index.ts:540–561  ·  view source on GitHub ↗
(string: string, root: string)

Source from the content-addressed store, hash-verified

538const isWindows = process.platform === 'win32'
539
540export function replaceRoot(string: string, root: string) {
541 const schemaRoot = root.startsWith('file://') ? root : pathToFileURL(root).toString()
542 if (!root.endsWith('/') && !isWindows) {
543 root += '?/'
544 }
545 if (!isWindows) {
546 return string
547 .replace(new RegExp(schemaRoot, 'g'), '<urlRoot>')
548 .replace(new RegExp(root, 'g'), '<root>/')
549 }
550 let unixRoot = root.replace(/\\/g, '/')
551 let win32Root = root.replaceAll('/', '\\\\')
552 if (!root.endsWith('/') && !root.endsWith('\\')) {
553 unixRoot += '?/'
554 win32Root += '?\\\\'
555 }
556
557 return string
558 .replace(new RegExp(schemaRoot, 'gi'), '<urlRoot>')
559 .replace(new RegExp(unixRoot, 'gi'), '<root>/')
560 .replace(new RegExp(win32Root, 'gi'), '<root>/')
561}
562
563export const ts = String.raw
564

Callers

nothing calls this directly

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected