forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move smoke test package script into scripts (microsoft#53245)
- Loading branch information
1 parent
9769421
commit 9ccf47f
Showing
4 changed files
with
48 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { createRequire } from "module"; | ||
import { __importDefault, __importStar } from "tslib"; | ||
|
||
// This script tests that TypeScript's CJS API is structured | ||
// as expected. It calls "require" as though it were in CWD, | ||
// so it can be tested on a separate install of TypeScript. | ||
|
||
const require = createRequire(process.cwd() + "/index.js"); | ||
|
||
console.log(`Testing ${process.argv[2]}...`); | ||
const ts = require(process.argv[2]); | ||
|
||
// See: https://github.com/microsoft/TypeScript/pull/51474#issuecomment-1310871623 | ||
/** @type {[fn: (() => any), shouldSucceed: boolean][]} */ | ||
const fns = [ | ||
[() => ts.version, true], | ||
[() => ts.default.version, false], | ||
[() => __importDefault(ts).version, false], | ||
[() => __importDefault(ts).default.version, true], | ||
[() => __importStar(ts).version, true], | ||
[() => __importStar(ts).default.version, true], | ||
]; | ||
|
||
for (const [fn, shouldSucceed] of fns) { | ||
let success = false; | ||
try { | ||
success = !!fn(); | ||
} | ||
catch { | ||
// Ignore | ||
} | ||
const status = success ? "succeeded" : "failed"; | ||
if (success === shouldSucceed) { | ||
console.log(`${fn.toString()} ${status} as expected.`); | ||
} | ||
else { | ||
console.log(`${fn.toString()} unexpectedly ${status}.`); | ||
process.exitCode = 1; | ||
} | ||
} | ||
console.log("ok"); |