Skip to content

Commit 497872a

Browse files
authored
Merge pull request #269 from microsoft/test-infrastructure
Validate export structure of every entrypoint
2 parents 6abc075 + f63baa3 commit 497872a

File tree

26 files changed

+135
-104
lines changed

26 files changed

+135
-104
lines changed

.github/workflows/CI.yml

+2-9
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,14 @@ jobs:
99
ci:
1010
runs-on: ubuntu-latest
1111

12-
strategy:
13-
matrix:
14-
node-version: [12.x, 14.x, 16.x]
15-
1612
steps:
1713
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
1814

19-
- name: Use node version ${{ matrix.node-version }}
15+
- name: Setup Node.js
2016
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
2117
with:
22-
node-version: ${{ matrix.node-version }}
18+
node-version: 22.x
2319

2420
- name: Run tests
2521
run: node ./test/runTests.js
2622

27-
- name: Run tests
28-
run: node ./test/validateModuleExportsMatchCommonJS/index.js
29-
if: matrix.node-version == '16.x'

test/cjs/index.js

-2
This file was deleted.

test/cjs/package.json

-6
This file was deleted.

test/esm-node-native/package.json

-9
This file was deleted.

test/node/exportStructure.test.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import assert from "node:assert";
2+
import { test } from "node:test";
3+
4+
import * as tslibJs from "tslib/tslib.js";
5+
import * as tslibEs6Js from "tslib/tslib.es6.js";
6+
import * as tslibEs6Mjs from "tslib/tslib.es6.mjs";
7+
import * as tslibModulesIndex from "tslib/modules/index.js";
8+
9+
test("all helpers available as named exports", () => {
10+
compareKeys("tslib.js", tslibJs, "tslib.es6.js", tslibEs6Js);
11+
compareKeys("tslib.js", tslibJs, "tslib.es6.mjs", tslibEs6Mjs);
12+
compareKeys("tslib.js", tslibJs, "modules/index.js", tslibModulesIndex);
13+
});
14+
15+
test("default export contains all named exports", () => {
16+
assert.ok(tslibJs.default);
17+
compareKeys("tslib.js (default export)", tslibJs.default, "tslib.js (namespace)", tslibJs);
18+
assert.ok(tslibEs6Js.default);
19+
compareKeys("tslib.es6.js (default export)", tslibEs6Js.default, "tslib.es6.js (namespace)", tslibEs6Js);
20+
assert.ok(tslibEs6Mjs.default);
21+
compareKeys("tslib.es6.mjs (default export)", tslibEs6Mjs.default, "tslib.es6.mjs (namespace)", tslibEs6Mjs);
22+
});
23+
24+
/**
25+
* @param {string} name1
26+
* @param {object} tslib1
27+
* @param {string} name2
28+
* @param {object} tslib2
29+
*/
30+
function compareKeys(name1, tslib1, name2, tslib2) {
31+
const difference = new Set(Object.keys(tslib1)).symmetricDifference(new Set(Object.keys(tslib2)));
32+
difference.delete("__esModule");
33+
difference.delete("default"); // Asserted separately where expected
34+
const messages = Array.from(difference).map(missing => `'${missing}' missing in ${missing in tslib1 ? name2 : name1}`);
35+
if (messages.length > 0) {
36+
assert.fail(`Mismatch between ${name1} and ${name2}:\n\n ${messages.join("\n ")}\n`);
37+
}
38+
}

test/node/package.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "module",
3+
"scripts": {
4+
"test": "node --test --experimental-detect-module"
5+
}
6+
}

test/node/testHelper.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { describe } from "node:test";
2+
3+
import * as tslibJs from "tslib/tslib.js";
4+
import * as tslibEs6Js from "tslib/tslib.es6.js";
5+
import * as tslibEs6Mjs from "tslib/tslib.es6.mjs";
6+
7+
/**
8+
* @template {keyof tslibJs} K
9+
* @param {K} helperName
10+
* @param {(helper: tslibJs[K]) => any} test
11+
*/
12+
export function testHelper(helperName, test) {
13+
describe(helperName, () => {
14+
describe("tslib.js", () => {
15+
test(tslibJs[helperName]);
16+
});
17+
describe("tslib.es6.js", () => {
18+
test(tslibEs6Js[helperName]);
19+
});
20+
describe("tslib.es6.mjs", () => {
21+
test(tslibEs6Mjs[helperName]);
22+
});
23+
});
24+
}

test/node/tsconfig.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"module": "NodeNext",
4+
"checkJs": true,
5+
"noEmit": true,
6+
"strict": true,
7+
"forceConsistentCasingInFileNames": true,
8+
"types": ["node"],
9+
}
10+
}

