Skip to content

Commit

Permalink
feat(hit limit): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericbonnet committed Oct 15, 2021
1 parent 6d58226 commit 871782b
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 64 deletions.
2 changes: 1 addition & 1 deletion e2e/test/hit-limit/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"spec": "test/**.mocha.spec.js"
"require": ["test/chai-setup.js"]
}
4 changes: 0 additions & 4 deletions e2e/test/hit-limit/jasmine.json

This file was deleted.

2 changes: 1 addition & 1 deletion e2e/test/hit-limit/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = function(config) {
frameworks: ['jasmine'],
files: [
'src/*.js',
'test/*.karma.spec.js'
'test/*.spec.js'
],
reporters: ['progress'],
colors: true,
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/hit-limit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"main": "index.js",
"scripts": {
"test:mocha": "mocha",
"test:jasmine": "jasmine --config=jasmine.json",
"test:jasmine": "jasmine",
"test:karma": "karma start",
"test": "mocha --no-package --timeout 60000 --require \"../../tasks/ts-node-register.js\" verify/verify.ts"
},
Expand Down
8 changes: 8 additions & 0 deletions e2e/test/hit-limit/spec/support/jasmine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"spec_dir": "spec",
"spec_files": [
"../test/*.spec.js"
],
"stopSpecOnExpectationFailure": false,
"random": true
}
1 change: 0 additions & 1 deletion e2e/test/hit-limit/stryker.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
"configFile": "karma.conf.js",
"config": {}
},
"jasmineConfigFile": "jasmine.json",
"concurrency": 1
}
6 changes: 6 additions & 0 deletions e2e/test/hit-limit/test/chai-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const chai = require('chai');

chai.util.addMethod(chai.Assertion.prototype, 'toEqual', function (expected) {
var obj = chai.util.flag(this, 'object');
new chai.Assertion(obj).to.deep.equal(expected);
});
9 changes: 0 additions & 9 deletions e2e/test/hit-limit/test/loop.jasmine.spec.js

This file was deleted.

7 changes: 0 additions & 7 deletions e2e/test/hit-limit/test/loop.karma.spec.js

This file was deleted.

10 changes: 0 additions & 10 deletions e2e/test/hit-limit/test/loop.mocha.spec.js

This file was deleted.

14 changes: 14 additions & 0 deletions e2e/test/hit-limit/test/loop.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if (typeof require === 'function') {
loop = require('../src/loop').loop;
}
if (typeof expect === 'undefined') {
globalThis.expect = require('chai').expect;
}

describe('loop', () => {
it('should result in 15 for n=5 and a sum function', () => {
let result = 0;
loop(5, (n) => (result += n));
expect(result).toEqual(15);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,20 @@ describe('Infinite loop', () => {
await sut.dispose();
});

it.skip('should report a timeout eventually and be able to recover from it', async function () {
// TODO Mocha runner doesn't seem to detect timeout in infinite loop
this.timeout(1000);

// This is a slow test, so I decided to put 2 tests into one 🤷‍♀️
// Act
const result = await sut.mutantRun(factory.mutantRunOptions());

// Assert
assertions.expectTimeout(result);

// Second test, should be recovered by now.
const secondResult = await sut.mutantRun(factory.mutantRunOptions({ testFilter: ['spec1'] }));
assertions.expectSurvived(secondResult);
expect(secondResult.nrOfTests).eq(1);
});

it('should be able to recover using a hit counter', async () => {
// Time this test, this should be fairly stable because there is large margin
const startTime = new Date();
const maxTestDurationMS = 5000;
// Arrange
const options = factory.mutantRunOptions({
activeMutant: factory.mutant({ id: '19' }),
testFilter: ['spec2'],
hitLimit: 10,
});

const result = await sut.mutantRun(
factory.mutantRunOptions({
activeMutant: factory.mutant({ id: '19' }),
testFilter: ['spec2'],
hitLimit: 10,
})
);
// Act
const result = await sut.mutantRun(options);

// Assert
assertions.expectTimeout(result);
expect(result.reason).contains('Hit limit reached');
expect(new Date().valueOf() - startTime.valueOf(), 'Test took longer than 3 sec to complete, was the hit counter malfunctioning?').lt(
maxTestDurationMS
);
});

it('should reset hit counter state correctly between runs', async () => {
Expand Down

0 comments on commit 871782b

Please sign in to comment.