UNPKG

@stryker-mutator/karma-runner

Version:

A plugin to use the karma test runner in Stryker, the JavaScript mutation testing framework

58 lines 2.77 kB
import decamelize from 'decamelize'; import semver from 'semver'; import { commonTokens, tokens } from '@stryker-mutator/api/plugin'; import { strykerKarmaConfigPath } from '../karma-plugins/index.js'; import { pluginTokens } from '../plugin-tokens.js'; const MIN_ANGULAR_CLI_VERSION = '6.1.0'; export class AngularProjectStarter { logger; options; requireFromCwd; static inject = tokens(commonTokens.logger, commonTokens.options, pluginTokens.requireResolve); constructor(logger, options, requireFromCwd) { this.logger = logger; this.options = options; this.requireFromCwd = requireFromCwd; } // eslint-disable-next-line @typescript-eslint/require-await -- Any thrown errors need to be translated to rejections async start() { this.verifyAngularCliVersion(); const { ngConfig } = this.options.karma; // Make sure require angular cli from inside this function, that way it won't break if angular isn't installed and this file is required. let cli = this.requireFromCwd('@angular/cli'); if ('default' in cli) { cli = cli.default; } const cliArgs = ['test', '--progress=false', `--karma-config=${strykerKarmaConfigPath}`]; if (ngConfig?.testArguments) { const testArguments = ngConfig.testArguments; const ngTestArguments = Object.keys(testArguments); verifyNgTestArguments(ngTestArguments); ngTestArguments.forEach((key) => { const decamelizedKey = decamelize(key, { separator: '-' }); if ('progress' !== key && 'karma-config' !== decamelizedKey) { cliArgs.push(`--${decamelizedKey}=${testArguments[key]}`); } }); } const actualCommand = `ng ${cliArgs.join(' ')}`; this.logger.debug(`Starting Angular tests: ${actualCommand}`); return { exitPromise: cli({ cliArgs }), }; } verifyAngularCliVersion() { const pkg = this.requireFromCwd('@angular/cli/package'); const version = semver.coerce(pkg.version); if (!version || semver.lt(version, MIN_ANGULAR_CLI_VERSION)) { throw new Error(`Your @angular/cli version (${pkg.version}) is not supported. Please install ${MIN_ANGULAR_CLI_VERSION} or higher`); } } } function verifyNgTestArguments(ngTestArguments) { const prefixedArguments = ngTestArguments.filter((key) => key.trim().startsWith('-')); if (prefixedArguments.length > 0) { throw new Error(`Don't prefix arguments with dashes ('-'). Stryker will do this automatically. Problematic arguments are ${prefixedArguments.join(', ')}.`); } } //# sourceMappingURL=angular-starter.js.map