@stryker-mutator/core
Version:
The extendable JavaScript mutation testing framework
57 lines • 2.63 kB
JavaScript
import os from 'os';
import fs from 'fs/promises';
import { commonTokens } from '@stryker-mutator/api/plugin';
import semver from 'semver';
import { fileUtils } from '../../utils/file-utils.js';
import { coreTokens } from '../../di/index.js';
const guideUrl = 'https://stryker-mutator.io/docs/stryker-js/guides/angular';
const karmaConfigFile = 'karma.conf.js';
export class AngularInitializer {
constructor(log, execa, resolve) {
this.log = log;
this.execa = execa;
this.resolve = resolve;
this.name = 'angular-cli';
// Please keep config in sync with handbook
this.dependencies = ['@stryker-mutator/karma-runner'];
this.config = {
mutate: ['src/**/*.ts', '!src/**/*.spec.ts', '!src/test.ts', '!src/environments/*.ts'],
testRunner: 'karma',
karma: {
configFile: karmaConfigFile,
projectType: 'angular-cli',
config: {
browsers: ['ChromeHeadless'],
},
},
reporters: ['progress', 'clear-text', 'html'],
concurrency: Math.floor(os.cpus().length / 2),
// eslint-disable-next-line camelcase
concurrency_comment: 'Recommended to use about half of your available cores when running stryker with angular',
coverageAnalysis: 'perTest',
};
}
async createConfig() {
const [karmaConfigExists, ngVersionOutput] = await Promise.all([fileUtils.exists(karmaConfigFile), this.getCurrentAngularVersion()]);
if (!karmaConfigExists && ngVersionOutput && semver.gte(ngVersionOutput, '15.1.0')) {
const command = 'npx ng generate config karma';
this.log.info(`No "karma.conf.js" file found, running command: "${command}"`);
const { stdout } = await this.execa(command);
this.log.info(`\n${stdout}`);
}
return { config: this.config, guideUrl, dependencies: this.dependencies };
}
async getCurrentAngularVersion() {
try {
const packageLocation = this.resolve('@angular/cli/package.json');
return JSON.parse(await fs.readFile(packageLocation, 'utf8')).version;
}
catch (err) {
const error = err;
this.log.warn(`Could not discover your local angular-cli version. Continuing without generating karma configuration. ${error.stack}`);
return undefined;
}
}
}
AngularInitializer.inject = [commonTokens.logger, coreTokens.execa, coreTokens.resolveFromCwd];
//# sourceMappingURL=angular-initializer.js.map