@stryker-mutator/karma-runner
Advanced tools
Comparing version 3.2.4 to 3.3.0
@@ -6,2 +6,10 @@ # Change Log | ||
# [3.3.0](https://github.io/stryker-mutator/stryker/compare/v3.2.4...v3.3.0) (2020-06-16) | ||
**Note:** Version bump only for package @stryker-mutator/karma-runner | ||
## [3.2.4](https://github.io/stryker-mutator/stryker/compare/v3.2.3...v3.2.4) (2020-05-18) | ||
@@ -8,0 +16,0 @@ |
{ | ||
"name": "@stryker-mutator/karma-runner", | ||
"version": "3.2.4", | ||
"version": "3.3.0", | ||
"description": "A plugin to use the karma test runner in Stryker, the JavaScript mutation testing framework", | ||
@@ -35,6 +35,6 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"@stryker-mutator/jasmine-framework": "^3.2.4", | ||
"@stryker-mutator/mocha-framework": "^3.2.4", | ||
"@stryker-mutator/test-helpers": "^3.2.4", | ||
"@stryker-mutator/util": "^3.2.4", | ||
"@stryker-mutator/jasmine-framework": "^3.3.0", | ||
"@stryker-mutator/mocha-framework": "^3.3.0", | ||
"@stryker-mutator/test-helpers": "^3.3.0", | ||
"@stryker-mutator/util": "^3.3.0", | ||
"@types/express": "~4.17.0", | ||
@@ -54,3 +54,3 @@ "@types/node": "^14.0.1", | ||
"dependencies": { | ||
"@stryker-mutator/api": "^3.2.4", | ||
"@stryker-mutator/api": "^3.3.0", | ||
"decamelize": "^4.0.0", | ||
@@ -72,3 +72,3 @@ "semver": "~6.3.0", | ||
}, | ||
"gitHead": "638decb743653d1dc070ec342a024b7ec60440da" | ||
"gitHead": "c4afdd2cc0bf8a9140d1fd92c4026e90e8c57556" | ||
} |
@@ -10,124 +10,121 @@ "use strict"; | ||
const TestHooksMiddleware_1 = require("./TestHooksMiddleware"); | ||
let KarmaTestRunner = /** @class */ (() => { | ||
class KarmaTestRunner { | ||
constructor(log, getLogger, options) { | ||
this.log = log; | ||
this.testHooksMiddleware = TestHooksMiddleware_1.default.instance; | ||
const setup = this.loadSetup(options); | ||
this.starter = new ProjectStarter_1.default(getLogger, setup); | ||
this.setGlobals(setup, getLogger); | ||
this.cleanRun(); | ||
this.listenToServerStart(); | ||
this.listenToRunComplete(); | ||
this.listenToSpecComplete(); | ||
this.listenToCoverage(); | ||
this.listenToError(); | ||
class KarmaTestRunner { | ||
constructor(log, getLogger, options) { | ||
this.log = log; | ||
this.testHooksMiddleware = TestHooksMiddleware_1.default.instance; | ||
const setup = this.loadSetup(options); | ||
this.starter = new ProjectStarter_1.default(getLogger, setup); | ||
this.setGlobals(setup, getLogger); | ||
this.cleanRun(); | ||
this.listenToServerStart(); | ||
this.listenToRunComplete(); | ||
this.listenToSpecComplete(); | ||
this.listenToCoverage(); | ||
this.listenToError(); | ||
} | ||
init() { | ||
return new Promise((res, rej) => { | ||
StrykerReporter_1.default.instance.once('browsers_ready', res); | ||
this.starter | ||
.start() | ||
.then(() => { | ||
/*noop*/ | ||
}) | ||
.catch(rej); | ||
}); | ||
} | ||
async run({ testHooks }) { | ||
this.testHooksMiddleware.currentTestHooks = testHooks || ''; | ||
if (this.currentRunStatus !== test_runner_1.RunStatus.Error) { | ||
// Only run when there was no compile error | ||
// An compile error can happen in case of angular-cli | ||
await this.runServer(); | ||
} | ||
init() { | ||
return new Promise((res, rej) => { | ||
StrykerReporter_1.default.instance.once('browsers_ready', res); | ||
this.starter | ||
.start() | ||
.then(() => { | ||
/*noop*/ | ||
}) | ||
.catch(rej); | ||
const runResult = this.collectRunResult(); | ||
this.cleanRun(); | ||
return runResult; | ||
} | ||
loadSetup(options) { | ||
const defaultKarmaConfig = { | ||
projectType: 'custom', | ||
}; | ||
return Object.assign(defaultKarmaConfig, options.karma); | ||
} | ||
setGlobals(setup, getLogger) { | ||
strykerKarmaConf.setGlobals({ | ||
getLogger, | ||
karmaConfig: setup.config, | ||
karmaConfigFile: setup.configFile, | ||
}); | ||
} | ||
cleanRun() { | ||
this.currentTestResults = []; | ||
this.currentErrorMessages = []; | ||
this.currentCoverageReport = undefined; | ||
this.currentRunStatus = test_runner_1.RunStatus.Complete; | ||
} | ||
// Don't use dispose() to stop karma (using karma.stopper.stop) | ||
// It only works when in `detached` mode, as specified here: http://karma-runner.github.io/1.0/config/configuration-file.html | ||
listenToSpecComplete() { | ||
StrykerReporter_1.default.instance.on('test_result', (testResult) => { | ||
this.currentTestResults.push(testResult); | ||
}); | ||
} | ||
listenToServerStart() { | ||
StrykerReporter_1.default.instance.on('server_start', (port) => { | ||
this.port = port; | ||
}); | ||
} | ||
listenToCoverage() { | ||
StrykerReporter_1.default.instance.on('coverage_report', (coverageReport) => { | ||
this.currentCoverageReport = coverageReport; | ||
}); | ||
} | ||
listenToRunComplete() { | ||
StrykerReporter_1.default.instance.on('run_complete', (runStatus) => { | ||
this.currentRunStatus = runStatus; | ||
}); | ||
} | ||
listenToError() { | ||
StrykerReporter_1.default.instance.on('browser_error', (error) => { | ||
this.currentErrorMessages.push(error); | ||
}); | ||
StrykerReporter_1.default.instance.on('compile_error', (errors) => { | ||
errors.forEach((error) => this.currentErrorMessages.push(error)); | ||
this.currentRunStatus = test_runner_1.RunStatus.Error; | ||
}); | ||
} | ||
runServer() { | ||
return new Promise((resolve) => { | ||
karma.runner.run({ port: this.port }, (exitCode) => { | ||
this.log.debug('karma run done with ', exitCode); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
collectRunResult() { | ||
return { | ||
coverage: this.currentCoverageReport, | ||
errorMessages: this.currentErrorMessages, | ||
status: this.determineRunState(), | ||
tests: this.currentTestResults, | ||
}; | ||
} | ||
determineRunState() { | ||
// Karma will report an Error if no tests had executed. | ||
// This is not an "error" in Stryker terms | ||
if (this.currentRunStatus === test_runner_1.RunStatus.Error && !this.currentErrorMessages.length && !this.currentTestResults.length) { | ||
return test_runner_1.RunStatus.Complete; | ||
} | ||
async run({ testHooks }) { | ||
this.testHooksMiddleware.currentTestHooks = testHooks || ''; | ||
if (this.currentRunStatus !== test_runner_1.RunStatus.Error) { | ||
// Only run when there was no compile error | ||
// An compile error can happen in case of angular-cli | ||
await this.runServer(); | ||
} | ||
const runResult = this.collectRunResult(); | ||
this.cleanRun(); | ||
return runResult; | ||
else if (this.currentErrorMessages.length) { | ||
// Karma will return Complete when there are runtime errors | ||
return test_runner_1.RunStatus.Error; | ||
} | ||
loadSetup(options) { | ||
const defaultKarmaConfig = { | ||
projectType: 'custom', | ||
}; | ||
return Object.assign(defaultKarmaConfig, options.karma); | ||
else { | ||
return this.currentRunStatus; | ||
} | ||
setGlobals(setup, getLogger) { | ||
strykerKarmaConf.setGlobals({ | ||
getLogger, | ||
karmaConfig: setup.config, | ||
karmaConfigFile: setup.configFile, | ||
}); | ||
} | ||
cleanRun() { | ||
this.currentTestResults = []; | ||
this.currentErrorMessages = []; | ||
this.currentCoverageReport = undefined; | ||
this.currentRunStatus = test_runner_1.RunStatus.Complete; | ||
} | ||
// Don't use dispose() to stop karma (using karma.stopper.stop) | ||
// It only works when in `detached` mode, as specified here: http://karma-runner.github.io/1.0/config/configuration-file.html | ||
listenToSpecComplete() { | ||
StrykerReporter_1.default.instance.on('test_result', (testResult) => { | ||
this.currentTestResults.push(testResult); | ||
}); | ||
} | ||
listenToServerStart() { | ||
StrykerReporter_1.default.instance.on('server_start', (port) => { | ||
this.port = port; | ||
}); | ||
} | ||
listenToCoverage() { | ||
StrykerReporter_1.default.instance.on('coverage_report', (coverageReport) => { | ||
this.currentCoverageReport = coverageReport; | ||
}); | ||
} | ||
listenToRunComplete() { | ||
StrykerReporter_1.default.instance.on('run_complete', (runStatus) => { | ||
this.currentRunStatus = runStatus; | ||
}); | ||
} | ||
listenToError() { | ||
StrykerReporter_1.default.instance.on('browser_error', (error) => { | ||
this.currentErrorMessages.push(error); | ||
}); | ||
StrykerReporter_1.default.instance.on('compile_error', (errors) => { | ||
errors.forEach((error) => this.currentErrorMessages.push(error)); | ||
this.currentRunStatus = test_runner_1.RunStatus.Error; | ||
}); | ||
} | ||
runServer() { | ||
return new Promise((resolve) => { | ||
karma.runner.run({ port: this.port }, (exitCode) => { | ||
this.log.debug('karma run done with ', exitCode); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
collectRunResult() { | ||
return { | ||
coverage: this.currentCoverageReport, | ||
errorMessages: this.currentErrorMessages, | ||
status: this.determineRunState(), | ||
tests: this.currentTestResults, | ||
}; | ||
} | ||
determineRunState() { | ||
// Karma will report an Error if no tests had executed. | ||
// This is not an "error" in Stryker terms | ||
if (this.currentRunStatus === test_runner_1.RunStatus.Error && !this.currentErrorMessages.length && !this.currentTestResults.length) { | ||
return test_runner_1.RunStatus.Complete; | ||
} | ||
else if (this.currentErrorMessages.length) { | ||
// Karma will return Complete when there are runtime errors | ||
return test_runner_1.RunStatus.Error; | ||
} | ||
else { | ||
return this.currentRunStatus; | ||
} | ||
} | ||
} | ||
KarmaTestRunner.inject = plugin_1.tokens(plugin_1.commonTokens.logger, plugin_1.commonTokens.getLogger, plugin_1.commonTokens.options); | ||
return KarmaTestRunner; | ||
})(); | ||
} | ||
exports.default = KarmaTestRunner; | ||
KarmaTestRunner.inject = plugin_1.tokens(plugin_1.commonTokens.logger, plugin_1.commonTokens.getLogger, plugin_1.commonTokens.options); | ||
//# sourceMappingURL=KarmaTestRunner.js.map |
@@ -13,76 +13,73 @@ "use strict"; | ||
*/ | ||
let StrykerReporter = /** @class */ (() => { | ||
class StrykerReporter extends events_1.EventEmitter { | ||
constructor() { | ||
super(); | ||
this.adapters = []; | ||
this.onListening = (port) => { | ||
this.emit('server_start', port); | ||
}; | ||
this.onSpecComplete = (_browser, spec) => { | ||
const name = spec.suite.reduce((name, suite) => name + suite + ' ', '') + spec.description; | ||
let status = test_runner_1.TestStatus.Failed; | ||
if (spec.skipped) { | ||
status = test_runner_1.TestStatus.Skipped; | ||
} | ||
else if (spec.success) { | ||
status = test_runner_1.TestStatus.Success; | ||
} | ||
const testResult = { | ||
failureMessages: spec.log, | ||
name, | ||
status, | ||
timeSpentMs: spec.time, | ||
}; | ||
this.emit('test_result', testResult); | ||
}; | ||
this.onRunComplete = (runResult) => { | ||
this.emit('run_complete', this.collectRunState(runResult)); | ||
}; | ||
this.onLoadError = (...args) => { | ||
this.emit('load_error', ...args); | ||
}; | ||
this.onBrowserComplete = (_browser, result) => { | ||
this.emit('coverage_report', result.coverage); | ||
}; | ||
this.onBrowsersReady = () => { | ||
this.emit('browsers_ready'); | ||
}; | ||
this.onBrowserError = (_browser, error) => { | ||
// Karma 2.0 has different error messages | ||
if (error.message) { | ||
this.emit('browser_error', error.message); | ||
} | ||
else { | ||
this.emit('browser_error', error.toString()); | ||
} | ||
}; | ||
this.onCompileError = (errors) => { | ||
// This is called from angular cli logic | ||
// https://github.com/angular/angular-cli/blob/012672161087a05ae5ecffbed5d1ee307ce1e0ad/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts#L96 | ||
this.emit('compile_error', errors); | ||
}; | ||
} | ||
static get instance() { | ||
if (!this._instance) { | ||
this._instance = new StrykerReporter(); | ||
class StrykerReporter extends events_1.EventEmitter { | ||
constructor() { | ||
super(); | ||
this.adapters = []; | ||
this.onListening = (port) => { | ||
this.emit('server_start', port); | ||
}; | ||
this.onSpecComplete = (_browser, spec) => { | ||
const name = spec.suite.reduce((name, suite) => name + suite + ' ', '') + spec.description; | ||
let status = test_runner_1.TestStatus.Failed; | ||
if (spec.skipped) { | ||
status = test_runner_1.TestStatus.Skipped; | ||
} | ||
return this._instance; | ||
} | ||
collectRunState(runResult) { | ||
if (runResult.disconnected) { | ||
return test_runner_1.RunStatus.Timeout; | ||
else if (spec.success) { | ||
status = test_runner_1.TestStatus.Success; | ||
} | ||
else if (runResult.error) { | ||
return test_runner_1.RunStatus.Error; | ||
const testResult = { | ||
failureMessages: spec.log, | ||
name, | ||
status, | ||
timeSpentMs: spec.time, | ||
}; | ||
this.emit('test_result', testResult); | ||
}; | ||
this.onRunComplete = (runResult) => { | ||
this.emit('run_complete', this.collectRunState(runResult)); | ||
}; | ||
this.onLoadError = (...args) => { | ||
this.emit('load_error', ...args); | ||
}; | ||
this.onBrowserComplete = (_browser, result) => { | ||
this.emit('coverage_report', result.coverage); | ||
}; | ||
this.onBrowsersReady = () => { | ||
this.emit('browsers_ready'); | ||
}; | ||
this.onBrowserError = (_browser, error) => { | ||
// Karma 2.0 has different error messages | ||
if (error.message) { | ||
this.emit('browser_error', error.message); | ||
} | ||
else { | ||
return test_runner_1.RunStatus.Complete; | ||
this.emit('browser_error', error.toString()); | ||
} | ||
}; | ||
this.onCompileError = (errors) => { | ||
// This is called from angular cli logic | ||
// https://github.com/angular/angular-cli/blob/012672161087a05ae5ecffbed5d1ee307ce1e0ad/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts#L96 | ||
this.emit('compile_error', errors); | ||
}; | ||
} | ||
static get instance() { | ||
if (!this._instance) { | ||
this._instance = new StrykerReporter(); | ||
} | ||
return this._instance; | ||
} | ||
StrykerReporter._instance = new StrykerReporter(); | ||
return StrykerReporter; | ||
})(); | ||
collectRunState(runResult) { | ||
if (runResult.disconnected) { | ||
return test_runner_1.RunStatus.Timeout; | ||
} | ||
else if (runResult.error) { | ||
return test_runner_1.RunStatus.Error; | ||
} | ||
else { | ||
return test_runner_1.RunStatus.Complete; | ||
} | ||
} | ||
} | ||
exports.default = StrykerReporter; | ||
StrykerReporter._instance = new StrykerReporter(); | ||
//# sourceMappingURL=StrykerReporter.js.map |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78653
688
Updated@stryker-mutator/api@^3.3.0