Skip to content

Commit af644e2

Browse files
committed
ci(test): add maintained node versions sub-tests directly to integration tests
1 parent 330aa1e commit af644e2

File tree

2 files changed

+93
-73
lines changed

2 files changed

+93
-73
lines changed

test/integration/integration-node-interop.test.ts

Lines changed: 86 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33

44
// * These are tests that ensure babel-plugin-tester works (1) in ESM vs CJS
55
// * environments, (2) using modern vs modern-default vs default vs dot-default
6-
// * import syntax, (3) using main vs pure import specifiers.
6+
// * import syntax, (3) using main vs pure import specifiers, (4) across all
7+
// * maintained versions of NodeJS.
78

89
import { existsSync } from 'node:fs';
910
import debugFactory from 'debug';
1011
import mergeWith from 'lodash.mergewith';
12+
import path from 'node:path';
1113

1214
import { name as pkgName, exports as pkgExports } from '../../package.json';
1315
import { withMockedFixture } from '../setup';
1416
import { assets } from './assets';
17+
import { expectSuccessAndOutput } from './test-expectations';
1518

1619
import {
1720
defaultFixtureOptions,
1821
BABEL_VERSIONS_UNDER_TEST,
1922
IMPORT_SPECIFIERS_UNDER_TEST,
20-
IMPORT_STYLES_UNDER_TEST
23+
IMPORT_STYLES_UNDER_TEST,
24+
NODE_VERSIONS_UNDER_TEST
2125
} from './test-config';
22-
import { expectSuccessAndOutput } from './test-expectations';
23-
import { withNodeTestInterop } from './test-interop';
2426

