-
Notifications
You must be signed in to change notification settings - Fork 5k
Enable run-detect-module-type test and fix its import.cjs fixtures #37182
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
Open
robobun
wants to merge
6
commits into
main
Choose a base branch
from
farm/ff6be295/fix-detect-module-type-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9545f15
test: enable run-detect-module-type and fix its import.cjs fixtures
robobun 0bb1e9a
test: assert fixture stdout is exactly true or false
robobun 3612059
test: reject unexpected stderr from fixtures
robobun 86a9669
test: enable run-importmetamain, pin CommonJS-marker detection rows
robobun d3e5b9e
test: use tempDir and assert exit status in run-importmetamain
robobun 952b677
ci: retrigger
robobun 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| import * as fs from "node:fs"; | ||
| console.log(eval("typeof module === 'undefined'")); | ||
| +fs; | ||
| fs.constants; |
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 |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| import * as fs from "node:fs"; | ||
| console.log(eval("typeof module === 'undefined'")); | ||
| +fs; | ||
| fs.constants; |
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,61 @@ | ||
| import { expect, test } from "bun:test"; | ||
| import { bunEnv, bunExe } from "harness"; | ||
| import { join } from "path"; | ||
|
|
||
| // package.json "type" -> file name -> expected module type of the main entry | ||
| const table = { | ||
| cjs: { | ||
| "hello.cjs": "commonjs", | ||
| "hello.js": "commonjs", | ||
| "hello.mjs": "module", | ||
| "hello.ts": "commonjs", | ||
| "hello.tsx": "module", | ||
| "hello.cts": "commonjs", | ||
| "hello.jsx": "module", | ||
| "hello.mts": "module", | ||
| // files using ES import and no exports will be detected as module | ||
| "import.cjs": "module", | ||
| }, | ||
| esm: { | ||
| "hello.cjs": "commonjs", | ||
| "hello.js": "module", | ||
| "hello.mjs": "module", | ||
| "hello.ts": "module", | ||
| "hello.tsx": "module", | ||
| "hello.cts": "commonjs", | ||
| "hello.jsx": "module", | ||
| "hello.mts": "module", | ||
| // files using ES import and no exports will be detected as module | ||
| "import.cjs": "module", | ||
| }, | ||
| } as const; | ||
|
|
||
| const cases = Object.entries(table).flatMap(([packageType, files]) => | ||
| Object.entries(files).map(([file, expectedType]) => ({ packageType, file, expectedType })), | ||
| ); | ||
|
|
||
| test("detect module type", async () => { | ||
| // each fixture prints `typeof module === 'undefined'`: "false" means it ran as commonjs | ||
| const actual = await Promise.all( | ||
| cases.map(async ({ packageType, file }) => { | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "run", join(import.meta.dir, "module-type-fixture", packageType, file)], | ||
| env: bunEnv, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| if (exitCode !== 0) { | ||
| throw new Error(`Failed to run ${packageType}/${file}: ${stderr.trim()}`); | ||
| } | ||
| const out = stdout.trim(); | ||
| const detected = | ||
| out === "true" ? "module" : out === "false" ? "commonjs" : `unexpected output ${JSON.stringify(out)}`; | ||
| return `${packageType} ${file} -> ${detected}`; | ||
| }), | ||
| ); | ||
|
|
||
| expect(actual).toEqual( | ||
| cases.map(({ packageType, file, expectedType }) => `${packageType} ${file} -> ${expectedType}`), | ||
| ); | ||
| }); | ||
This file was deleted.
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.
Uh oh!
There was an error while loading. Please reload this page.