Skip to content

Commit 11dc0f8

Browse files
committed
test: improve typescript compat tests
1 parent 9df82f3 commit 11dc0f8

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

test/typings-compatibility/template/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"license": "MIT",
1010
"devDependencies": {
11-
"typescript": "x.x.x"
11+
"typescript": "x.x.x",
12+
"@types/node": "y.y.y"
1213
}
1314
}

test/unit/typings-compatibility-test.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,30 @@ import {assert} from "chai"
2020
* EXCLUDE_TYPINGS_COMPAT_TESTS=true
2121
*/
2222

23-
type TestDef = {version: string; minTarget: string; requiredLibs?: string[]}
23+
type TestDef = {
24+
tscVersion: string
25+
nodeTypesVersion: string
26+
minTarget: string
27+
requiredLibs?: string[]
28+
}
2429

2530
const tsVersions: TestDef[] = [
31+
// the oldest supported version
32+
{tscVersion: "3.7.x", nodeTypesVersion: "10.x", minTarget: "es3"},
33+
34+
// 4.0
35+
{tscVersion: "4.0", nodeTypesVersion: "14.x", minTarget: "es5"},
36+
2637
// 4.x
27-
{version: "4.x", minTarget: "es3"},
38+
{tscVersion: "4.x", nodeTypesVersion: "18.x", minTarget: "es6"},
39+
40+
// 5.x
41+
{tscVersion: "5.x", nodeTypesVersion: "22.x", minTarget: "ES2022"},
2842
]
2943

3044
// use ./typings-test.ts for tsc test, but change the import location for zmq
3145
// to be used from `test/typings-compatibility/ts-x.x.x/typings-test.ts`:
32-
const zmqImportLoc = "../../../"
46+
const zmqImportLoc = "../../../lib"
3347
const srcFile = path.resolve(__dirname, "typings-test.ts")
3448
const srcStr = readFile(srcFile, "utf8").then(content => {
3549
// replace import statement `import * as zmq from ...`:
@@ -71,9 +85,9 @@ async function run(
7185
}
7286

7387
function getItLabelDetails(tsVer: TestDef): string {
74-
const lbl = `v${tsVer.version} for (minimal) compile target ${JSON.stringify(
75-
tsVer.minTarget,
76-
)}`
88+
const lbl = `v${
89+
tsVer.tscVersion
90+
} for (minimal) compile target ${JSON.stringify(tsVer.minTarget)}`
7791
if (!tsVer.requiredLibs || tsVer.requiredLibs.length === 0) {
7892
return lbl
7993
}
@@ -98,12 +112,15 @@ describe("compatibility of typings for typescript versions", async function () {
98112
// the typescript package to complete
99113
this.timeout(30000)
100114

101-
const tscTargetPath = path.resolve(tscTestBasePath, `ts-${tsVer.version}`)
115+
const tscTargetPath = path.resolve(
116+
tscTestBasePath,
117+
`ts-${tsVer.tscVersion}`,
118+
)
102119

103120
it(`it should compile successfully with typescript version ${
104-
tsVer.version
121+
tsVer.tscVersion
105122
// eslint-disable-next-line no-loop-func
106-
}, tsc ${getItLabelDetails(tsVer)}`, async function () {
123+
}, tsc ${getItLabelDetails(tsVer)}`, async () => {
107124
await prepareTestPackage(tscTargetPath, tsVer, execCmd)
108125

109126
const cmd = ["npm", "pnpm"].includes(execCmd) ? `${execCmd} run` : execCmd
@@ -146,8 +163,9 @@ async function prepareTestPackage(
146163
path.resolve(templateSrcPath, "package.json"),
147164
)
148165

149-
pkgJson.name = `test-typings-ts-${tsVer.version}`
150-
pkgJson.devDependencies.typescript = `${tsVer.version}`
166+
pkgJson.name = `test-typings-ts-${tsVer.tscVersion}`
167+
pkgJson.devDependencies.typescript = `${tsVer.tscVersion}`
168+
pkgJson.devDependencies["@types/node"] = tsVer.nodeTypesVersion
151169
return writeJson(path.resolve(tscTargetPath, "package.json"), pkgJson)
152170
})(),
153171
(async () => {

0 commit comments

Comments
 (0)