Skip to content

Commit

Permalink
feat(vitest): support vitest test runner
Browse files Browse the repository at this point in the history
Add support for [vitest](vitest.dev) as a test runner using the `@stryker-mutator/vitest-runner` plugin.

This plugin currently supports minimal options:

```json
{
  "testRunner": "vitest",
  "vitest": { "configFile": "vitest.config.js" }
}
```

Limitations:

- The vitest runner only supports `"coverageAnalysis": "perTest"`.
- Some vitest options are always overridden by the plugin:
   - `threads: true`, `coverage: { enabled: false }`, `singleThread: true`

---------

Co-authored-by: Nico Jansen <jansennico@gmail.com>
Co-authored-by: danny12321 <dannyberkelaar@gmail.com>
  • Loading branch information
3 people authored May 20, 2023
1 parent 6e53201 commit 7394e95
Show file tree
Hide file tree
Showing 98 changed files with 7,093 additions and 42 deletions.
1,695 changes: 1,659 additions & 36 deletions e2e/package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"ts-jest": "29.0.5",
"ts-loader": "9.4.2",
"ts-node": "10.9.1",
"vitest": "0.31.1",
"typescript": "5.0.4",
"webpack": "5.83.1",
"webpack-cli": "5.1.1"
Expand All @@ -68,6 +69,7 @@
"@stryker-mutator/cucumber-runner": "../packages/cucumber-runner",
"@stryker-mutator/util": "../packages/util",
"@stryker-mutator/tap-runner": "../packages/tap-runner",
"@stryker-mutator/typescript-checker": "../packages/typescript-checker"
"@stryker-mutator/typescript-checker": "../packages/typescript-checker",
"@stryker-mutator/vitest-runner": "../packages/vitest-runner"
}
}
8 changes: 8 additions & 0 deletions e2e/test/mono-schema/test/invalid.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@
"features": [32],
"tags": "tag",
"profile": 42
},
"vitest": {
"options": {
"coverage": false
}
},
"tap": {
"specFiles": "{**/@(test|tests|__test__|__tests__)/**,**/*.@(test|tests|spec)}.@(cjs|mjs|js|jsx|ts|tsx)"
}
}
6 changes: 6 additions & 0 deletions e2e/test/mono-schema/test/valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@
"features": ["my-feature.feature"],
"profile": "stryker",
"tags": ["@tag", "@tag2"]
},
"vitest": {
"configFile": "vitest.config.js"
},
"tap": {
"testFiles": "{**/@(test|tests|__test__|__tests__)/**,**/*.@(test|tests|spec)}.@(cjs|mjs|js|jsx|ts|tsx)"
}
}
18 changes: 18 additions & 0 deletions e2e/test/mono-schema/verify/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ describe('The Stryker meta schema', () => {
},
message: 'must be object',
},
{
instancePath: '/tap',
keyword: 'additionalProperties',
message: 'must NOT have additional properties',
params: {
additionalProperty: 'specFiles',
},
schemaPath: '#/properties/tap/additionalProperties',
},
{
instancePath: '/vitest',
keyword: 'additionalProperties',
message: 'must NOT have additional properties',
params: {
additionalProperty: 'options',
},
schemaPath: '#/properties/vitest/additionalProperties',
},
].sort(orderByInstancePath);

/**
Expand Down
15 changes: 15 additions & 0 deletions e2e/test/vitest-noconfig/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "vitest-noconfig",
"version": "0.0.0",
"private": true,
"description": "A module to perform an integration test",
"main": "index.js",
"scripts": {
"pretest": "rimraf \"reports\"",
"test": "stryker run",
"posttest": "mocha --no-config --no-package --timeout 0 verify/verify.js",
"test:unit": "vitest run"
},
"author": "",
"license": "ISC"
}
3 changes: 3 additions & 0 deletions e2e/test/vitest-noconfig/src/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function add(num1: number, num2: number) {
return num1 + num2;
}
6 changes: 6 additions & 0 deletions e2e/test/vitest-noconfig/src/increment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

export function increment(number: number) {
number++;
return number;
}

7 changes: 7 additions & 0 deletions e2e/test/vitest-noconfig/src/is-negative.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function isNegativeNumber(number: number) {
var isNegative = false;
if (number < 0) {
isNegative = true;
}
return isNegative;
}
4 changes: 4 additions & 0 deletions e2e/test/vitest-noconfig/src/negate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export function negate(number: number) {
return -number;
}
10 changes: 10 additions & 0 deletions e2e/test/vitest-noconfig/stryker.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "../../node_modules/@stryker-mutator/core/schema/stryker-schema.json",
"testRunner": "vitest",
"concurrency": 1,
"coverageAnalysis": "perTest",
"reporters": ["json", "clear-text", "html", "event-recorder"],
"plugins": [
"@stryker-mutator/vitest-runner"
]
}
9 changes: 9 additions & 0 deletions e2e/test/vitest-noconfig/tests/add.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { add } from '../src/add';
import { expect, test, describe } from 'vitest';

describe('add', () => {
test('should be able to add two numbers', function () {
const actual = add(5, 2);
expect(actual).toBe(7);
});
});
15 changes: 15 additions & 0 deletions e2e/test/vitest-noconfig/tests/increment.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { increment } from '../src/increment';
import { expect, test, describe } from 'vitest';

describe('increment', () => {

test('should be able to add one to a number', function () {
var number = 2;
var expected = 3;

var actual = increment(number);

expect(actual).toBe(expected);
});

});
11 changes: 11 additions & 0 deletions e2e/test/vitest-noconfig/tests/is-negative.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { isNegativeNumber } from '../src/is-negative';
import { expect, test, describe } from 'vitest';

describe('math', () => {

test('should be able to recognize a negative number', function () {
const number = -2;
const result = isNegativeNumber(number);
expect(result).toBe(true);
});
});
9 changes: 9 additions & 0 deletions e2e/test/vitest-noconfig/tests/negate.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { negate } from '../src/negate';
import { expect, test, describe } from 'vitest';

describe('negate', () => {
test('should be able negate a number', function () {
const actual = negate(2);
expect(actual).toBe(-2);
});
});
3 changes: 3 additions & 0 deletions e2e/test/vitest-noconfig/verify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
7 changes: 7 additions & 0 deletions e2e/test/vitest-noconfig/verify/verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { expectMetricsJsonToMatchSnapshot } from '../../../helpers.js';

describe('Verify stryker has ran correctly', () => {
it('should report correct score', async () => {
await expectMetricsJsonToMatchSnapshot();
});
});
22 changes: 22 additions & 0 deletions e2e/test/vitest-noconfig/verify/verify.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Verify stryker has ran correctly should report correct score 1`] = `
Object {
"compileErrors": 0,
"ignored": 0,
"killed": 11,
"mutationScore": 78.57142857142857,
"mutationScoreBasedOnCoveredCode": 78.57142857142857,
"noCoverage": 0,
"pending": 0,
"runtimeErrors": 0,
"survived": 3,
"timeout": 0,
"totalCovered": 14,
"totalDetected": 11,
"totalInvalid": 0,
"totalMutants": 14,
"totalUndetected": 3,
"totalValid": 14,
}
`;
Loading

0 comments on commit 7394e95

Please sign in to comment.