Skip to content

Commit

Permalink
chore: attempt to skip flaky test (#14699)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Nov 17, 2023
1 parent 3e86cf3 commit 2c3d240
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
37 changes: 26 additions & 11 deletions e2e/__tests__/nativeEsm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down
4 changes: 3 additions & 1 deletion e2e/native-esm/__tests__/native-esm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
});
Expand Down
4 changes: 3 additions & 1 deletion e2e/native-esm/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
3 changes: 3 additions & 0 deletions e2e/native-esm/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2c3d240

Please sign in to comment.