Skip to content

Commit d2557c0

Browse files
author
Szymon.Poltorak
committed
fix: path resolution #3
1 parent 307b179 commit d2557c0

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

testing/test-setup-config/src/lib/vitest-config-factory.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function toAbsolutePaths(
7171
return paths && paths.length > 0
7272
? paths
7373
.filter(Boolean)
74-
.map(p => path.resolve(fileURLToPath(projectRootUrl), p))
74+
.map(p => path.resolve(getProjectRootPath(projectRootUrl), p))
7575
: [];
7676
}
7777

@@ -95,7 +95,7 @@ function defaultGlobalSetup(
9595
): string[] | undefined {
9696
return kind === 'e2e'
9797
? undefined
98-
: [path.resolve(fileURLToPath(projectRootUrl), 'global-setup.ts')];
98+
: [path.resolve(getProjectRootPath(projectRootUrl), 'global-setup.ts')];
9999
}
100100

101101
function buildCoverageConfig(params: {
@@ -106,7 +106,7 @@ function buildCoverageConfig(params: {
106106
}): CoverageOptions {
107107
const defaultExclude = ['mocks/**', '**/types.ts'];
108108
const reportsDirectory = path.resolve(
109-
fileURLToPath(params.projectRootUrl),
109+
getProjectRootPath(params.projectRootUrl),
110110
params.kind === 'e2e'
111111
? `e2e/${params.projectKey}/.coverage`
112112
: `packages/${params.projectKey}/.coverage/${params.kind}-tests`,
@@ -132,15 +132,15 @@ function buildBaseConfig(params: {
132132
}): VitestOverrides {
133133
const cfg: VitestOverrides = {
134134
cacheDir: path.resolve(
135-
fileURLToPath(params.projectRootUrl),
135+
getProjectRootPath(params.projectRootUrl),
136136
`node_modules/.vite/${params.cacheDirName}`,
137137
),
138138
test: {
139139
reporters: ['basic'],
140140
globals: true,
141141
cache: {
142142
dir: path.resolve(
143-
fileURLToPath(params.projectRootUrl),
143+
getProjectRootPath(params.projectRootUrl),
144144
'node_modules/.vitest',
145145
),
146146
},
@@ -199,3 +199,13 @@ function sanitizeOverrides(overrides: VitestOverrides): VitestOverrides {
199199

200200
return { ...overrides, test: sanitizedTest };
201201
}
202+
203+
function getProjectRootPath(projectRootUrl: URL): string {
204+
try {
205+
return fileURLToPath(projectRootUrl);
206+
} catch {
207+
// Fallback for non-file:// URLs or invalid URLs
208+
const pathname = projectRootUrl.pathname;
209+
return pathname.startsWith('/') ? pathname : `/${pathname}`;
210+
}
211+
}

0 commit comments

Comments
 (0)