@@ -86,32 +86,11 @@ const init: any = (config: any, emitter: any) => {
86
86
config . reporters . unshift ( '@angular-devkit/build-angular--event-reporter' ) ;
87
87
88
88
// When using code-coverage, auto-add karma-coverage.
89
- if ( options . codeCoverage ) {
90
- config . plugins = config . plugins || [ ] ;
91
- config . reporters = config . reporters || [ ] ;
92
- const { plugins, reporters } = config ;
93
- const hasCoveragePlugin = plugins . some ( isPlugin ( 'karma-coverage' , 'reporter:coverage' ) ) ;
94
- const hasIstanbulPlugin = plugins . some (
95
- isPlugin ( 'karma-coverage-istanbul-reporter' , 'reporter:coverage-istanbul' ) ,
96
- ) ;
97
- const hasCoverageReporter = reporters . includes ( 'coverage' ) ;
98
- const hasIstanbulReporter = reporters . includes ( 'coverage-istanbul' ) ;
99
- if ( hasCoveragePlugin && ! hasCoverageReporter ) {
100
- reporters . push ( 'coverage' ) ;
101
- } else if ( hasIstanbulPlugin && ! hasIstanbulReporter ) {
102
- // coverage-istanbul is deprecated in favor of karma-coverage
103
- reporters . push ( 'coverage-istanbul' ) ;
104
- } else if ( ! hasCoveragePlugin && ! hasIstanbulPlugin ) {
105
- throw new Error ( 'karma-coverage must be installed in order to run code coverage.' ) ;
106
- }
107
-
108
- if ( hasIstanbulPlugin ) {
109
- logger . warn (
110
- `'karma-coverage-istanbul-reporter' usage has been deprecated since version 11.\n` +
111
- `Please install 'karma-coverage' and update 'karma.conf.js.' ` +
112
- 'For more info, see https://github.com/karma-runner/karma-coverage/blob/master/README.md' ,
113
- ) ;
114
- }
89
+ if (
90
+ options . codeCoverage &&
91
+ ! config . reporters . some ( ( r : string ) => r === 'coverage' || r === 'coverage-istanbul' )
92
+ ) {
93
+ config . reporters . push ( 'coverage' ) ;
115
94
}
116
95
117
96
// Add webpack config.
@@ -316,32 +295,6 @@ function fallbackMiddleware() {
316
295
} ;
317
296
}
318
297
319
- /**
320
- * Returns a function that returns true if the plugin identifier matches the
321
- * `moduleId` or `pluginName`. A plugin identifier can be either a string or
322
- * an object according to https://karma-runner.github.io/5.2/config/plugins.html
323
- * @param moduleId name of the node module (e.g. karma-coverage)
324
- * @param pluginName name of the karma plugin (e.g. reporter:coverage)
325
- */
326
- function isPlugin ( moduleId : string , pluginName : string ) {
327
- return ( plugin : string | { } ) : boolean => {
328
- if ( typeof plugin === 'string' ) {
329
- if ( ! plugin . includes ( '*' ) ) {
330
- return plugin === moduleId ;
331
- }
332
- const regexp = new RegExp ( `^${ plugin . replace ( '*' , '.*' ) } ` ) ;
333
- if ( regexp . test ( moduleId ) ) {
334
- try {
335
- require . resolve ( moduleId ) ;
336
- return true ;
337
- } catch { }
338
- }
339
- return false ;
340
- }
341
- return pluginName in plugin ;
342
- } ;
343
- }
344
-
345
298
module . exports = {
346
299
'framework:@angular-devkit/build-angular' : [ 'factory' , init ] ,
347
300
'reporter:@angular-devkit/build-angular--sourcemap-reporter' : [ 'type' , sourceMapReporter ] ,
0 commit comments