Skip to content

Commit

Permalink
feat(instrumenter): support .mts and .cts file extensions (#4694)
Browse files Browse the repository at this point in the history
* feat(instrumenter): support `.mts` and `.cts` file extensions

* test(tap-runner): exclude hooks file from mutating
  • Loading branch information
nicojs authored Jan 29, 2024
1 parent e536cd6 commit 7a09c75
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ Restart each test runner worker process after `n` runs. Not recommended unless y

### `mutate` [`string[]`]

Default: `['{src,lib}/**/*.js?(x)', '!{src,lib}/**/__tests__/**/*.js?(x)', '!{src,lib}/**/?(*.)+(spec|test).js?(x)', '!{src,lib}/**/*+(Spec|Test).js?(x)']`<br />
Default: `['{src,lib}/**/!(*.+(s|S)pec|*.+(t|T)est).+(cjs|mjs|js|ts|mts|cts|jsx|tsx|html|vue|svelte)', '!{src,lib}/**/__tests__/**/*.+(cjs|mjs|js|ts|mts|cts|jsx|tsx|html|vue|svelte)']`<br />

- Config file: `"mutate": ["src/**/*.js", "a.js"]` or `"mutate": ["src/**/*.ts","!src/**/*.spec.ts","!src/**/*.module.ts"]`
- Command line:
Expand Down
4 changes: 2 additions & 2 deletions packages/api/schema/stryker-core.json
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@
"type": "string"
},
"default": [
"{src,lib}/**/!(*.+(s|S)pec|*.+(t|T)est).+(cjs|mjs|js|ts|jsx|tsx|html|vue|svelte)",
"!{src,lib}/**/__tests__/**/*.+(cjs|mjs|js|ts|jsx|tsx|html|vue|svelte)"
"{src,lib}/**/!(*.+(s|S)pec|*.+(t|T)est).+(cjs|mjs|js|ts|mts|cts|jsx|tsx|html|vue|svelte)",
"!{src,lib}/**/__tests__/**/*.+(cjs|mjs|js|ts|mts|cts|jsx|tsx|html|vue|svelte)"
]
},
"mutator": {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/unit/config/options-validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ describe(OptionsValidator.name, () => {
maxConcurrentTestRunners: 9007199254740991,
maxTestRunnerReuse: 0,
mutate: [
'{src,lib}/**/!(*.+(s|S)pec|*.+(t|T)est).+(cjs|mjs|js|ts|jsx|tsx|html|vue|svelte)',
'!{src,lib}/**/__tests__/**/*.+(cjs|mjs|js|ts|jsx|tsx|html|vue|svelte)',
'{src,lib}/**/!(*.+(s|S)pec|*.+(t|T)est).+(cjs|mjs|js|ts|mts|cts|jsx|tsx|html|vue|svelte)',
'!{src,lib}/**/__tests__/**/*.+(cjs|mjs|js|ts|mts|cts|jsx|tsx|html|vue|svelte)',
],
mutator: {
excludedMutations: [],
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/unit/fs/project-reader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ describe(ProjectReader.name, () => {
normalizeWhitespaces(`Warning: No files found for mutation with the given glob expressions.
As a result, a dry-run will be performed without actually modifying anything.
If you intended to mutate files, please check and adjust the configuration.
Current glob pattern(s) used: "{src,lib}/**/!(*.+(s|S)pec|*.+(t|T)est).+(cjs|mjs|js|ts|jsx|tsx|html|vue|svelte)",
"!{src,lib}/**/__tests__/**/*.+(cjs|mjs|js|ts|jsx|tsx|html|vue|svelte)".
Current glob pattern(s) used: "{src,lib}/**/!(*.+(s|S)pec|*.+(t|T)est).+(cjs|mjs|js|ts|mts|cts|jsx|tsx|html|vue|svelte)",
"!{src,lib}/**/__tests__/**/*.+(cjs|mjs|js|ts|mts|cts|jsx|tsx|html|vue|svelte)".
To enable file mutation, consider configuring the \`mutate\`
property in your configuration file or using the --mutate option via the command line.`),
);
Expand Down
2 changes: 2 additions & 0 deletions packages/instrumenter/src/parsers/create-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export function getFormat(fileName: string, override?: AstFormat): AstFormat | u
case '.mjs':
case '.cjs':
return AstFormat.JS;
case '.mts':
case '.cts':
case '.ts':
return AstFormat.TS;
case '.tsx':
Expand Down
8 changes: 8 additions & 0 deletions packages/instrumenter/test/integration/parsers.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ describe('parsers integration', () => {
const actual = await actAssertTsx('App.tsx');
expect(actual).to.matchSnapshot();
});
it('should allow to parse a mts file', async () => {
const actual = await actAssertTS('app.mts');
expect(actual).to.matchSnapshot();
});
it('should allow to parse a cts file', async () => {
const actual = await actAssertTS('app.cts');
expect(actual).to.matchSnapshot();
});

it('should allow to parse a react file with custom babelrc file', async () => {
const actual = await actAssertJS('jsx-with-babelrc/Badge.js');
Expand Down
320 changes: 320 additions & 0 deletions packages/instrumenter/test/integration/parsers.it.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,166 @@ Object {
}
`;
exports[`parsers integration should allow to parse a cts file 1`] = `
Object {
"format": "ts",
"originFileName": "app.cts",
"rawContent": "export class App {}
",
"root": Node {
"comments": Array [],
"end": 20,
"errors": Array [],
"loc": SourceLocation {
"end": Position {
"column": 0,
"index": 20,
"line": 2,
},
"filename": undefined,
"identifierName": undefined,
"start": Position {
"column": 0,
"index": 0,
"line": 1,
},
},
"program": Node {
"body": Array [
Node {
"declaration": Node {
"body": Node {
"body": Array [],
"end": 19,
"loc": SourceLocation {
"end": Position {
"column": 19,
"index": 19,
"line": 1,
},
"filename": undefined,
"identifierName": undefined,
"start": Position {
"column": 17,
"index": 17,
"line": 1,
},
},
"range": Array [
17,
19,
],
"start": 17,
"type": "ClassBody",
},
"end": 19,
"id": Node {
"end": 16,
"loc": SourceLocation {
"end": Position {
"column": 16,
"index": 16,
"line": 1,
},
"filename": undefined,
"identifierName": "App",
"start": Position {
"column": 13,
"index": 13,
"line": 1,
},
},
"name": "App",
"range": Array [
13,
16,
],
"start": 13,
"type": "Identifier",
},
"loc": SourceLocation {
"end": Position {
"column": 19,
"index": 19,
"line": 1,
},
"filename": undefined,
"identifierName": undefined,
"start": Position {
"column": 7,
"index": 7,
"line": 1,
},
},
"range": Array [
7,
19,
],
"start": 7,
"superClass": null,
"type": "ClassDeclaration",
},
"end": 19,
"exportKind": "value",
"loc": SourceLocation {
"end": Position {
"column": 19,
"index": 19,
"line": 1,
},
"filename": undefined,
"identifierName": undefined,
"start": Position {
"column": 0,
"index": 0,
"line": 1,
},
},
"range": Array [
0,
19,
],
"source": null,
"specifiers": Array [],
"start": 0,
"type": "ExportNamedDeclaration",
},
],
"directives": Array [],
"end": 20,
"interpreter": null,
"loc": SourceLocation {
"end": Position {
"column": 0,
"index": 20,
"line": 2,
},
"filename": undefined,
"identifierName": undefined,
"start": Position {
"column": 0,
"index": 0,
"line": 1,
},
},
"range": Array [
0,
20,
],
"sourceType": "module",
"start": 0,
"type": "Program",
},
"range": Array [
0,
20,
],
"start": 0,
"type": "File",
},
}
`;
exports[`parsers integration should allow to parse a mjs file 1`] = `
Object {
"format": "js",
Expand Down Expand Up @@ -2218,6 +2378,166 @@ Object {
}
`;
exports[`parsers integration should allow to parse a mts file 1`] = `
Object {
"format": "ts",
"originFileName": "app.mts",
"rawContent": "export class App {}
",
"root": Node {
"comments": Array [],
"end": 20,
"errors": Array [],
"loc": SourceLocation {
"end": Position {
"column": 0,
"index": 20,
"line": 2,
},
"filename": undefined,
"identifierName": undefined,
"start": Position {
"column": 0,
"index": 0,
"line": 1,
},
},
"program": Node {
"body": Array [
Node {
"declaration": Node {
"body": Node {
"body": Array [],
"end": 19,
"loc": SourceLocation {
"end": Position {
"column": 19,
"index": 19,
"line": 1,
},
"filename": undefined,
"identifierName": undefined,
"start": Position {
"column": 17,
"index": 17,
"line": 1,
},
},
"range": Array [
17,
19,
],
"start": 17,
"type": "ClassBody",
},
"end": 19,
"id": Node {
"end": 16,
"loc": SourceLocation {
"end": Position {
"column": 16,
"index": 16,
"line": 1,
},
"filename": undefined,
"identifierName": "App",
"start": Position {
"column": 13,
"index": 13,
"line": 1,
},
},
"name": "App",
"range": Array [
13,
16,
],
"start": 13,
"type": "Identifier",
},
"loc": SourceLocation {
"end": Position {
"column": 19,
"index": 19,
"line": 1,
},
"filename": undefined,
"identifierName": undefined,
"start": Position {
"column": 7,
"index": 7,
"line": 1,
},
},
"range": Array [
7,
19,
],
"start": 7,
"superClass": null,
"type": "ClassDeclaration",
},
"end": 19,
"exportKind": "value",
"loc": SourceLocation {
"end": Position {
"column": 19,
"index": 19,
"line": 1,
},
"filename": undefined,
"identifierName": undefined,
"start": Position {
"column": 0,
"index": 0,
"line": 1,
},
},
"range": Array [
0,
19,
],
"source": null,
"specifiers": Array [],
"start": 0,
"type": "ExportNamedDeclaration",
},
],
"directives": Array [],
"end": 20,
"interpreter": null,
"loc": SourceLocation {
"end": Position {
"column": 0,
"index": 20,
"line": 2,
},
"filename": undefined,
"identifierName": undefined,
"start": Position {
"column": 0,
"index": 0,
"line": 1,
},
},
"range": Array [
0,
20,
],
"sourceType": "module",
"start": 0,
"type": "Program",
},
"range": Array [
0,
20,
],
"start": 0,
"type": "File",
},
}
`;
exports[`parsers integration should allow to parse a react file with custom babelrc file 1`] = `
Object {
"format": "js",
Expand Down
Loading

0 comments on commit 7a09c75

Please sign in to comment.