Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
36 changes: 0 additions & 36 deletions e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap

This file was deleted.

36 changes: 0 additions & 36 deletions e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap

This file was deleted.

2 changes: 1 addition & 1 deletion e2e/__tests__/jest.config.js.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {wrap} from 'jest-snapshot-serializer-raw';
import runJest from '../runJest';
import {cleanup, extractSummary, writeFiles} from '../Utils';

const DIR = path.resolve(__dirname, '../jest.config.js');
const DIR = path.resolve(__dirname, '../tmp/jest-config-js');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant

import {tmpdir} from 'os';`

😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimenB If I move it to tmp the traverses directory tree up until it finds jest.config test will fail because it can't find the slash package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should install slash in it, then. We have a runYarn helper already - I don't think it takes args, but that should be a simple refactor.

We can do it later, though 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice, runYarn is exactly what I was looking for

Copy link
Contributor Author

@Gamote Gamote Oct 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimenB I've reverted the change with the tmp bacause I couldn't make runYarn to install the slash package. I even tried run('yarn install', DIR) with same module does not exist error.

As you said, we can do it later so we don't need to delay this fix.

Full example:

test('traverses directory tree up until it finds jest.config', () => {
  writeFiles(DIR, {
    '__tests__/a-giraffe.js': `
    const slash = require('slash');
    test('giraffe', () => expect(1).toBe(1));
    test('abc', () => console.log(slash(process.cwd())));
    `,
    'jest.config.ts': `export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};`,
    'package.json': '{ "devDependencies": { "slash": "^3.0.0" } }',
    'some/nested/directory/file.js': '// nothing special',
  });

  // 1st try with small local refactoring to allow args
  runYarn(DIR, undefined, ['install']);

  // 2nd try
  run('yarn install', DIR);

  const {stderr, exitCode, stdout} = runJest(
    path.join(DIR, 'some', 'nested', 'directory'),
    ['-w=1', '--ci=false'],
    {skipPkgJsonCheck: true},
  );

  // expects...
});


beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));
Expand Down
17 changes: 16 additions & 1 deletion e2e/__tests__/jest.config.ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {wrap} from 'jest-snapshot-serializer-raw';
import runJest from '../runJest';
import {cleanup, extractSummary, writeFiles} from '../Utils';

const DIR = path.resolve(__dirname, '../jest.config.ts');
const DIR = path.resolve(__dirname, '../tmp/jest-config-ts');

beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));
Expand All @@ -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
Original file line number Diff line number Diff line change
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