test/package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"dependencies": {
3+
"chalk": "^4.1.2",
4+
"rollup": "4.22.0",
35
"tslib": "file:..",
4-
"rollup": "2.28.2",
5-
"@rollup/plugin-node-resolve": "9.0.0",
6-
"webpack": "4.44.2",
7-
"webpack-cli": "3.3.12",
8-
"snowpack": "2.12.1",
9-
"vite": "2.8.0"
6+
"vite": "5.4.6",
7+
"webpack": "5.94.0",
8+
"webpack-cli": "5.1.4"
109
}
1110
}

test/rollup-modules/rollup.config.js

-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { nodeResolve } from '@rollup/plugin-node-resolve';
2-
31
export default {
42
input: 'index.js',
53
output: {
64
dir: 'build',
75
format: 'cjs'
86
},
9-
plugins: [nodeResolve()]
107
};

test/runTests.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
// @ts-check
12
const { spawnSync } = require("child_process");
23
const fs = require("fs");
34
const path = require("path");
45
const mainVersion = Number(process.version.replace("v","").split(".")[0])
56

67
// Loop through all the folders and run `npm test`
78

8-
const blocklist = ["validateModuleExportsMatchCommonJS", "node_modules"];
99
const filesInTest = fs.readdirSync(__dirname);
1010
const tests = filesInTest
1111
.filter((f) => fs.statSync(path.join(__dirname, f)).isDirectory())
12-
.filter((f) => !blocklist.includes(f));
12+
.filter((f) => f !== "node_modules");
1313

1414
// Support setting up the test node modules
1515
if (!filesInTest.includes("node_modules")) {
@@ -18,7 +18,7 @@ if (!filesInTest.includes("node_modules")) {
1818
console.log("Installed");
1919
}
2020

21-
const chalk = require("chalk").default;
21+
const chalk = require("chalk");
2222
for (const test of tests) {
2323
console.log("---> " + chalk.bold(test));
2424

test/snowpack-modules/index.js

-2
This file was deleted.

test/snowpack-modules/package.json

-10
This file was deleted.

test/validateModuleExportsMatchCommonJS/index.js

-17
This file was deleted.

test/validateModuleExportsMatchCommonJS/package.json

-6
This file was deleted.

test/webpack-4-modules/index.js

-2
This file was deleted.

test/webpack-4-modules/package.json

-5
This file was deleted.

test/webpack-5-modules/index.js

-2
This file was deleted.

test/webpack-5-modules/package.json

-10
This file was deleted.

test/webpack-5-modules/webpack.config.js

-12
This file was deleted.
File renamed without changes.

test/webpack-modules/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"scripts": {
3+
"test": "webpack && node build/main.js"
4+
}
5+
}

tslib.es6.js

+4
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ export default {
354354
__rest: __rest,
355355
__decorate: __decorate,
356356
__param: __param,
357+
__esDecorate: __esDecorate,
358+
__runInitializers: __runInitializers,
359+
__propKey: __propKey,
360+
__setFunctionName: __setFunctionName,
357361
__metadata: __metadata,
358362
__awaiter: __awaiter,
359363
__generator: __generator,

tslib.es6.mjs

+4
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ export default {
353353
__rest,
354354
__decorate,
355355
__param,
356+
__esDecorate,
357+
__runInitializers,
358+
__propKey,
359+
__setFunctionName,
356360
__metadata,
357361
__awaiter,
358362
__generator,

tslib.js

+34
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,37 @@ var __disposeResources;
427427
exporter("__addDisposableResource", __addDisposableResource);
428428
exporter("__disposeResources", __disposeResources);
429429
});
430+
431+
0 && (module.exports = {
432+
__extends,
433+
__assign,
434+
__rest,
435+
__decorate,
436+
__param,
437+
__esDecorate,
438+
__runInitializers,
439+
__propKey,
440+
__setFunctionName,
441+
__metadata,
442+
__awaiter,
443+
__generator,
444+
__exportStar,
445+
__createBinding,
446+
__values,
447+
__read,
448+
__spread,
449+
__spreadArrays,
450+
__spreadArray,
451+
__await,
452+
__asyncGenerator,
453+
__asyncDelegator,
454+
__asyncValues,
455+
__makeTemplateObject,
456+
__importStar,
457+
__importDefault,
458+
__classPrivateFieldGet,
459+
__classPrivateFieldSet,
460+
__classPrivateFieldIn,
461+
__addDisposableResource,
462+
__disposeResources,
463+
});

0 commit comments

Comments
 (0)