Skip to content

Commit

Permalink
chore: add test verifying top-level await works (#10721)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 26, 2020
1 parent 08c8fca commit c49e2e3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
10 changes: 9 additions & 1 deletion e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap
@@ -1,9 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`on node >=14.3.0 supports top-level await 1`] = `
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm.tla.test.js/i.
`;
exports[`on node ^12.16.0 || >=13.7.0 runs test with native ESM 1`] = `
Test Suites: 1 passed, 1 total
Tests: 15 passed, 15 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
Ran all test suites matching /native-esm.test.js/i.
`;
19 changes: 18 additions & 1 deletion e2e/__tests__/nativeEsm.test.ts
Expand Up @@ -23,7 +23,7 @@ test('test config is without transform', () => {
// 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, [], {
const {exitCode, stderr, stdout} = runJest(DIR, ['native-esm.test.js'], {
nodeOptions: '--experimental-vm-modules',
});

Expand All @@ -34,3 +34,20 @@ onNodeVersions('^12.16.0 || >=13.7.0', () => {
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);
});
});
12 changes: 12 additions & 0 deletions e2e/native-esm/__tests__/native-esm-tla.test.js
@@ -0,0 +1,12 @@
/**
* 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.
*/

const value = await Promise.resolve('hello!');

test('supports top level await', () => {
expect(value).toBe('hello!');
});

0 comments on commit c49e2e3

Please sign in to comment.