diff --git a/packages/angular_devkit/build_angular/src/karma/code-coverage_spec.ts b/packages/angular_devkit/build_angular/src/karma/code-coverage_spec.ts index 381d8c5b2f94..8afedef13ee7 100644 --- a/packages/angular_devkit/build_angular/src/karma/code-coverage_spec.ts +++ b/packages/angular_devkit/build_angular/src/karma/code-coverage_spec.ts @@ -184,4 +184,16 @@ describe('Karma Builder code coverage', () => { expect(success).toBe(true); await run.stop(); }, 120000); + + it('is able to process coverage plugins provided as string karma-*', async () => { + host.replaceInFile('karma.conf.js', /plugins: \[.+?\]/s, `plugins: [ + 'karma-*', + require('@angular-devkit/build-angular/plugins/karma'), + ]`); + const run = await architect.scheduleTarget(karmaTargetSpec, { codeCoverage: true }); + + const {success} = await run.result; + expect(success).toBe(true); + await run.stop(); + }, 120000); }); diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/karma.ts b/packages/angular_devkit/build_angular/src/webpack/plugins/karma.ts index d95c5bd92507..ec925d44fb1f 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/karma.ts +++ b/packages/angular_devkit/build_angular/src/webpack/plugins/karma.ts @@ -345,7 +345,17 @@ function fallbackMiddleware() { function isPlugin(moduleId: string, pluginName: string) { return (plugin: string|{}): boolean => { if (typeof plugin === 'string') { - return plugin === moduleId; + if (!plugin.includes('*')) { + return plugin === moduleId; + } + const regexp = new RegExp(`^${plugin.replace('*', '.*')}`); + if (regexp.test(moduleId)) { + try { + require.resolve(moduleId); + return true; + } catch {} + } + return false; } return pluginName in plugin; }