Skip to content

Commit 7552a9f

Browse files
clydinalan-agius4
authored andcommitted
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. (cherry picked from commit bd917d9)
1 parent 32b1dcd commit 7552a9f

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
@@ -29,6 +29,7 @@ import { findTests, getTestEntrypoints } from './find-tests';
2929
import { Schema as KarmaBuilderOptions } from './schema';
3030

3131
const localResolve = createRequire(__filename).resolve;
32+
const isWindows = process.platform === 'win32';
3233

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

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

0 commit comments

Comments
 (0)