2527
const TEST_IDENTIFIER = 'node-interop';
2628
const debug = debugFactory(`${pkgName}:${TEST_IDENTIFIER}`);
@@ -49,93 +51,104 @@ let counter = 1;
4951
for (const esm of [true, false] as const) {
5052
for (const importSpecifierName of IMPORT_SPECIFIERS_UNDER_TEST) {
5153
for (const importStyleName of IMPORT_STYLES_UNDER_TEST) {
52-
const count = counter++;
53-
const title = `${count}. works as a ${importStyleName} ${importSpecifierName} ${
54-
esm ? 'ESM' : 'CJS'
55-
} import`;
56-
57-
if (esm && importStyleName == 'dot-default') {
58-
debug(`skipped test due to incompatible options: ${title}`);
59-
continue;
60-
}
61-
62-
debug(`registered test: ${title}`);
63-
64-
// eslint-disable-next-line jest/valid-title
65-
(process.env.NO_CONCURRENT ? it : it.concurrent)(title, async () => {
66-
// eslint-disable-next-line jest/no-standalone-expect
67-
expect.hasAssertions();
68-
69-
debug(`started running test: ${title}`);
70-
71-
const indexPath = `src/index.test.${esm ? 'm' : ''}js`;
72-
const importSpecifier = `${pkgName}${
73-
importSpecifierName == 'main' ? '' : '/pure'
74-
}`;
75-
76-
const importStyle = {
77-
modern: '{ pluginTester }',
78-
'modern-default': '{ default: pluginTester }',
79-
default: 'pluginTester',
80-
'dot-default': 'pluginTester'
81-
}[importStyleName];
82-
83-
const fixtureOptions = mergeWith(
84-
{},
85-
defaultFixtureOptions,
86-
{
87-
npmInstall: ['@babel/core@latest'],
88-
runWith: {
89-
binary: 'npx',
90-
args: ['node']
54+
for (const nodeVersion of NODE_VERSIONS_UNDER_TEST) {
55+
const count = counter++;
56+
const title = `${count}. works as a ${importStyleName} ${importSpecifierName} ${
57+
esm ? 'ESM' : 'CJS'
58+
} import using ${nodeVersion}`;
59+
60+
if (esm && importStyleName == 'dot-default') {
61+
debug(`skipped test due to incompatible options: ${title}`);
62+
continue;
63+
}
64+
65+
debug(`registered test: ${title}`);
66+
67+
// eslint-disable-next-line jest/valid-title
68+
(process.env.NO_CONCURRENT ? it : it.concurrent)(title, async () => {
69+
// eslint-disable-next-line jest/no-standalone-expect
70+
expect.hasAssertions();
71+
72+
debug(`started running test: ${title}`);
73+
74+
const indexPath = `src/index.test.${esm ? 'm' : ''}js`;
75+
const importSpecifier = `${pkgName}${
76+
importSpecifierName == 'main' ? '' : '/pure'
77+
}`;
78+
79+
const importStyle = {
80+
modern: '{ pluginTester }',
81+
'modern-default': '{ default: pluginTester }',
82+
default: 'pluginTester',
83+
'dot-default': 'pluginTester'
84+
}[importStyleName];
85+
86+
const fixtureOptions = mergeWith(
87+
{},
88+
defaultFixtureOptions,
89+
{
90+
performCleanup: false,
91+
runInstallScripts: true,
92+
npmInstall: ['@babel/core@latest', 'jest@latest', nodeVersion],
93+
runWith: {
94+
binary: path.join('node_modules', '.bin', 'node'),
95+
args: [
96+
'--experimental-vm-modules',
97+
path.join('node_modules', '.bin', 'jest')
98+
]
99+
}
100+
},
101+
{
102+
initialFileContents: {
103+
'jest.config.js':
104+
'module.exports = {testMatch:["**/?(*.)+(spec|test).?(m)[jt]s?(x)"],transform:{}};',
105+
'fixtures/dummy-fixture-asset/code.js':
106+
assets.dummyFixtureAssetCode[importSpecifierName],
107+
'fixtures/dummy-fixture-asset/options.js':
108+
assets.dummyFixtureAssetOptions[importSpecifierName],
109+
'fixtures/dummy-fixture-asset/output.js':
110+
assets.dummyFixtureAssetOutput[importSpecifierName]
111+
}
91112
}
92-
},
93-
{
94-
initialFileContents: {
95-
'fixtures/dummy-fixture-asset/code.js':
96-
assets.dummyFixtureAssetCode[importSpecifierName],
97-
'fixtures/dummy-fixture-asset/options.js':
98-
assets.dummyFixtureAssetOptions[importSpecifierName],
99-
'fixtures/dummy-fixture-asset/output.js':
100-
assets.dummyFixtureAssetOutput[importSpecifierName]
101-
}
102-
}
103-
);
113+
);
104114

105-
const sourceInput = withNodeTestInterop(assets.invocation)[importSpecifierName];
106-
const sourceCode =
107-
typeof sourceInput == 'string' ? sourceInput : sourceInput[esm ? 'esm' : 'cjs'];
115+
const sourceInput = assets.invocation[importSpecifierName];
116+
const sourceCode =
117+
typeof sourceInput == 'string'
118+
? sourceInput
119+
: sourceInput[esm ? 'esm' : 'cjs'];
108120

109-
fixtureOptions.initialFileContents[indexPath] = esm
110-
? `
121+
fixtureOptions.initialFileContents[indexPath] = esm
122+
? `
111123
import ${
112124
esm ? importStyle.replaceAll(':', ' as') : importStyle
113125
} from '${importSpecifier}';
114126
import identifierReversePlugin from '../plugin-identifier-reverse.js';
115127
116128
${sourceCode}
117129
`
118-
: `
130+
: `
119131
const ${importStyle} = require('${importSpecifier}')${
120-
importStyleName == 'dot-default' ? '.default' : ''
121-
};
132+
importStyleName == 'dot-default' ? '.default' : ''
133+
};
122134
const identifierReversePlugin = require('../plugin-identifier-reverse.js');
123135
124136
${sourceCode}
125137
`;
126138

127-
await withMockedFixture({
128-
testIdentifier: TEST_IDENTIFIER,
129-
options: fixtureOptions,
130-
fn: async (context) => {
131-
if (!context.testResult) {
132-
throw new Error('must use node-import-test fixture');
133-
}
139+
await withMockedFixture({
140+
testIdentifier: TEST_IDENTIFIER,
141+
options: fixtureOptions,
142+
fn: async (context) => {
143+
if (!context.testResult) {
144+
throw new Error('must use node-import-test fixture');
145+
}
134146

135-
expectSuccessAndOutput(context);
136-
}
147+
expectSuccessAndOutput(context);
148+
}
149+
});
137150
});
138-
});
151+
}
139152
}
140153
}
141154
}

test/integration/test-config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// * numbers will only change when the configuration below changes. You can also
88
// * match against test framework names (like `node:test`) and other settings.
99

10+
import browserslist from 'browserslist';
11+
1012
import { name as pkgName, version as pkgVersion } from '../../package.json';
1113
import { withNodeTestInterop, withJasmineInterop } from './test-interop';
1214
import { assets } from './assets';
@@ -53,6 +55,11 @@ export const BABEL_VERSIONS_UNDER_TEST = ([
5355
['@babel/core@latest'] // ? Latest version
5456
]);
5557

58+
// * [node@version, ...]
59+
export const NODE_VERSIONS_UNDER_TEST = browserslist('maintained node versions').map(
60+
(v) => v.split(' ').join('@')
61+
);
62+
5663
export const FRAMEWORKS_UNDER_TEST: FrameworksUnderTest = [
5764
{
5865
frameworkPkg: 'jest@latest',

0 commit comments

Comments
 (0)