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 angular#19993
  • Loading branch information
iftee-hussain committed Feb 7, 2021
1 parent cae2209 commit 60bc0cc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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 @@ -7,10 +7,13 @@
*/
// tslint:disable
// TODO: cleanup this file, it's copied as is from Angular CLI.
import * as fs from 'fs';
import * as http from 'http';
import * as path from 'path';
import * as glob from 'glob';
import * as webpack from 'webpack';

const karmaPath = path.dirname(require.resolve('karma'));
const webpackDevMiddleware = require('webpack-dev-middleware');

import { KarmaWebpackFailureCb } from './karma-webpack-failure-cb';
Expand Down Expand Up @@ -336,6 +339,13 @@ function fallbackMiddleware() {
function isPlugin(moduleId: string, pluginName: string) {
return (plugin: string|{}): boolean => {
if (typeof plugin === 'string') {
if(karmaPath) {
const pluginDirectory = path.join(karmaPath, '../../');
const regexp = new RegExp(`^${plugin.replace('*', '.*')}`)
const installeKarmaPlugins = fs.readdirSync(pluginDirectory)
.filter((installedPluginName) => regexp.test(installedPluginName));
return installeKarmaPlugins.includes( moduleId);
}
return plugin === moduleId;
}
return pluginName in plugin;
Expand Down

0 comments on commit 60bc0cc

Please sign in to comment.