Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): fixed ignoring of karma plugins c…
Browse files Browse the repository at this point in the history
…onfig

Previously `karma-coverage` was validated only when in karma plugins config one of these was added
``'karma-coverage'` or `require('karma-coverage')`

This change will allow cli to validate `karma-coverage` plugin if in `karma.conf.js` `'karma-*'` is used. Example:
```
plugins: [
      ...
      'karma-*',
      require('@angular-devkit/build-angular/plugins/karma'),
      ...
    ]
```

Fixes #19993
  • Loading branch information
iftee-hussain authored and clydin committed Feb 8, 2021
1 parent b203378 commit a7ffce1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,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;
}
Expand Down

0 comments on commit a7ffce1

Please sign in to comment.