Skip to content

Commit bd917d9

Browse files
clydinalan-agius4
authored andcommittedMar 25, 2025·
fix(@angular/build): normalize karma asset paths before lookup
When handling a request for a configured asset with the application- based karma unit testing, the asset URL is now normalized to the executing platform's path format before looking up the asset. This is required due to the build file paths being based on the underlying operating system's paths which may not align with a URL's path separator such as when using Windows.
1 parent 3f506f5 commit bd917d9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed
 

‎packages/angular/build/src/builders/karma/application_builder.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { findTests, getTestEntrypoints } from './find-tests';
2525
import { Schema as KarmaBuilderOptions } from './schema';
2626

2727
const localResolve = createRequire(__filename).resolve;
28+
const isWindows = process.platform === 'win32';
2829

2930
interface BuildOptions extends ApplicationBuilderInternalOptions {
3031
// We know that it's always a string since we set it.
@@ -69,7 +70,14 @@ class AngularAssetsMiddleware {
6970
let err = null;
7071
try {
7172
const url = new URL(`http://${req.headers['host']}${req.url}`);
72-
const file = this.latestBuildFiles.files[url.pathname.slice(1)];
73+
// Remove the leading slash from the URL path and convert to platform specific.
74+
// The latest build files will use the platform path separator.
75+
let pathname = url.pathname.slice(1);
76+
if (isWindows) {
77+
pathname = pathname.replaceAll(path.posix.sep, path.win32.sep);
78+
}
79+
80+
const file = this.latestBuildFiles.files[pathname];
7381

7482
if (file?.origin === 'disk') {
7583
this.serveFile(file.inputPath, undefined, res);

0 commit comments

Comments
 (0)
Please sign in to comment.