Emulate some CJS and ESM projects as unit test not to break user projects#1605
Emulate some CJS and ESM projects as unit test not to break user projects#1605Yang-33 wants to merge 7 commits into
Conversation
| const repoRoot = process.cwd(); | ||
| const tempDirs: string[] = []; | ||
| let tarballPath = ""; | ||
| const TS5_VERSION = "5.9.3"; |
There was a problem hiding this comment.
Would it make sense to use a semver range like ~5.9 here (and ^6.0 in the ts6 spec) instead of pinning the exact patch?
Since these tests aim to emulate real consumer projects, automatically picking up patch/minor TS updates would let us catch breakages of the shipped .d.ts against future TS releases earlier. The min-release-age=7 in .npmrc already mitigates zero-day supply-chain risk.
If CI determinism is the priority, pinning is also reasonable — just sharing a thought.
There was a problem hiding this comment.
specific version is better to make build stable?
| } | ||
|
|
||
| afterAll(async () => { | ||
| await Promise.all(tempDirs.map(dir => removeDir(dir))); |
There was a problem hiding this comment.
[nits] Using Promise.allSettled here (and in the other spec files that share the same pattern) would ensure the remaining temp dirs are still cleaned up even if one removal fails.
There was a problem hiding this comment.
mkdtemp creates a temporary directory, so I think it should be removed automatically, but your point makes sense. I fixed it.
| interface TsLaneConfig { | ||
| readonly fixtureName: string; | ||
| readonly packageTemplateFile: "package.module.json" | "package.commonjs.json"; | ||
| readonly tsconfigTemplateFile: | ||
| | "tsconfig.nodenext.json" | ||
| | "tsconfig.node16.json" | ||
| | "tsconfig.bundler.json"; | ||
| readonly withRuntime: boolean; | ||
| } | ||
|
|
||
| async function runTsLane(config: TsLaneConfig): Promise<void> { | ||
| const fixtureDir = await prepareFixtureDir(config.fixtureName); | ||
| await materializeTsFixture({ | ||
| repoRoot, | ||
| outDir: fixtureDir, | ||
| packageTemplateFile: config.packageTemplateFile, | ||
| tsconfigTemplateFile: config.tsconfigTemplateFile, | ||
| tsVersion: TS6_VERSION, | ||
| }); | ||
|
|
||
| installSdkTarball(fixtureDir, tarballPath); | ||
| runCommand(fixtureDir, "npm", ["run", "build"]); | ||
| if (config.withRuntime) { | ||
| runCommand(fixtureDir, "npm", ["run", "run:resolution"]); | ||
| } | ||
| } |
There was a problem hiding this comment.
[nits] TsLaneConfig / runTsLane are nearly identical between this file and consumer-contract-ts5.spec.ts. Extracting a shared helper could make adding future TS major versions (ts7, ...) easier.
There was a problem hiding this comment.
Alright, I created a common for the common parts! 😄 323676e
…026-05-08 # Conflicts: # .npmrc
|
PTAL~ |
resolve #1585
We need to keep the dual package for another 2 to 3 years.
Therefore, we need to prevent regressions in ESM and CJS support caused by TypeScript config changes or publishing changes.
This change adds tests for that. The local execution time increases by about 30 seconds, which I think is acceptable.