Skip to content

Commit c49e2e3

Browse files
authored
chore: add test verifying top-level await works (#10721)
1 parent 08c8fca commit c49e2e3

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`on node >=14.3.0 supports top-level await 1`] = `
4+
Test Suites: 1 passed, 1 total
5+
Tests: 1 passed, 1 total
6+
Snapshots: 0 total
7+
Time: <<REPLACED>>
8+
Ran all test suites matching /native-esm.tla.test.js/i.
9+
`;
10+
311
exports[`on node ^12.16.0 || >=13.7.0 runs test with native ESM 1`] = `
412
Test Suites: 1 passed, 1 total
513
Tests: 15 passed, 15 total
614
Snapshots: 0 total
715
Time: <<REPLACED>>
8-
Ran all test suites.
16+
Ran all test suites matching /native-esm.test.js/i.
917
`;

e2e/__tests__/nativeEsm.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test('test config is without transform', () => {
2323
// The versions where vm.Module exists and commonjs with "exports" is not broken
2424
onNodeVersions('^12.16.0 || >=13.7.0', () => {
2525
test('runs test with native ESM', () => {
26-
const {exitCode, stderr, stdout} = runJest(DIR, [], {
26+
const {exitCode, stderr, stdout} = runJest(DIR, ['native-esm.test.js'], {
2727
nodeOptions: '--experimental-vm-modules',
2828
});
2929

@@ -34,3 +34,20 @@ onNodeVersions('^12.16.0 || >=13.7.0', () => {
3434
expect(exitCode).toBe(0);
3535
});
3636
});
37+
38+
// The versions where TLA is supported
39+
onNodeVersions('>=14.3.0', () => {
40+
test('supports top-level await', () => {
41+
const {exitCode, stderr, stdout} = runJest(
42+
DIR,
43+
['native-esm.tla.test.js'],
44+
{nodeOptions: '--experimental-vm-modules'},
45+
);
46+
47+
const {summary} = extractSummary(stderr);
48+
49+
expect(wrap(summary)).toMatchSnapshot();
50+
expect(stdout).toBe('');
51+
expect(exitCode).toBe(0);
52+
});
53+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
const value = await Promise.resolve('hello!');
9+
10+
test('supports top level await', () => {
11+
expect(value).toBe('hello!');
12+
});

0 commit comments

Comments
 (0)