Skip to content

Commit

Permalink
feat(tap-runner): support "nodeArgs" (#4235)
Browse files Browse the repository at this point in the history
Add support for the `tap.nodeArgs` config option. Here you can specify additional node arguments to be passed to every test runner.

With this, it is now possible to JIT compile typescript code using:

```json
{
  "tap": {
    "nodeArgs": ["--loader", "ts-node/esm"]
  }
}
```

Or (when using commonjs)

```json
{
  "tap": {
    "nodeArgs": ["-r", "ts-node/register"]
  }
}
```

Also add a test for typescript using the tap runner.
  • Loading branch information
nicojs authored May 27, 2023
1 parent c0466e2 commit c149b34
Show file tree
Hide file tree
Showing 35 changed files with 686 additions and 182 deletions.
8 changes: 4 additions & 4 deletions e2e/test/incremental/verify/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ describe('incremental', () => {

beforeEach(async () => {
await fsPromises.rm(incrementalFile, { force: true });
/**
* @type {import('@stryker-mutator/api/core').LogLevel}
*/
strykerOptions = {
incremental: true,
concurrency: 1,
plugins: ['./verify/mutation-run-plan-reporter.js'],
reporters: ['mutation-run-plan', 'html'],
tap: {
testFiles: 'spec/*.tap.js',
},
};
await changeFiles('original'); // change the files back to there original state
});
Expand All @@ -42,7 +42,7 @@ describe('incremental', () => {
// We know which test files are changed and assume each test in that file changed
withoutTestLocations: 2,
// We know which test file the test originated from, but we can't differentiate between tests in the file (TAP runner)
withoutTestDeviation: 6,
withoutTestDeviation: 2,
// Don't know from which test files the tests originated
withoutTestFiles: 7,
});
Expand Down
62 changes: 37 additions & 25 deletions e2e/test/incremental/verify/verify.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1920,8 +1920,10 @@ Array [
Object {
"fileName": "src/concat.js",
"mutant": Object {
"coveredBy": Array [],
"killedBy": Array [],
"coveredBy": Array [
"spec/concat.tap.js",
],
"killedBy": undefined,
"location": Object {
"end": Object {
"column": 1,
Expand All @@ -1935,16 +1937,17 @@ Array [
"mutatorName": "BlockStatement",
"replacement": "{}",
"static": false,
"status": "NoCoverage",
"testsCompleted": undefined,
"status": undefined,
},
"plan": "EarlyResult",
"plan": "Run",
},
Object {
"fileName": "src/concat.js",
"mutant": Object {
"coveredBy": Array [],
"killedBy": Array [],
"coveredBy": Array [
"spec/concat.tap.js",
],
"killedBy": undefined,
"location": Object {
"end": Object {
"column": 19,
Expand All @@ -1958,16 +1961,15 @@ Array [
"mutatorName": "StringLiteral",
"replacement": "\`\`",
"static": false,
"status": "NoCoverage",
"testsCompleted": undefined,
"status": undefined,
},
"plan": "EarlyResult",
"plan": "Run",
},
Object {
"fileName": "src/concat.js",
"mutant": Object {
"coveredBy": Array [
"spec/concat.spec.js",
"spec/concat.tap.js",
],
"killedBy": undefined,
"location": Object {
Expand All @@ -1990,7 +1992,9 @@ Array [
Object {
"fileName": "src/concat.js",
"mutant": Object {
"coveredBy": Array [],
"coveredBy": Array [
"spec/concat.tap.js",
],
"killedBy": undefined,
"location": Object {
"end": Object {
Expand All @@ -2012,7 +2016,9 @@ Array [
Object {
"fileName": "src/concat.js",
"mutant": Object {
"coveredBy": Array [],
"coveredBy": Array [
"spec/concat.tap.js",
],
"killedBy": undefined,
"location": Object {
"end": Object {
Expand Down Expand Up @@ -2078,7 +2084,9 @@ Array [
Object {
"fileName": "src/math.js",
"mutant": Object {
"coveredBy": Array [],
"coveredBy": Array [
"spec/math.tap.js",
],
"killedBy": undefined,
"location": Object {
"end": Object {
Expand All @@ -2100,7 +2108,9 @@ Array [
Object {
"fileName": "src/math.js",
"mutant": Object {
"coveredBy": Array [],
"coveredBy": Array [
"spec/math.tap.js",
],
"killedBy": undefined,
"location": Object {
"end": Object {
Expand All @@ -2122,8 +2132,10 @@ Array [
Object {
"fileName": "src/math.js",
"mutant": Object {
"coveredBy": Array [],
"killedBy": Array [],
"coveredBy": Array [
"spec/math.tap.js",
],
"killedBy": undefined,
"location": Object {
"end": Object {
"column": 1,
Expand All @@ -2137,16 +2149,17 @@ Array [
"mutatorName": "BlockStatement",
"replacement": "{}",
"static": false,
"status": "NoCoverage",
"testsCompleted": undefined,
"status": undefined,
},
"plan": "EarlyResult",
"plan": "Run",
},
Object {
"fileName": "src/math.js",
"mutant": Object {
"coveredBy": Array [],
"killedBy": Array [],
"coveredBy": Array [
"spec/math.tap.js",
],
"killedBy": undefined,
"location": Object {
"end": Object {
"column": 14,
Expand All @@ -2160,10 +2173,9 @@ Array [
"mutatorName": "ArithmeticOperator",
"replacement": "a / b",
"static": false,
"status": "NoCoverage",
"testsCompleted": undefined,
"status": undefined,
},
"plan": "EarlyResult",
"plan": "Run",
},
Object {
"fileName": "src/math.js",
Expand Down
3 changes: 2 additions & 1 deletion e2e/test/mono-schema/test/valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"configFile": "vitest.config.js"
},
"tap": {
"testFiles": "{**/@(test|tests|__test__|__tests__)/**,**/*.@(test|tests|spec)}.@(cjs|mjs|js|jsx|ts|tsx)"
"testFiles": "{**/@(test|tests|__test__|__tests__)/**,**/*.@(test|tests|spec)}.@(cjs|mjs|js|jsx|ts|tsx)",
"nodeArgs": ["--loader", "ts-node/esm"]
}
}
16 changes: 16 additions & 0 deletions e2e/test/tap-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "tap-typescript",
"version": "0.0.0",
"private": true,
"description": "A project using node-tap and typescript",
"main": "index.js",
"type": "module",
"scripts": {
"pretest": "rimraf \"reports\"",
"test": "stryker run",
"posttest": "mocha --no-config --no-package --timeout 0 verify/verify.js",
"test:unit": "NODE_OPTIONS=\"--loader ts-node/esm\" tap --ts"
},
"author": "",
"license": "ISC"
}
3 changes: 3 additions & 0 deletions e2e/test/tap-typescript/src/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function add(num1: number, num2: number): number {
return num1 + num2;
}
6 changes: 6 additions & 0 deletions e2e/test/tap-typescript/src/increment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

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

7 changes: 7 additions & 0 deletions e2e/test/tap-typescript/src/is-negative.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function isNegativeNumber(n: number) {
var isNegative = false;
if (n < 0) {
isNegative = true;
}
return isNegative;
}
3 changes: 3 additions & 0 deletions e2e/test/tap-typescript/src/negate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function negate(n: number) {
return -n;
}
13 changes: 13 additions & 0 deletions e2e/test/tap-typescript/stryker.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "../../node_modules/@stryker-mutator/core/schema/stryker-schema.json",
"testRunner": "tap",
"concurrency": 1,
"reporters": ["json", "clear-text", "html", "event-recorder"],
"testRunnerNodeArgs_comment": ["--inspect-brk"],
"tap": {
"nodeArgs": ["--loader", "ts-node/esm"]
},
"plugins": [
"@stryker-mutator/tap-runner"
]
}
12 changes: 12 additions & 0 deletions e2e/test/tap-typescript/test/add.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test } from 'tap';
import { add } from '../src/add.js';

test('add', (t) => {
t.test('should be able to add two numbers', (t) => {
const actual = add(5, 2);
t.equal(actual, 7);
t.end();
});

t.end();
});
16 changes: 16 additions & 0 deletions e2e/test/tap-typescript/test/increment.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { test } from 'tap';
import { increment } from '../src/increment.js';

test('increment', (t) => {
t.test('should be able to add one to a number', (t) => {
const number = 2;
const expected = 3;

const actual = increment(number);

t.equal(actual, expected);
t.end();
});

t.end();
});
9 changes: 9 additions & 0 deletions e2e/test/tap-typescript/test/is-negative.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test } from 'tap';
import { isNegativeNumber } from '../src/is-negative.js';

test('math - should be able to recognize a negative number', (t) => {
const number = -2;
const result = isNegativeNumber(number);
t.equal(result, true);
t.end();
});
12 changes: 12 additions & 0 deletions e2e/test/tap-typescript/test/negate.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test } from 'tap';
import { negate } from '../src/negate.js';

test('negate', (t) => {
t.test('should be able to negate a number', (t) => {
const actual = negate(2);
t.equal(actual, -2);
t.end();
});

t.end();
});
16 changes: 16 additions & 0 deletions e2e/test/tap-typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "es2022",
"lib": ["es2022"],
"module": "Node16",
"moduleResolution": "node16",
"outDir": "dist",
// "noEmit": true,
"isolatedModules": true,
"verbatimModuleSyntax": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
7 changes: 7 additions & 0 deletions e2e/test/tap-typescript/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/tap-typescript/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 c149b34

Please sign in to comment.