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
Add a few tests for --compile --target #10523
Open
Jarred-Sumner
wants to merge
4
commits into
main
Choose a base branch
from
jarred/compile-target-test
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
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
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,131 @@ | ||
import { bunEnv } from "harness"; | ||
import { itBundled, testForFile } from "./expectBundled"; | ||
var { describe, test, expect } = testForFile(import.meta.path); | ||
import { CompileTarget } from "bun:internal-for-testing"; | ||
|
||
describe("bundler", async () => { | ||
itBundled("compile_cross/DetectDefaultTarget", { | ||
compile: true, | ||
target: CompileTarget.getDefaultTarget(), | ||
env: { | ||
...bunEnv, | ||
BUN_COMPILE_TARGET_TARBALL_URL: | ||
"https://localhost:999999/deliberately-invalid-url-to-check-that-it-detects-default-target-correctly", | ||
}, | ||
files: { | ||
"/entry.ts": /* js */ ` | ||
console.log("Hello, world!"); | ||
`, | ||
}, | ||
run: { stdout: "Hello, world!" }, | ||
}); | ||
itBundled("compile_cross/DetectDefaultTarget2", { | ||
compile: true, | ||
target: "bun", | ||
env: { | ||
...bunEnv, | ||
BUN_COMPILE_TARGET_TARBALL_URL: | ||
"https://localhost:999999/deliberately-invalid-url-to-check-that-it-detects-default-target-correctly", | ||
}, | ||
files: { | ||
"/entry.ts": /* js */ ` | ||
console.log("Hello, world!"); | ||
`, | ||
}, | ||
run: { stdout: "Hello, world!" }, | ||
}); | ||
itBundled("compile_cross/FailOnInvalidTarget", { | ||
compile: true, | ||
target: `bun-poop`, | ||
env: { | ||
...bunEnv, | ||
BUN_COMPILE_TARGET_TARBALL_URL: | ||
"https://localhost:999999/deliberately-invalid-url-to-check-that-it-detects-default-target-correctly", | ||
}, | ||
files: { | ||
"/entry.ts": /* js */ ` | ||
console.log("Hello, world!"); | ||
`, | ||
}, | ||
bundleErrors: { | ||
"<bun>": [`Unsupported target "poop" in "bun-poop"`], | ||
}, | ||
}); | ||
itBundled("compile_cross/FailOnWildcardVersion", { | ||
compile: true, | ||
target: `bun-v1.*`, | ||
env: { | ||
...bunEnv, | ||
BUN_COMPILE_TARGET_TARBALL_URL: | ||
"https://localhost:999999/deliberately-invalid-url-to-check-that-it-detects-default-target-correctly", | ||
}, | ||
files: { | ||
"/entry.ts": /* js */ ` | ||
console.log("Hello, world!"); | ||
`, | ||
}, | ||
bundleErrors: { | ||
"<bun>": [ | ||
`Please pass a complete version number to --target. For example, --target=bun-v` + | ||
Bun.version.replace("-debug", ""), | ||
], | ||
}, | ||
}); | ||
itBundled("compile_cross/FailsOnInvalidURL", { | ||
compile: true, | ||
target: `bun-linux-arm64-v1.0.9999`, | ||
env: { | ||
...bunEnv, | ||
BUN_COMPILE_TARGET_TARBALL_URL: "https://localhost:999999/deliberately-invalid-url", | ||
}, | ||
files: { | ||
"/entry.ts": /* js */ ` | ||
console.log("Hello, world!"); | ||
`, | ||
}, | ||
bundleErrors: { | ||
"<bun>": [`failed to download cross-compiled bun executable`], | ||
}, | ||
}); | ||
|
||
// we allow using a local file if it has the exact name we expect | ||
// this is undocumented behavior, but it will make it easier to write tests in the future | ||
itBundled("compile_cross/UsesFileFromSameLocation", { | ||
compile: true, | ||
target: `bun-linux-arm64-v1.999.9999`, | ||
env: { | ||
...bunEnv, | ||
BUN_COMPILE_TARGET_TARBALL_URL: "https://localhost:999999/deliberately-invalid-url", | ||
}, | ||
files: { | ||
"/entry.ts": /* js */ ` | ||
console.log("Hello, world!"); | ||
`, | ||
// expects "bun" to be trimmed | ||
[CompileTarget.from("-linux-arm64-v1.999.9999")]: ``, | ||
}, | ||
}); | ||
|
||
// expects "bun" to be trimmed | ||
const sameLocationTarget = CompileTarget.from(`-${process.platform}-${process.arch}-v1.0.9999`); | ||
|
||
// Test that it can load a file that didn't actually come from bun.selfExePath() | ||
itBundled("compile_cross/RunsFileFromSameLocation", { | ||
compile: true, | ||
target: sameLocationTarget, | ||
env: { | ||
...bunEnv, | ||
BUN_COMPILE_TARGET_TARBALL_URL: "https://localhost:999999/deliberately-invalid-url", | ||
}, | ||
files: { | ||
"/entry.ts": /* js */ ` | ||
console.log("Hello, world!"); | ||
`, | ||
|
||
["/" + sameLocationTarget]: Buffer.from(await Bun.file(process.execPath).arrayBuffer()), | ||
}, | ||
run: { | ||
stdout: "Hello, world!", | ||
}, | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -46,13 +46,29 @@ function dedent(str: string | TemplateStringsArray, ...args: any[]) { | |
let currentFile: string | undefined; | ||
|
||
function errorOrWarnParser(isError = true) { | ||
const prefix = isError ? "error: " : "warn: "; | ||
return function (text: string) { | ||
let defaultPrefix = isError ? "error: " : "warn: "; | ||
return function parser(text: string) { | ||
let prefix = defaultPrefix; | ||
var i = 0; | ||
var list = []; | ||
while (i < text.length) { | ||
let errorLineI = text.indexOf(prefix, i); | ||
if (errorLineI === -1) { | ||
// Sometimes, our errors start with the error name itself | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah i understand alot more now. thanks for the comment |
||
// e.g. "ConnectionRefused: connect ECONNREFUSED 127.0.0.1:8080" | ||
// In those cases, it IS an error, but it doesn't start with "error: ", | ||
if (list.length === 0 && prefix === defaultPrefix && !text.includes(prefix)) { | ||
const firstPrefix = text.indexOf(": ", 0); | ||
if (firstPrefix !== -1) { | ||
const possiblePrefix = text.slice(0, firstPrefix).trim(); | ||
if (/^([a-zA-Z0-9_]+)$/.test(possiblePrefix)) { | ||
prefix = possiblePrefix.trim() + ": "; | ||
i = 0; | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
return list; | ||
} | ||
const message = text.slice(errorLineI + prefix.length, text.indexOf("\n", errorLineI + 1)); | ||
|
@@ -175,7 +191,7 @@ export interface BundlerTestInput { | |
/** Defaults to `/out` */ | ||
outdir?: string; | ||
/** Defaults to "browser". "bun" is set to "node" when using esbuild. */ | ||
target?: "bun" | "node" | "browser"; | ||
target?: "bun" | "node" | "browser" | `bun-${string}`; | ||
publicPath?: string; | ||
keepNames?: boolean; | ||
legalComments?: "none" | "inline" | "eof" | "linked" | "external"; | ||
|
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.
lol doesnt this function exit the program on failure.
would be cool if we could test the parser. its fine of course.