Skip to content

Commit 9ccf47f

Browse files
authored
Move smoke test package script into scripts (microsoft#53245)
1 parent 9769421 commit 9ccf47f

File tree

4 files changed

+48
-37
lines changed

4 files changed

+48
-37
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -107,55 +107,23 @@ jobs:
107107
- run: |
108108
npm pack
109109
mv typescript*.tgz typescript.tgz
110-
echo "PACKAGE=$PWD/typescript.tgz" >> $GITHUB_ENV
110+
echo "package=$PWD/typescript.tgz" >> "$GITHUB_OUTPUT"
111+
id: pack
111112
112113
- name: Smoke test
113114
run: |
114115
cd "$(mktemp -d)"
115116
npm init --yes
116-
npm install $PACKAGE tslib
117+
npm install ${{ steps.pack.outputs.package }}
117118
118119
echo "Testing tsc..."
119120
npx tsc --version
120121
121122
echo "Testing tsserver..."
122123
echo '{"seq": 1, "command": "status"}' | npx tsserver
123124
124-
cat > smoke.js << 'EOF'
125-
console.log(`Testing ${process.argv[2]}...`);
126-
const { __importDefault, __importStar } = require("tslib");
127-
const ts = require(process.argv[2]);
128-
129-
// See: https://github.com/microsoft/TypeScript/pull/51474#issuecomment-1310871623
130-
const fns = [
131-
[() => ts.version, true],
132-
[() => ts.default.version, false],
133-
[() => __importDefault(ts).version, false],
134-
[() => __importDefault(ts).default.version, true],
135-
[() => __importStar(ts).version, true],
136-
[() => __importStar(ts).default.version, true],
137-
];
138-
139-
for (const [fn, shouldSucceed] of fns) {
140-
let success = false;
141-
try {
142-
success = !!fn();
143-
}
144-
catch {}
145-
const status = success ? "succeeded" : "failed";
146-
if (success === shouldSucceed) {
147-
console.log(`${fn.toString()} ${status} as expected.`);
148-
}
149-
else {
150-
console.log(`${fn.toString()} unexpectedly ${status}.`);
151-
process.exitCode = 1;
152-
}
153-
}
154-
console.log("ok");
155-
EOF
156-
157-
node ./smoke.js typescript
158-
node ./smoke.js typescript/lib/tsserverlibrary
125+
node $GITHUB_WORKSPACE/scripts/checkModuleFormat.mjs typescript
126+
node $GITHUB_WORKSPACE/scripts/checkModuleFormat.mjs typescript/lib/tsserverlibrary
159127
160128
package-size:
161129
runs-on: ubuntu-latest

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"ms": "^2.1.3",
7979
"node-fetch": "^3.2.10",
8080
"source-map-support": "^0.5.21",
81+
"tslib": "^2.5.0",
8182
"typescript": "5.0.1-rc",
8283
"which": "^2.0.2"
8384
},

scripts/checkModuleFormat.mjs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { createRequire } from "module";
2+
import { __importDefault, __importStar } from "tslib";
3+
4+
// This script tests that TypeScript's CJS API is structured
5+
// as expected. It calls "require" as though it were in CWD,
6+
// so it can be tested on a separate install of TypeScript.
7+
8+
const require = createRequire(process.cwd() + "/index.js");
9+
10+
console.log(`Testing ${process.argv[2]}...`);
11+
const ts = require(process.argv[2]);
12+
13+
// See: https://github.com/microsoft/TypeScript/pull/51474#issuecomment-1310871623
14+
/** @type {[fn: (() => any), shouldSucceed: boolean][]} */
15+
const fns = [
16+
[() => ts.version, true],
17+
[() => ts.default.version, false],
18+
[() => __importDefault(ts).version, false],
19+
[() => __importDefault(ts).default.version, true],
20+
[() => __importStar(ts).version, true],
21+
[() => __importStar(ts).default.version, true],
22+
];
23+
24+
for (const [fn, shouldSucceed] of fns) {
25+
let success = false;
26+
try {
27+
success = !!fn();
28+
}
29+
catch {
30+
// Ignore
31+
}
32+
const status = success ? "succeeded" : "failed";
33+
if (success === shouldSucceed) {
34+
console.log(`${fn.toString()} ${status} as expected.`);
35+
}
36+
else {
37+
console.log(`${fn.toString()} unexpectedly ${status}.`);
38+
process.exitCode = 1;
39+
}
40+
}
41+
console.log("ok");

0 commit comments

Comments
 (0)