-
Notifications
You must be signed in to change notification settings - Fork 429
Emulate some CJS and ESM projects as unit test not to break user projects #1605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1444f62
test dual package
Yang-33 de5c5bf
polish
Yang-33 7a8da60
Add timeout for new process
Yang-33 cf118b7
polish 2
Yang-33 5049102
Merge branch 'master' into dual-package-test-2026-05-08
Yang-33 f90db32
Merge remote-tracking branch 'origin/master' into dual-package-test-2…
Yang-33 323676e
setup common of common
Yang-33 bb1f6fc
Merge branch 'master' into dual-package-test-2026-05-08
Yang-33 a565370
Merge branch 'master' into dual-package-test-2026-05-08
Yang-33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,65 @@ | ||
| import { afterAll, beforeAll, describe, it } from "vitest"; | ||
| import { | ||
| buildPackedTarball, | ||
| copyDir, | ||
| installSdkTarball, | ||
| prepareFixtureDir, | ||
| removeDir, | ||
| runCommand, | ||
| } from "./runner"; | ||
|
|
||
| const repoRoot = process.cwd(); | ||
| const tempDirs: string[] = []; | ||
| let tarballPath = ""; | ||
| const JS_TIMEOUT_MS = 180_000; | ||
|
|
||
| async function runJsFixture( | ||
| fixtureName: "js-esm" | "js-cjs", | ||
| scripts: readonly string[], | ||
| ): Promise<void> { | ||
| const fixtureDir = await prepareFixtureDir(tempDirs, fixtureName); | ||
| await copyDir( | ||
| `${repoRoot}/test/consumer/fixtures/${fixtureName}`, | ||
| fixtureDir, | ||
| ); | ||
| installSdkTarball(fixtureDir, tarballPath); | ||
|
|
||
| for (const script of scripts) { | ||
| runCommand(fixtureDir, "node", [script]); | ||
| } | ||
| } | ||
|
|
||
| afterAll(async () => { | ||
| await Promise.allSettled(tempDirs.map(dir => removeDir(dir))); | ||
| }); | ||
|
|
||
| describe("dual package JS consumer contract", () => { | ||
| beforeAll(async () => { | ||
| const packOutDir = await prepareFixtureDir(tempDirs, "js-pack"); | ||
| tarballPath = await buildPackedTarball(repoRoot, packOutDir); | ||
| }); | ||
|
|
||
| it( | ||
| "runs JS ESM fixture with resolution and behavioral contract checks", | ||
| async () => { | ||
| await runJsFixture("js-esm", [ | ||
| "./resolution-load-check.mjs", | ||
| "./outbound-http-contract.mjs", | ||
| "./webhook-signature-contract.mjs", | ||
| ]); | ||
| }, | ||
| JS_TIMEOUT_MS, | ||
| ); | ||
|
|
||
| it( | ||
| "runs JS CJS fixture resolution and behavioral contract checks", | ||
| async () => { | ||
| await runJsFixture("js-cjs", [ | ||
| "./resolution-load-check.cjs", | ||
| "./outbound-http-contract.cjs", | ||
| "./webhook-signature-contract.cjs", | ||
| ]); | ||
| }, | ||
| JS_TIMEOUT_MS, | ||
| ); | ||
| }); |
This file contains hidden or 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,69 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { existsSync } from "node:fs"; | ||
| import { afterAll, beforeAll, describe, it } from "vitest"; | ||
| import { | ||
| buildPackedTarball, | ||
| listTarEntries, | ||
| prepareFixtureDir, | ||
| readTarPackageJson, | ||
| removeDir, | ||
| } from "./runner"; | ||
|
|
||
| const repoRoot = process.cwd(); | ||
| const tempDirs: string[] = []; | ||
| let tarballPath = ""; | ||
|
|
||
| afterAll(async () => { | ||
| await Promise.allSettled(tempDirs.map(dir => removeDir(dir))); | ||
| }); | ||
|
|
||
| describe("dual package packaging contract", () => { | ||
| beforeAll(async () => { | ||
| const packOutDir = await prepareFixtureDir(tempDirs, "packaging-pack"); | ||
| tarballPath = await buildPackedTarball(repoRoot, packOutDir); | ||
| assert.equal(existsSync(tarballPath), true); | ||
| }); | ||
|
|
||
| it("includes required export targets and metadata", async () => { | ||
| const entries = listTarEntries(repoRoot, tarballPath); | ||
| const requiredEntries = [ | ||
| "package/dist/index.js", | ||
| "package/dist/index.d.ts", | ||
| "package/dist/cjs/index.js", | ||
| "package/dist/cjs/index.d.ts", | ||
| "package/dist/cjs/package.json", | ||
| "package/package.json", | ||
| ]; | ||
|
|
||
| for (const entry of requiredEntries) { | ||
| assert.equal( | ||
| entries.includes(entry), | ||
| true, | ||
| `${entry} was not found in tarball`, | ||
| ); | ||
| } | ||
|
|
||
| const packagedJson = await readTarPackageJson(repoRoot, tarballPath); | ||
| assert.equal(packagedJson.main, "./dist/cjs/index.js"); | ||
| assert.equal(packagedJson.types, "./dist/index.d.ts"); | ||
|
|
||
| assert.equal(packagedJson.exports["."].import.types, "./dist/index.d.ts"); | ||
| assert.equal(packagedJson.exports["."].import.default, "./dist/index.js"); | ||
| assert.equal( | ||
| packagedJson.exports["."].require.types, | ||
| "./dist/cjs/index.d.ts", | ||
| ); | ||
| assert.equal( | ||
| packagedJson.exports["."].require.default, | ||
| "./dist/cjs/index.js", | ||
| ); | ||
| }); | ||
|
|
||
| it("does not include test artifacts", () => { | ||
| const entries = listTarEntries(repoRoot, tarballPath); | ||
| const testArtifacts = entries.filter(entry => | ||
| /(^|\/)tests?\//.test(entry.replace(/^package\//, "")), | ||
| ); | ||
| assert.deepEqual(testArtifacts, []); | ||
| }); | ||
| }); |
This file contains hidden or 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,84 @@ | ||
| import { afterAll, beforeAll, describe, it } from "vitest"; | ||
| import { buildPackedTarball, prepareFixtureDir, removeDir } from "./runner"; | ||
| import { runTsLane } from "./runner/ts-lane"; | ||
|
|
||
| const repoRoot = process.cwd(); | ||
| const tempDirs: string[] = []; | ||
| let tarballPath = ""; | ||
| const TS5_VERSION = "5.9.3"; | ||
| const TS_TIMEOUT_MS = 240_000; | ||
|
|
||
| afterAll(async () => { | ||
| await Promise.allSettled(tempDirs.map(dir => removeDir(dir))); | ||
| }); | ||
|
|
||
| describe("dual package TS5 consumer contract", () => { | ||
| beforeAll(async () => { | ||
| const packOutDir = await prepareFixtureDir(tempDirs, "ts5-pack"); | ||
| tarballPath = await buildPackedTarball(repoRoot, packOutDir); | ||
| }); | ||
|
|
||
| it( | ||
| `runs TS ESM modern lane (${TS5_VERSION})`, | ||
| async () => { | ||
| await runTsLane( | ||
| { repoRoot, tarballPath, tsVersion: TS5_VERSION, tempDirs }, | ||
| { | ||
| fixtureName: "ts5-esm-modern", | ||
| packageTemplateFile: "package.module.json", | ||
| tsconfigTemplateFile: "tsconfig.nodenext.json", | ||
| withRuntime: true, | ||
| }, | ||
| ); | ||
| }, | ||
| TS_TIMEOUT_MS, | ||
| ); | ||
|
|
||
| it( | ||
| `runs TS CJS modern lane (${TS5_VERSION})`, | ||
| async () => { | ||
| await runTsLane( | ||
| { repoRoot, tarballPath, tsVersion: TS5_VERSION, tempDirs }, | ||
| { | ||
| fixtureName: "ts5-cjs-modern", | ||
| packageTemplateFile: "package.commonjs.json", | ||
| tsconfigTemplateFile: "tsconfig.nodenext.json", | ||
| withRuntime: true, | ||
| }, | ||
| ); | ||
| }, | ||
| TS_TIMEOUT_MS, | ||
| ); | ||
|
|
||
| it( | ||
| `runs TS CJS legacy lane (${TS5_VERSION})`, | ||
| async () => { | ||
| await runTsLane( | ||
| { repoRoot, tarballPath, tsVersion: TS5_VERSION, tempDirs }, | ||
| { | ||
| fixtureName: "ts5-cjs-legacy", | ||
| packageTemplateFile: "package.commonjs.json", | ||
| tsconfigTemplateFile: "tsconfig.legacy-commonjs.json", | ||
| withRuntime: true, | ||
| }, | ||
| ); | ||
| }, | ||
| TS_TIMEOUT_MS, | ||
| ); | ||
|
|
||
| it( | ||
| `runs TS bundler compile-only lane (${TS5_VERSION})`, | ||
| async () => { | ||
| await runTsLane( | ||
| { repoRoot, tarballPath, tsVersion: TS5_VERSION, tempDirs }, | ||
| { | ||
| fixtureName: "ts5-bundler", | ||
| packageTemplateFile: "package.module.json", | ||
| tsconfigTemplateFile: "tsconfig.bundler.json", | ||
| withRuntime: false, | ||
| }, | ||
| ); | ||
| }, | ||
| TS_TIMEOUT_MS, | ||
| ); | ||
| }); | ||
This file contains hidden or 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,84 @@ | ||
| import { afterAll, beforeAll, describe, it } from "vitest"; | ||
| import { buildPackedTarball, prepareFixtureDir, removeDir } from "./runner"; | ||
| import { runTsLane } from "./runner/ts-lane"; | ||
|
|
||
| const repoRoot = process.cwd(); | ||
| const tempDirs: string[] = []; | ||
| let tarballPath = ""; | ||
| const TS6_VERSION = "6.0.3"; | ||
| const TS_TIMEOUT_MS = 240_000; | ||
|
|
||
| afterAll(async () => { | ||
| await Promise.allSettled(tempDirs.map(dir => removeDir(dir))); | ||
| }); | ||
|
|
||
| describe("dual package TS6 consumer contract", () => { | ||
| beforeAll(async () => { | ||
| const packOutDir = await prepareFixtureDir(tempDirs, "ts6-pack"); | ||
| tarballPath = await buildPackedTarball(repoRoot, packOutDir); | ||
| }); | ||
|
|
||
| it( | ||
| `runs TS ESM modern lane (${TS6_VERSION})`, | ||
| async () => { | ||
| await runTsLane( | ||
| { repoRoot, tarballPath, tsVersion: TS6_VERSION, tempDirs }, | ||
| { | ||
| fixtureName: "ts6-esm-modern", | ||
| packageTemplateFile: "package.module.json", | ||
| tsconfigTemplateFile: "tsconfig.nodenext.json", | ||
| withRuntime: true, | ||
| }, | ||
| ); | ||
| }, | ||
| TS_TIMEOUT_MS, | ||
| ); | ||
|
|
||
| it( | ||
| `runs TS CJS modern lane (${TS6_VERSION})`, | ||
| async () => { | ||
| await runTsLane( | ||
| { repoRoot, tarballPath, tsVersion: TS6_VERSION, tempDirs }, | ||
| { | ||
| fixtureName: "ts6-cjs-modern", | ||
| packageTemplateFile: "package.commonjs.json", | ||
| tsconfigTemplateFile: "tsconfig.nodenext.json", | ||
| withRuntime: true, | ||
| }, | ||
| ); | ||
| }, | ||
| TS_TIMEOUT_MS, | ||
| ); | ||
|
|
||
| it( | ||
| `runs TS bundler compile-only lane (${TS6_VERSION})`, | ||
| async () => { | ||
| await runTsLane( | ||
| { repoRoot, tarballPath, tsVersion: TS6_VERSION, tempDirs }, | ||
| { | ||
| fixtureName: "ts6-bundler", | ||
| packageTemplateFile: "package.module.json", | ||
| tsconfigTemplateFile: "tsconfig.bundler.json", | ||
| withRuntime: false, | ||
| }, | ||
| ); | ||
| }, | ||
| TS_TIMEOUT_MS, | ||
| ); | ||
|
|
||
| it( | ||
| `runs TS CJS node16 lane (${TS6_VERSION})`, | ||
| async () => { | ||
| await runTsLane( | ||
| { repoRoot, tarballPath, tsVersion: TS6_VERSION, tempDirs }, | ||
| { | ||
| fixtureName: "ts6-cjs-node16", | ||
| packageTemplateFile: "package.commonjs.json", | ||
| tsconfigTemplateFile: "tsconfig.node16.json", | ||
| withRuntime: true, | ||
| }, | ||
| ); | ||
| }, | ||
| TS_TIMEOUT_MS, | ||
| ); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to use a semver range like
~5.9here (and^6.0in 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.tsagainst future TS releases earlier. Themin-release-age=7in.npmrcalready mitigates zero-day supply-chain risk.If CI determinism is the priority, pinning is also reasonable — just sharing a thought.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specific version is better to make build stable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned in my comment, if maintaining the stability of the CI is a priority, I think it’s fine to leave it as is.