Skip to content

Commit

Permalink
chore: update test for new node 12 error message (#9030)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Oct 9, 2019
1 parent 464933f commit db7b1b4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion e2e/__tests__/detectOpenHandles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import {wrap} from 'jest-snapshot-serializer-raw';
import {onNodeVersions} from '@jest/test-utils';
import runJest, {until} from '../runJest';
import {onNodeVersions} from '../../packages/test-utils';

try {
require('async_hooks');
Expand Down
9 changes: 8 additions & 1 deletion e2e/__tests__/unexpectedToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import runJest from '../runJest';
import {cleanup, writeFiles} from '../Utils';

const DIR = path.resolve(tmpdir(), 'unexpected-token');
const nodeMajorVersion = Number(process.versions.node.split('.')[0]);

beforeEach(() => cleanup(DIR));
afterEach(() => cleanup(DIR));
Expand Down Expand Up @@ -50,7 +51,13 @@ test('triggers unexpected token error message for untranspiled node_modules', ()
expect(stdout).toBe('');
expect(stderr).toMatch(/Jest encountered an unexpected token/);
expect(stderr).toMatch(/import {module}/);
expect(stderr).toMatch(/Unexpected token/);
if (nodeMajorVersion < 12) {
expect(stderr).toMatch(/Unexpected token/);
} else {
expect(stderr).toMatch(
/SyntaxError: Cannot use import statement outside a module/,
);
}
});

test('does not trigger unexpected token error message for regular syntax errors', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-transform/src/ScriptTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ export default class ScriptTransformer {

if (
e instanceof SyntaxError &&
e.message.includes('Unexpected token') &&
(e.message.includes('Unexpected token') ||
e.message.includes('Cannot use import')) &&
!e.message.includes(' expected')
) {
throw enhanceUnexpectedTokenMessage(e);
Expand Down

0 comments on commit db7b1b4

Please sign in to comment.