-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathintegration-smoke.test.ts
More file actions
157 lines (132 loc) · 5.11 KB
/
integration-smoke.test.ts
File metadata and controls
157 lines (132 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* eslint-disable jest/require-hook */
// * These are tests that ensure babel-plugin-tester works (1) with the babel
// * versions we claim it does, (2) with the test frameworks we claim it does,
// * (3) with the feature set we claim and interoperability code given in the
// * documentation.
import { toAbsolutePath, toDirname, toRelativePath } from '@-xun/fs';
import { readXPackageJsonAtRoot } from '@-xun/project';
import {
exports as packageExports,
name as packageName,
version as packageVersion
} from 'rootverse:package.json';
import { assets } from 'testverse:integration/assets.ts';
import {
dummyDirectoriesFixture,
dummyFilesFixture,
dummyNpmPackageFixture,
ensurePackageHasBeenBuilt,
nodeImportAndRunTestFixture,
npmCopyPackageFixture,
reconfigureJestGlobalsToSkipTestsInThisFileIfRequested,
testDebugger,
withMockedFixtures
} from 'testverse:util.ts';
import {
BABEL_VERSIONS_UNDER_TEST,
FRAMEWORKS_UNDER_TEST
} from 'testverse:integration/.config.ts';
import type { IMPORT_SPECIFIERS_UNDER_TEST } from 'testverse:integration/.config.ts';
reconfigureJestGlobalsToSkipTestsInThisFileIfRequested({ it: true });
const TEST_IDENTIFIER = 'node-smoke';
const TEST_TARGET: (typeof IMPORT_SPECIFIERS_UNDER_TEST)[number] = 'main'; // * Or: 'pure'
const debug = testDebugger.extend(TEST_IDENTIFIER);
const packageRoot = toAbsolutePath(toDirname(require.resolve('rootverse:package.json')));
debug('FRAMEWORKS_UNDER_TEST: %O', FRAMEWORKS_UNDER_TEST);
debug('BABEL_VERSIONS_UNDER_TEST: %O', BABEL_VERSIONS_UNDER_TEST);
beforeAll(async () => {
await ensurePackageHasBeenBuilt(packageRoot, packageName, packageExports);
});
let counter = 1;
for (const [
index,
[babelPackage, ...otherBabelPkgs]
] of BABEL_VERSIONS_UNDER_TEST.entries()) {
for (const {
frameworkPkg,
frameworkArgs,
otherFrameworkPkgs,
skipLastBabelVersionUnderTest = false,
tests
} of FRAMEWORKS_UNDER_TEST) {
if (skipLastBabelVersionUnderTest && index >= BABEL_VERSIONS_UNDER_TEST.length - 1) {
debug.warn(
'saw skipLastBabelVersionUnderTest=true in FRAMEWORKS_UNDER_TEST entry; skipped testing %O with %O',
babelPackage,
frameworkPkg
);
continue;
}
const otherPkgs = otherBabelPkgs.concat(otherFrameworkPkgs || []);
const pkgsString = [babelPackage, frameworkPkg, ...otherPkgs].join(', ');
for (const [index, { source, expectations }] of tests.entries()) {
const count = counter++;
const title = `${count}. Works with ${pkgsString} [ subtest #${index + 1} ]`;
debug(`registered test: ${title}`);
// eslint-disable-next-line jest/valid-title
it(title, async () => {
expect.hasAssertions();
debug(`started running test: ${title}`);
const indexPath = 'src/index.test.js';
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const importSpecifier = `${packageName}${TEST_TARGET === 'main' ? '' : '/pure'}`;
const sourceInput = source[TEST_TARGET];
const sourceCode =
typeof sourceInput === 'string' ? sourceInput : sourceInput.cjs;
await withMockedFixtures(
async (context) => {
expectations(context);
},
[
dummyNpmPackageFixture,
npmCopyPackageFixture,
dummyDirectoriesFixture,
dummyFilesFixture,
nodeImportAndRunTestFixture
],
{
performCleanup: true,
identifier: TEST_IDENTIFIER,
initialVirtualFiles: {
'package.json': `{"name":"dummy-pkg","dependencies":{"${packageName}":"${packageVersion}"}}`,
'plugin-identifier-reverse.js': assets.pluginIdentifierReverse,
'fixtures/dummy-fixture-asset/code.js':
assets.dummyFixtureAssetCode[TEST_TARGET],
'fixtures/dummy-fixture-asset/options.js':
assets.dummyFixtureAssetOptions[TEST_TARGET],
'fixtures/dummy-fixture-asset/output.js':
assets.dummyFixtureAssetOutput[TEST_TARGET],
[indexPath]: /*ts*/ `
const { pluginTester } = require('${importSpecifier}');
const identifierReversePlugin = require('../plugin-identifier-reverse.js');
${sourceCode}
`
},
directoryPaths: [toRelativePath('fixtures/dummy-fixture-asset')],
additionalPackagesToInstall: [
frameworkPkg,
babelPackage,
...otherPkgs
].filter(
(p): p is string => typeof p === 'string' && !p.startsWith('node:')
),
runWith: {
binary: 'npx',
args: [...frameworkArgs],
runnerOptions: {
env: { NODE_OPTIONS: '--no-warnings --experimental-vm-modules' }
}
},
packageUnderTest: {
root: packageRoot,
json: readXPackageJsonAtRoot.sync(packageRoot, { useCached: true }),
attributes: { cjs: true }
}
}
);
});
}
}
}
debug('finished registering tests');
debug(`registered a total of ${counter} tests!`);