Skip to content

Commit 6cf0bfe

Browse files
committed
remove test file if present
1 parent bc81a4c commit 6cf0bfe

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

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

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -102,45 +102,33 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
102102
webpackConfig.plugins.push(new KarmaWebpackThrowError());
103103
}
104104

105+
// Use existing config if any.
105106
config.webpack = Object.assign(webpackConfig, config.webpack);
106107
config.webpackMiddleware = Object.assign(webpackMiddlewareConfig, config.webpackMiddleware);
107108

108-
// Replace the @angular/cli preprocessor with webpack+sourcemap.
109-
Object.keys(config.preprocessors)
110-
.filter((file) => config.preprocessors[file].indexOf('@angular/cli') !== -1)
111-
.map((file) => config.preprocessors[file])
112-
.map((arr) => arr.splice(arr.indexOf('@angular/cli'), 1, 'webpack', 'sourcemap'));
113-
114-
config.customContextFile = `${__dirname}/karma-context.html`;
115-
config.customDebugFile = `${__dirname}/karma-debug.html`;
116-
117-
config.files.forEach((file: any) => {
118-
if (file.pattern === `./${appConfig.root}/${appConfig.test}`) {
119-
file.watched = false;
120-
file.served = false;
121-
file.included = false;
109+
// Remove the @angular/cli test file if present, for backwards compatibility.
110+
const testFilePath = path.join(appRoot, appConfig.test);
111+
config.files.forEach((file: any, index: number) => {
112+
if (path.normalize(file.pattern) === testFilePath) {
113+
config.files.splice(index, 1);
122114
}
123115
});
124116

117+
// Our custom context and debug files list the webpack bundles directly instead of using
118+
// the karma files array.
119+
config.customContextFile = `${__dirname}/karma-context.html`;
120+
config.customDebugFile = `${__dirname}/karma-debug.html`;
125121

126-
// Add the blocker.
122+
// Add the request blocker.
127123
config.beforeMiddleware = config.beforeMiddleware || [];
128124
config.beforeMiddleware.push('angularCliBlocker');
129125

130-
// code from karma-webpack
131-
132-
// The webpack tier owns the watch behavior so we want to force it in the config
126+
// The webpack tier owns the watch behavior so we want to force it in the config.
133127
webpackConfig.watch = true;
134128
// Files need to be served from a custom path for Karma.
135129
webpackConfig.output.path = '/_karma_webpack_/';
136130
webpackConfig.output.publicPath = '/_karma_webpack_/';
137131

138-
139-
// webpackConfig.entry = Object.assign({}, {
140-
// scripts: [],
141-
// styles: []
142-
// }, webpackConfig.entry)
143-
144132
let compiler: any;
145133
try {
146134
compiler = webpack(webpackConfig);

0 commit comments

Comments
 (0)