From 2c3d2409879952157433de215ae0eee5188a4384 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 17 Nov 2023 13:25:50 +0100 Subject: [PATCH] chore: attempt to skip flaky test (#14699) --- e2e/__tests__/nativeEsm.test.ts | 37 +++++++++++++++------ e2e/native-esm/__tests__/native-esm.test.js | 4 ++- e2e/native-esm/package.json | 4 ++- e2e/native-esm/yarn.lock | 3 ++ 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/e2e/__tests__/nativeEsm.test.ts b/e2e/__tests__/nativeEsm.test.ts index 4d54936a4a2f..387a54a87168 100644 --- a/e2e/__tests__/nativeEsm.test.ts +++ b/e2e/__tests__/nativeEsm.test.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +import {createRequire} from 'module'; import {resolve} from 'path'; import {onNodeVersions} from '@jest/test-utils'; import {extractSummary, runYarnInstall} from '../Utils'; @@ -16,8 +17,19 @@ jest.retryTimes(3); const DIR = resolve(__dirname, '../native-esm'); +let isolatedVmInstalled = false; + beforeAll(() => { runYarnInstall(DIR); + + const require = createRequire(`${DIR}/index.js`); + + try { + const ivm = require('isolated-vm'); + isolatedVmInstalled = ivm != null; + } catch (error) { + console.warn('`isolated-vm` is not installed, skipping tests', error); + } }); test('test config is without transform', () => { @@ -108,19 +120,22 @@ test('does not enforce import assertions', () => { expect(exitCode).toBe(0); }); -test('properly handle re-exported native modules in ESM via CJS', () => { - const {exitCode, stderr, stdout} = runJest( - DIR, - ['native-esm-native-module.test.js'], - {nodeOptions: '--experimental-vm-modules --no-warnings'}, - ); +(isolatedVmInstalled ? test : test.skip)( + 'properly handle re-exported native modules in ESM via CJS', + () => { + const {exitCode, stderr, stdout} = runJest( + DIR, + ['native-esm-native-module.test.js'], + {nodeOptions: '--experimental-vm-modules --no-warnings'}, + ); - const {summary} = extractSummary(stderr); + const {summary} = extractSummary(stderr); - expect(summary).toMatchSnapshot(); - expect(stdout).toBe(''); - expect(exitCode).toBe(0); -}); + expect(summary).toMatchSnapshot(); + expect(stdout).toBe(''); + expect(exitCode).toBe(0); + }, +); // version where `vm` API gets `import assertions` onNodeVersions('>=16.12.0', () => { diff --git a/e2e/native-esm/__tests__/native-esm.test.js b/e2e/native-esm/__tests__/native-esm.test.js index caacf8a51e90..d9b18c7ca440 100644 --- a/e2e/native-esm/__tests__/native-esm.test.js +++ b/e2e/native-esm/__tests__/native-esm.test.js @@ -49,13 +49,15 @@ test('should support importing node core modules', () => { devDependencies: { 'discord.js': '14.3.0', 'iso-constants': '^0.1.2', - 'isolated-vm': '^4.6.0', yargs: '^17.5.1', }, jest: { testEnvironment: 'node', transform: {}, }, + optionalDependencies: { + 'isolated-vm': '^4.6.0', + }, type: 'module', }); }); diff --git a/e2e/native-esm/package.json b/e2e/native-esm/package.json index 4ce1cc1741df..c113bde36bab 100644 --- a/e2e/native-esm/package.json +++ b/e2e/native-esm/package.json @@ -1,9 +1,11 @@ { "type": "module", + "optionalDependencies": { + "isolated-vm": "^4.6.0" + }, "devDependencies": { "discord.js": "14.3.0", "iso-constants": "^0.1.2", - "isolated-vm": "^4.6.0", "yargs": "^17.5.1" }, "jest": { diff --git a/e2e/native-esm/yarn.lock b/e2e/native-esm/yarn.lock index 9de4fdf036fb..04cccfa78471 100644 --- a/e2e/native-esm/yarn.lock +++ b/e2e/native-esm/yarn.lock @@ -1259,6 +1259,9 @@ __metadata: iso-constants: ^0.1.2 isolated-vm: ^4.6.0 yargs: ^17.5.1 + dependenciesMeta: + isolated-vm: + optional: true languageName: unknown linkType: soft