Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for the
jest.config.ts
configuration file (#10564)
- Loading branch information
Showing
20 changed files
with
420 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`traverses directory tree up until it finds jest.config 1`] = ` | ||
console.log | ||
<<REPLACED>>/jest.config.ts/some/nested/directory | ||
at Object.log (__tests__/a-giraffe.js:3:27) | ||
`; | ||
exports[`traverses directory tree up until it finds jest.config 2`] = ` | ||
PASS ../../../__tests__/a-giraffe.js | ||
✓ giraffe | ||
✓ abc | ||
`; | ||
exports[`traverses directory tree up until it finds jest.config 3`] = ` | ||
Test Suites: 1 passed, 1 total | ||
Tests: 2 passed, 2 total | ||
Snapshots: 0 total | ||
Time: <<REPLACED>> | ||
Ran all test suites. | ||
`; | ||
exports[`works with jest.config.ts 1`] = ` | ||
PASS __tests__/a-giraffe.js | ||
✓ giraffe | ||
`; | ||
exports[`works with jest.config.ts 2`] = ` | ||
Test Suites: 1 passed, 1 total | ||
Tests: 1 passed, 1 total | ||
Snapshots: 0 total | ||
Time: <<REPLACED>> | ||
Ran all test suites. | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import * as path from 'path'; | ||
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'); | ||
|
||
beforeEach(() => cleanup(DIR)); | ||
afterAll(() => cleanup(DIR)); | ||
|
||
test('works with jest.config.ts', () => { | ||
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': '{}', | ||
}); | ||
|
||
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': ` | ||
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': '{}', | ||
'some/nested/directory/file.js': '// nothing special', | ||
}); | ||
|
||
const {stderr, exitCode, stdout} = runJest( | ||
path.join(DIR, 'some', 'nested', 'directory'), | ||
['-w=1', '--ci=false'], | ||
{skipPkgJsonCheck: true}, | ||
); | ||
|
||
// Snapshot the console.loged `process.cwd()` and make sure it stays the same | ||
expect( | ||
wrap(stdout.replace(/^\W+(.*)e2e/gm, '<<REPLACED>>')), | ||
).toMatchSnapshot(); | ||
|
||
const {rest, summary} = extractSummary(stderr); | ||
expect(exitCode).toBe(0); | ||
expect(wrap(rest)).toMatchSnapshot(); | ||
expect(wrap(summary)).toMatchSnapshot(); | ||
}); | ||
|
||
test('it does type check the config', () => { | ||
writeFiles(DIR, { | ||
'__tests__/a-giraffe.js': `test('giraffe', () => expect(1).toBe(1));`, | ||
'jest.config.ts': `export default { testTimeout: "10000" }`, | ||
'package.json': '{}', | ||
}); | ||
|
||
const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']); | ||
expect(stderr).toMatch('must be of type'); | ||
expect(exitCode).toBe(1); | ||
}); | ||
|
||
test('invalid JS in jest.config.ts', () => { | ||
writeFiles(DIR, { | ||
'__tests__/a-giraffe.js': `test('giraffe', () => expect(1).toBe(1));`, | ||
'jest.config.ts': `export default i'll break this file yo`, | ||
'package.json': '{}', | ||
}); | ||
|
||
const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']); | ||
expect(stderr).toMatch('TSError: ⨯ Unable to compile TypeScript:'); | ||
expect(exitCode).toBe(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/jest-cli/src/init/__tests__/fixtures/has_jest_config_file_ts/jest.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
export default {}; |
1 change: 1 addition & 0 deletions
1
packages/jest-cli/src/init/__tests__/fixtures/has_jest_config_file_ts/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
1 change: 1 addition & 0 deletions
1
packages/jest-cli/src/init/__tests__/fixtures/test_generated_jest_config_ts/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.