@@ -93,8 +93,8 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
9393 config . plugins = config . plugins || [ ] ;
9494 config . reporters = config . reporters || [ ] ;
9595 const { plugins, reporters} = config ;
96- const hasCoveragePlugin = plugins . some ( ( p : { } ) => 'reporter:coverage' in p ) ;
97- const hasIstanbulPlugin = plugins . some ( ( p : { } ) => 'reporter:coverage-istanbul' in p ) ;
96+ const hasCoveragePlugin = plugins . some ( isPlugin ( 'karma-coverage' , 'reporter:coverage' ) ) ;
97+ const hasIstanbulPlugin = plugins . some ( isPlugin ( 'karma-coverage-istanbul-reporter' , 'reporter:coverage-istanbul' ) ) ;
9898 const hasCoverageReporter = reporters . includes ( 'coverage' ) ;
9999 const hasIstanbulReporter = reporters . includes ( 'coverage-istanbul' ) ;
100100 if ( hasCoveragePlugin && ! hasCoverageReporter ) {
@@ -334,6 +334,22 @@ function fallbackMiddleware() {
334334 } ;
335335}
336336
337+ /**
338+ * Returns a function that returns true if the plugin identifier matches the
339+ * `moduleId` or `pluginName`. A plugin identifier can be either a string or
340+ * an object according to https://karma-runner.github.io/5.2/config/plugins.html
341+ * @param moduleId name of the node module (e.g. karma-coverage)
342+ * @param pluginName name of the karma plugin (e.g. reporter:coverage)
343+ */
344+ function isPlugin ( moduleId : string , pluginName : string ) {
345+ return ( plugin : string | { } ) : boolean => {
346+ if ( typeof plugin === 'string' ) {
347+ return plugin === moduleId ;
348+ }
349+ return pluginName in plugin ;
350+ }
351+ }
352+
337353module . exports = {
338354 'framework:@angular-devkit/build-angular' : [ 'factory' , init ] ,
339355 'reporter:@angular-devkit/build-angular--sourcemap-reporter' : [ 'type' , sourceMapReporter ] ,
0 commit comments