-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
/
Copy pathnativeEsm.test.ts
53 lines (43 loc) · 1.51 KB
/
nativeEsm.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* 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 {resolve} from 'path';
import wrap from 'jest-snapshot-serializer-raw';
import {onNodeVersions} from '@jest/test-utils';
import {extractSummary} from '../Utils';
import runJest, {getConfig} from '../runJest';
const DIR = resolve(__dirname, '../native-esm');
test('test config is without transform', () => {
const {configs} = getConfig(DIR);
expect(configs).toHaveLength(1);
expect(configs[0].transform).toEqual([]);
});
// The versions where vm.Module exists and commonjs with "exports" is not broken
onNodeVersions('^12.16.0 || >=13.7.0', () => {
test('runs test with native ESM', () => {
const {exitCode, stderr, stdout} = runJest(DIR, ['native-esm.test.js'], {
nodeOptions: '--experimental-vm-modules',
});
const {summary} = extractSummary(stderr);
expect(wrap(summary)).toMatchSnapshot();
expect(stdout).toBe('');
expect(exitCode).toBe(0);
});
});
// The versions where TLA is supported
onNodeVersions('>=14.3.0', () => {
test('supports top-level await', () => {
const {exitCode, stderr, stdout} = runJest(
DIR,
['native-esm.tla.test.js'],
{nodeOptions: '--experimental-vm-modules'},
);
const {summary} = extractSummary(stderr);
expect(wrap(summary)).toMatchSnapshot();
expect(stdout).toBe('');
expect(exitCode).toBe(0);
});
});