Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions test/cli/install/bun-link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ it("should link and unlink workspace package", async () => {
);
let { out, err } = await runBunInstall(env, link_dir);
expect(err.split(/\r?\n/).slice(-2)).toEqual(["Saved lockfile", ""]);
expect(out.replace(/\s*\[[0-9\.]+ms\]\s*$/, "").split(/\r?\n/)).toEqual([
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun install v1."),
"",
"Done! Checked 3 packages (no changes)",
Expand Down Expand Up @@ -90,7 +90,7 @@ it("should link and unlink workspace package", async () => {

err = await stderr.text();
expect(err.split(/\r?\n/)).toEqual([""]);
expect((await stdout.text()).replace(/\s*\[[0-9\.]+ms\]\s*$/, "").split(/\r?\n/)).toEqual([
expect((await stdout.text()).replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun link v1."),
"",
`installed moo@link:moo`,
Expand Down Expand Up @@ -143,7 +143,7 @@ it("should link and unlink workspace package", async () => {

err = await stderr.text();
expect(err.split(/\r?\n/)).toEqual([""]);
expect((await stdout.text()).replace(/\s*\[[0-9\.]+ms\]\s*$/, "").split(/\r?\n/)).toEqual([
expect((await stdout.text()).replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun link v1."),
"",
`installed foo@link:foo`,
Expand Down Expand Up @@ -221,7 +221,7 @@ it("should link package", async () => {
const err2 = await new Response(stderr2).text();
expect(err2.split(/\r?\n/)).toEqual([""]);
const out2 = await new Response(stdout2).text();
expect(out2.replace(/\s*\[[0-9\.]+ms\]\s*$/, "").split(/\r?\n/)).toEqual([
expect(out2.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun link v1."),
"",
`installed ${link_name}@link:${link_name}`,
Expand Down Expand Up @@ -314,7 +314,7 @@ it("should link scoped package", async () => {
const err2 = await new Response(stderr2).text();
expect(err2.split(/\r?\n/)).toEqual([""]);
const out2 = await new Response(stdout2).text();
expect(out2.replace(/\s*\[[0-9\.]+ms\]\s*$/, "").split(/\r?\n/)).toEqual([
expect(out2.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun link v1."),
"",
`installed ${link_name}@link:${link_name}`,
Expand Down Expand Up @@ -404,7 +404,7 @@ it("should link dependency without crashing", async () => {
const err2 = await new Response(stderr2).text();
expect(err2.split(/\r?\n/).slice(-2)).toEqual(["Saved lockfile", ""]);
const out2 = await new Response(stdout2).text();
expect(out2.replace(/\s*\[[0-9\.]+ms\]\s*$/, "").split(/\r?\n/)).toEqual([
expect(out2.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun install v1."),
"",
`+ ${link_name}@link:${link_name}`,
Expand Down
4 changes: 2 additions & 2 deletions test/cli/test/bun-test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ describe("bun test", () => {
stderr
.replace(/bun-test-(.*)\.test\.ts/, "bun-test-*.test.ts")
.trim()
.replace(/\[.*\ms\]/, "[xx ms]"),
.replace(/\[[\d.]+m?s\]/, "[xx ms]"),
).toMatchInlineSnapshot(`
"bun-test-*.test.ts:

Expand Down Expand Up @@ -1422,7 +1422,7 @@ describe("bun test", () => {
expect(
stderr
.replace(/bun-test-(.*)\.test\.ts/, "bun-test-*.test.ts")
.replace(/ \[[\d.]+ms\]/g, "") // Remove all timings
.replace(/ \[[\d.]+m?s\]/g, "") // Remove all timings
.replace(/Ran \d+ tests across \d+ files?\.\s*$/, "Ran 2 tests across 1 file.") // Normalize test counts
.trim(),
).toMatchInlineSnapshot(`
Expand Down
29 changes: 11 additions & 18 deletions test/js/bun/test/printing/diffexample.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@ import { expect, test } from "bun:test";
import { bunEnv, bunExe } from "harness";

function cleanOutput(output: string) {
return output
.replaceAll(/ \[[0-9\.]+ms\]/g, "")
.replaceAll(/at <anonymous> \(.*\)/g, "at <anonymous> (FILE:LINE)")
.replaceAll(
"test\\js\\bun\\test\\printing\\diffexample.fixture.ts:",
"test/js/bun/test/printing/diffexample.fixture.ts:",
);
return output.replaceAll(/ \[[0-9\.]+m?s\]/g, "").replaceAll(/at <anonymous> \(.*\)/g, "at <anonymous> (FILE:LINE)");
}
function cleanAnsiEscapes(output: string) {
return output.replaceAll(/\x1B\[[0-9;]*m/g, "");
}

test("no color", async () => {
const noColorSpawn = Bun.spawn({
// cwd is pinned so the child does not load the repo bunfig.toml, whose test preload imports harness.ts.
function runFixture() {
return Bun.spawn({
cmd: [bunExe(), "test", import.meta.dir + "/diffexample.fixture.ts"],
cwd: import.meta.dir,
stdio: ["inherit", "pipe", "pipe"],
env: {
...bunEnv,
FORCE_COLOR: "0",
},
});
}

test("no color", async () => {
await using noColorSpawn = runFixture();
await using colorSpawn = runFixture();
await noColorSpawn.exited;
const noColorStderr = cleanOutput(await noColorSpawn.stderr.text());
const noColorStdout = await noColorSpawn.stdout.text();
expect(noColorStderr).toMatchInlineSnapshot(`
"
test/js/bun/test/printing/diffexample.fixture.ts:
diffexample.fixture.ts:
10 | .replaceAll("\\\\", "/")
11 | .replaceAll(process.cwd(), "<cwd>");
12 | }
Expand Down Expand Up @@ -725,14 +726,6 @@ test("no color", async () => {
`);
expect(noColorSpawn.exitCode).toBe(1);

const colorSpawn = Bun.spawn({
cmd: [bunExe(), "test", import.meta.dir + "/diffexample.fixture.ts"],
stdio: ["inherit", "pipe", "pipe"],
env: {
...bunEnv,
FORCE_COLOR: "0",
},
});
await colorSpawn.exited;
const colorStderr = cleanOutput(cleanAnsiEscapes(await colorSpawn.stderr.text()));
const colorStdout = cleanAnsiEscapes(await colorSpawn.stdout.text());
Expand Down
2 changes: 1 addition & 1 deletion test/js/bun/test/test-failing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe("test.failing", () => {
fail("Expected exit code to be non-zero\n\n" + stderr);
}
expect(stderr).toContain(" 2 fail\n");
expect(stderr.replaceAll(/ \[[\d.]+ms\]/g, "")).toMatchInlineSnapshot(`
expect(stderr.replaceAll(/ \[[\d.]+m?s\]/g, "")).toMatchInlineSnapshot(`
"
failing-test-passes.fixture.ts:
(fail) This should fail but it doesnt
Expand Down
2 changes: 1 addition & 1 deletion test/js/bun/test/test-test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ it("should return non-zero exit code for invalid syntax", async () => {
env: bunEnv,
});
const err = (await stderr.text()).replaceAll("\\", "/");
expect(err.replaceAll(test_dir.replaceAll("\\", "/"), "<dir>").replaceAll(/\[(.*)\ms\]/g, "[xx ms]"))
expect(err.replaceAll(test_dir.replaceAll("\\", "/"), "<dir>").replaceAll(/\[[\d.]+m?s\]/g, "[xx ms]"))
.toMatchInlineSnapshot(`
"
bad.test.js:
Expand Down
8 changes: 4 additions & 4 deletions test/regression/issue/19850/19850.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("when beforeEach callback throws", () => {
// the important part is not printing some gibberish in place of the second "test 1"
err = err
.replaceAll(import.meta.dir, "")
.replaceAll(/ \[[\d\.]+ms\]/g, "")
.replaceAll(/ \[[\d\.]+m?s\]/g, "")
.replaceAll("\\", "/");
expect(err).toBe(`
err-in-hook-and-multiple-tests.ts:
Expand Down Expand Up @@ -56,11 +56,11 @@ Ran 2 tests across 1 file.
const elapsed = Date.now() - start;
expect(proc.exitCode).toBe(1);
let err = await new Response(proc.stderr).text();
const matches = [...err.matchAll(/\[([\d\.]+)ms\]/g)];
const matches = [...err.matchAll(/\[([\d\.]+)(m?s)\]/g)];
// 1 for test 0, 1 for the total
expect(matches.length).toBe(2);
for (const match of matches) {
const ms = parseFloat(match[1]);
for (const [, value, unit] of matches) {
const ms = unit === "s" ? parseFloat(value) * 1000 : parseFloat(value);
expect(ms).toBeGreaterThan(45); // should have slept for at least 50 ms
expect(ms).toBeLessThan(2 * elapsed); // should not report a time vastly higher than what it actually took
}
Expand Down
Loading