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

chore(ci): refactor ts-node compatibility tests #12834

Merged
merged 4 commits into from
May 11, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
and syntax errors
  • Loading branch information
mrazauskas committed May 11, 2022
commit f266a6f11bd404ecfd880e611388343362b2ce73
43 changes: 41 additions & 2 deletions e2e/__tests__/tsIntegration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('when `Config` type is imported from "@jest/types"', () => {
expect(globalConfig.verbose).toBe(true);
});

test('type checks the config file', () => {
test('throws if type errors are encountered', () => {
writeFiles(DIR, {
'__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));",
'jest.config.ts': `
Expand All @@ -74,6 +74,25 @@ describe('when `Config` type is imported from "@jest/types"', () => {
expect(exitCode).toBe(1);
});

test('throws if syntax errors are encountered', () => {
writeFiles(DIR, {
'__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));",
'jest.config.ts': `
import type {Config} from '@jest/types';
const config: Config.InitialOptions = {verbose: true};
export default get config;
`,
'package.json': '{}',
});

const {stderr, exitCode} = runJest(DIR);

expect(stderr).toMatch(
"jest.config.ts(3,16): error TS2304: Cannot find name 'get'.",
);
expect(exitCode).toBe(1);
});

// The versions where vm.Module exists and commonjs with "exports" is not broken
onNodeVersions('>=12.16.0', () => {
test('works with object config exported from TS file when package.json#type=module', () => {
Expand Down Expand Up @@ -115,7 +134,7 @@ describe('when `Config` type is imported from "@jest/types"', () => {
expect(globalConfig.verbose).toBe(true);
});

test('type checks the config file when package.json#type=module', () => {
test('throws if type errors are encountered when package.json#type=module', () => {
writeFiles(DIR, {
'__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));",
'jest.config.ts': `
Expand All @@ -133,5 +152,25 @@ describe('when `Config` type is imported from "@jest/types"', () => {
);
expect(exitCode).toBe(1);
});

test('throws if syntax errors are encountered when package.json#type=module', () => {
writeFiles(DIR, {
'__tests__/dummy.test.js':
"test('dummy', () => expect(123).toBe(123));",
'jest.config.ts': `
import type {Config} from '@jest/types';
const config: Config.InitialOptions = {verbose: true};
export default get config;
`,
'package.json': '{}',
});

const {stderr, exitCode} = runJest(DIR);

expect(stderr).toMatch(
"jest.config.ts(3,16): error TS2304: Cannot find name 'get'.",
);
expect(exitCode).toBe(1);
});
});
});