From c49e2e3d9b253e18853b75f7179a6e7b785340fb Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 26 Oct 2020 22:56:27 +0100 Subject: [PATCH] chore: add test verifying top-level await works (#10721) --- .../__snapshots__/nativeEsm.test.ts.snap | 10 +++++++++- e2e/__tests__/nativeEsm.test.ts | 19 ++++++++++++++++++- .../__tests__/native-esm-tla.test.js | 12 ++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 e2e/native-esm/__tests__/native-esm-tla.test.js diff --git a/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap b/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap index 422a1b0e4868..a38414134da2 100644 --- a/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap +++ b/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: <> +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: <> -Ran all test suites. +Ran all test suites matching /native-esm.test.js/i. `; diff --git a/e2e/__tests__/nativeEsm.test.ts b/e2e/__tests__/nativeEsm.test.ts index 49a8427ab0c9..66d6c6d09c1a 100644 --- a/e2e/__tests__/nativeEsm.test.ts +++ b/e2e/__tests__/nativeEsm.test.ts @@ -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', }); @@ -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); + }); +}); diff --git a/e2e/native-esm/__tests__/native-esm-tla.test.js b/e2e/native-esm/__tests__/native-esm-tla.test.js new file mode 100644 index 000000000000..7b34efffe8c7 --- /dev/null +++ b/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!'); +});