|
7 | 7 |
|
8 | 8 | import * as path from 'path';
|
9 | 9 | import {cleanup, writeFiles} from '../Utils';
|
10 |
| -import runJest, {getConfig} from '../runJest'; |
| 10 | +import runJest, {getConfig, useNativeTypeScript} from '../runJest'; |
11 | 11 |
|
12 | 12 | const DIR = path.resolve(__dirname, '../ts-node-integration');
|
13 | 13 |
|
14 | 14 | beforeEach(() => cleanup(DIR));
|
15 | 15 | afterAll(() => cleanup(DIR));
|
16 | 16 |
|
| 17 | +// Node.js's builtin TypeScript support doesn't do type checking, so skip tests |
| 18 | +// that validate type-checking behavior. |
| 19 | +const testIfTsLoader = useNativeTypeScript ? test.skip : test; |
| 20 | + |
17 | 21 | describe('when `Config` type is imported from "@jest/types"', () => {
|
18 | 22 | test('with object config exported from TS file', () => {
|
19 | 23 | writeFiles(DIR, {
|
@@ -93,7 +97,7 @@ describe('when `Config` type is imported from "@jest/types"', () => {
|
93 | 97 | expect(globalConfig.verbose).toBe(true);
|
94 | 98 | });
|
95 | 99 |
|
96 |
| - test('throws if type errors are encountered', () => { |
| 100 | + testIfTsLoader('throws if type errors are encountered', () => { |
97 | 101 | writeFiles(DIR, {
|
98 | 102 | '__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));",
|
99 | 103 | 'jest.config.ts': `
|
@@ -247,24 +251,27 @@ describe('when `Config` type is imported from "@jest/types"', () => {
|
247 | 251 | expect(globalConfig.verbose).toBe(true);
|
248 | 252 | });
|
249 | 253 |
|
250 |
| - test('throws if type errors are encountered when package.json#type=module', () => { |
251 |
| - writeFiles(DIR, { |
252 |
| - '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", |
253 |
| - 'jest.config.ts': ` |
| 254 | + testIfTsLoader( |
| 255 | + 'throws if type errors are encountered when package.json#type=module', |
| 256 | + () => { |
| 257 | + writeFiles(DIR, { |
| 258 | + '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", |
| 259 | + 'jest.config.ts': ` |
254 | 260 | import type {Config} from '@jest/types';
|
255 | 261 | const config: Config.InitialOptions = {testTimeout: '10000'};
|
256 | 262 | export default config;
|
257 | 263 | `,
|
258 |
| - 'package.json': '{"type": "module"}', |
259 |
| - }); |
| 264 | + 'package.json': '{"type": "module"}', |
| 265 | + }); |
260 | 266 |
|
261 |
| - const {stderr, exitCode} = runJest(DIR); |
| 267 | + const {stderr, exitCode} = runJest(DIR); |
262 | 268 |
|
263 |
| - expect(stderr).toMatch( |
264 |
| - "jest.config.ts(2,40): error TS2322: Type 'string' is not assignable to type 'number'.", |
265 |
| - ); |
266 |
| - expect(exitCode).toBe(1); |
267 |
| - }); |
| 269 | + expect(stderr).toMatch( |
| 270 | + "jest.config.ts(2,40): error TS2322: Type 'string' is not assignable to type 'number'.", |
| 271 | + ); |
| 272 | + expect(exitCode).toBe(1); |
| 273 | + }, |
| 274 | + ); |
268 | 275 |
|
269 | 276 | test('throws if syntax errors are encountered when package.json#type=module', () => {
|
270 | 277 | writeFiles(DIR, {
|
@@ -403,7 +410,7 @@ describe('when `Config` type is imported from "jest"', () => {
|
403 | 410 | expect(globalConfig.verbose).toBe(true);
|
404 | 411 | });
|
405 | 412 |
|
406 |
| - test('throws if type errors are encountered', () => { |
| 413 | + testIfTsLoader('throws if type errors are encountered', () => { |
407 | 414 | writeFiles(DIR, {
|
408 | 415 | '__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));",
|
409 | 416 | 'jest.config.ts': `
|
@@ -557,24 +564,27 @@ describe('when `Config` type is imported from "jest"', () => {
|
557 | 564 | expect(globalConfig.verbose).toBe(true);
|
558 | 565 | });
|
559 | 566 |
|
560 |
| - test('throws if type errors are encountered when package.json#type=module', () => { |
561 |
| - writeFiles(DIR, { |
562 |
| - '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", |
563 |
| - 'jest.config.ts': ` |
| 567 | + testIfTsLoader( |
| 568 | + 'throws if type errors are encountered when package.json#type=module', |
| 569 | + () => { |
| 570 | + writeFiles(DIR, { |
| 571 | + '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", |
| 572 | + 'jest.config.ts': ` |
564 | 573 | import type {Config} from 'jest';
|
565 | 574 | const config: Config = {testTimeout: '10000'};
|
566 | 575 | export default config;
|
567 | 576 | `,
|
568 |
| - 'package.json': '{"type": "module"}', |
569 |
| - }); |
| 577 | + 'package.json': '{"type": "module"}', |
| 578 | + }); |
570 | 579 |
|
571 |
| - const {stderr, exitCode} = runJest(DIR); |
| 580 | + const {stderr, exitCode} = runJest(DIR); |
572 | 581 |
|
573 |
| - expect(stderr).toMatch( |
574 |
| - "jest.config.ts(2,25): error TS2322: Type 'string' is not assignable to type 'number'.", |
575 |
| - ); |
576 |
| - expect(exitCode).toBe(1); |
577 |
| - }); |
| 582 | + expect(stderr).toMatch( |
| 583 | + "jest.config.ts(2,25): error TS2322: Type 'string' is not assignable to type 'number'.", |
| 584 | + ); |
| 585 | + expect(exitCode).toBe(1); |
| 586 | + }, |
| 587 | + ); |
578 | 588 |
|
579 | 589 | test('throws if syntax errors are encountered when package.json#type=module', () => {
|
580 | 590 | writeFiles(DIR, {
|
|
0 commit comments