Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for the jest.config.ts compiler to not interfere with tsconfig.json files #10675

Merged
merged 8 commits into from Oct 22, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
### Fixes

- `[expect]` Fix `objectContaining` to work recursively into sub-objects ([#10508](https://github.com/facebook/jest/pull/10508))
- `[jest-config]` Fix for the `jest.config.ts` compiler to not interfere with `tsconfig.json` files
- `[jest-message-util]` Update to work properly with Node 15 ([#10660](https://github.com/facebook/jest/pull/10660))
- `[jest-mock]` Allow to mock methods in getters (TypeScript 3.9 export) ([#10156](https://github.com/facebook/jest/pull/10156))

Expand Down
13 changes: 13 additions & 0 deletions e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap
Expand Up @@ -34,3 +34,16 @@ Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
`;

exports[`works with tsconfig.json 1`] = `
PASS __tests__/a-giraffe.js
✓ giraffe
`;

exports[`works with tsconfig.json 2`] = `
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
`;
15 changes: 15 additions & 0 deletions e2e/__tests__/jest.config.ts.test.ts
Expand Up @@ -29,6 +29,21 @@ test('works with jest.config.ts', () => {
expect(wrap(summary)).toMatchSnapshot();
});

test('works with tsconfig.json', () => {
writeFiles(DIR, {
'__tests__/a-giraffe.js': `test('giraffe', () => expect(1).toBe(1));`,
'jest.config.ts': `export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};`,
'package.json': '{}',
'tsconfig.json': '{ "compilerOptions": { "module": "esnext" } }',
});

const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']);
const {rest, summary} = extractSummary(stderr);
expect(exitCode).toBe(0);
expect(wrap(rest)).toMatchSnapshot();
expect(wrap(summary)).toMatchSnapshot();
});

test('traverses directory tree up until it finds jest.config', () => {
writeFiles(DIR, {
'__tests__/a-giraffe.js': `
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-config/src/readConfigFileAndSetRootDir.ts
Expand Up @@ -107,7 +107,11 @@ const loadTSConfigFile = async (

// Register TypeScript compiler instance
try {
registerer = require('ts-node').register();
registerer = require('ts-node').register({
compilerOptions: {
module: 'CommonJS',
},
});
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
throw new Error(
Expand Down