Skip to content

Commit bc81a4c

Browse files
committed
don't 404 missing scripts
1 parent b1b3b57 commit bc81a4c

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

packages/@angular/cli/plugins/karma.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,16 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
131131

132132
// The webpack tier owns the watch behavior so we want to force it in the config
133133
webpackConfig.watch = true;
134+
// Files need to be served from a custom path for Karma.
134135
webpackConfig.output.path = '/_karma_webpack_/';
135136
webpackConfig.output.publicPath = '/_karma_webpack_/';
136137

138+
139+
// webpackConfig.entry = Object.assign({}, {
140+
// scripts: [],
141+
// styles: []
142+
// }, webpackConfig.entry)
143+
137144
let compiler: any;
138145
try {
139146
compiler = webpack(webpackConfig);
@@ -168,8 +175,22 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
168175
urlRegex: /^\/_karma_webpack_\/.*/,
169176
handler: function handler(req: any, res: any) {
170177
middleware(req, res, function () {
171-
res.statusCode = 404;
172-
res.end('Not found');
178+
// Ensure script and style bundles are served.
179+
// They are mentioned in the custom karma context page and we don't want them to 404.
180+
const alwaysServe = [
181+
'/_karma_webpack_/inline.bundle.js',
182+
'/_karma_webpack_/polyfills.bundle.js',
183+
'/_karma_webpack_/scripts.bundle.js',
184+
'/_karma_webpack_/styles.bundle.js',
185+
'/_karma_webpack_/vendor.bundle.js',
186+
];
187+
if (alwaysServe.indexOf(req.url) != -1) {
188+
res.statusCode = 200;
189+
res.end();
190+
} else {
191+
res.statusCode = 404;
192+
res.end('Not found');
193+
}
173194
});
174195
}
175196
});

0 commit comments

Comments
 (0)