mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Speed up some more tests (#25892)
### What does this PR do? ### How did you verify your code works?
This commit is contained in:
@@ -1,178 +1,193 @@
|
|||||||
import { spawn, spawnSync } from "bun";
|
import { spawn } from "bun";
|
||||||
import { upgrade_test_helpers } from "bun:internal-for-testing";
|
import { upgrade_test_helpers } from "bun:internal-for-testing";
|
||||||
import { beforeAll, beforeEach, expect, it, setDefaultTimeout } from "bun:test";
|
import { beforeAll, describe, expect, it, setDefaultTimeout } from "bun:test";
|
||||||
import { bunExe, bunEnv as env, tls, tmpdirSync } from "harness";
|
import { bunExe, bunEnv as env, tls, tmpdirSync } from "harness";
|
||||||
import { copyFileSync } from "node:fs";
|
import { copyFile } from "node:fs/promises";
|
||||||
import { basename, join } from "path";
|
import { basename, join } from "path";
|
||||||
const { openTempDirWithoutSharingDelete, closeTempDirHandle } = upgrade_test_helpers;
|
const { openTempDirWithoutSharingDelete, closeTempDirHandle } = upgrade_test_helpers;
|
||||||
|
|
||||||
let cwd: string;
|
|
||||||
let execPath: string;
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
setDefaultTimeout(1000 * 60 * 5);
|
setDefaultTimeout(1000 * 60 * 5);
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async () => {
|
describe.concurrent(() => {
|
||||||
cwd = tmpdirSync();
|
it("two invalid arguments, should display error message and suggest command", async () => {
|
||||||
execPath = join(cwd, basename(bunExe()));
|
const cwd = tmpdirSync();
|
||||||
copyFileSync(bunExe(), execPath);
|
const execPath = join(cwd, basename(bunExe()));
|
||||||
});
|
await copyFile(bunExe(), execPath);
|
||||||
|
const { stderr } = spawn({
|
||||||
|
cmd: [execPath, "upgrade", "bun-types", "--dev"],
|
||||||
|
cwd,
|
||||||
|
stdout: null,
|
||||||
|
stdin: "pipe",
|
||||||
|
stderr: "pipe",
|
||||||
|
env,
|
||||||
|
});
|
||||||
|
|
||||||
it("two invalid arguments, should display error message and suggest command", async () => {
|
const err = await stderr.text();
|
||||||
const { stderr } = spawn({
|
expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names.");
|
||||||
cmd: [execPath, "upgrade", "bun-types", "--dev"],
|
expect(err.split(/\r?\n/)).toContain("note: Use `bun update bun-types --dev` instead.");
|
||||||
cwd,
|
|
||||||
stdout: null,
|
|
||||||
stdin: "pipe",
|
|
||||||
stderr: "pipe",
|
|
||||||
env,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const err = await stderr.text();
|
it("two invalid arguments flipped, should display error message and suggest command", async () => {
|
||||||
expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names.");
|
const cwd = tmpdirSync();
|
||||||
expect(err.split(/\r?\n/)).toContain("note: Use `bun update bun-types --dev` instead.");
|
const execPath = join(cwd, basename(bunExe()));
|
||||||
});
|
await copyFile(bunExe(), execPath);
|
||||||
|
const { stderr } = spawn({
|
||||||
|
cmd: [execPath, "upgrade", "--dev", "bun-types"],
|
||||||
|
cwd,
|
||||||
|
stdout: null,
|
||||||
|
stdin: "pipe",
|
||||||
|
stderr: "pipe",
|
||||||
|
env,
|
||||||
|
});
|
||||||
|
|
||||||
it("two invalid arguments flipped, should display error message and suggest command", async () => {
|
const err = await stderr.text();
|
||||||
const { stderr } = spawn({
|
expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names.");
|
||||||
cmd: [execPath, "upgrade", "--dev", "bun-types"],
|
expect(err.split(/\r?\n/)).toContain("note: Use `bun update --dev bun-types` instead.");
|
||||||
cwd,
|
|
||||||
stdout: null,
|
|
||||||
stdin: "pipe",
|
|
||||||
stderr: "pipe",
|
|
||||||
env,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const err = await stderr.text();
|
it("one invalid argument, should display error message and suggest command", async () => {
|
||||||
expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names.");
|
const cwd = tmpdirSync();
|
||||||
expect(err.split(/\r?\n/)).toContain("note: Use `bun update --dev bun-types` instead.");
|
const execPath = join(cwd, basename(bunExe()));
|
||||||
});
|
await copyFile(bunExe(), execPath);
|
||||||
|
const { stderr } = spawn({
|
||||||
|
cmd: [execPath, "upgrade", "bun-types"],
|
||||||
|
cwd,
|
||||||
|
stdout: null,
|
||||||
|
stdin: "pipe",
|
||||||
|
stderr: "pipe",
|
||||||
|
env,
|
||||||
|
});
|
||||||
|
|
||||||
it("one invalid argument, should display error message and suggest command", async () => {
|
const err = await stderr.text();
|
||||||
const { stderr } = spawn({
|
expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names.");
|
||||||
cmd: [execPath, "upgrade", "bun-types"],
|
expect(err.split(/\r?\n/)).toContain("note: Use `bun update bun-types` instead.");
|
||||||
cwd,
|
|
||||||
stdout: null,
|
|
||||||
stdin: "pipe",
|
|
||||||
stderr: "pipe",
|
|
||||||
env,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const err = await stderr.text();
|
it("one valid argument, should succeed", async () => {
|
||||||
expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names.");
|
const cwd = tmpdirSync();
|
||||||
expect(err.split(/\r?\n/)).toContain("note: Use `bun update bun-types` instead.");
|
const execPath = join(cwd, basename(bunExe()));
|
||||||
});
|
await copyFile(bunExe(), execPath);
|
||||||
|
const { stderr } = spawn({
|
||||||
|
cmd: [execPath, "upgrade", "--help"],
|
||||||
|
cwd,
|
||||||
|
stdout: null,
|
||||||
|
stdin: "pipe",
|
||||||
|
stderr: "pipe",
|
||||||
|
env,
|
||||||
|
});
|
||||||
|
|
||||||
it("one valid argument, should succeed", async () => {
|
const err = await stderr.text();
|
||||||
const { stderr } = spawn({
|
// Should not contain error message
|
||||||
cmd: [execPath, "upgrade", "--help"],
|
expect(err.split(/\r?\n/)).not.toContain(
|
||||||
cwd,
|
"error: This command updates bun itself, and does not take package names.",
|
||||||
stdout: null,
|
);
|
||||||
stdin: "pipe",
|
expect(err.split(/\r?\n/)).not.toContain("note: Use `bun update --help` instead.");
|
||||||
stderr: "pipe",
|
|
||||||
env,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const err = await stderr.text();
|
it("two valid argument, should succeed", async () => {
|
||||||
// Should not contain error message
|
const cwd = tmpdirSync();
|
||||||
expect(err.split(/\r?\n/)).not.toContain("error: This command updates bun itself, and does not take package names.");
|
const execPath = join(cwd, basename(bunExe()));
|
||||||
expect(err.split(/\r?\n/)).not.toContain("note: Use `bun update --help` instead.");
|
await copyFile(bunExe(), execPath);
|
||||||
});
|
const { stderr } = spawn({
|
||||||
|
cmd: [execPath, "upgrade", "--stable", "--profile"],
|
||||||
|
cwd,
|
||||||
|
stdout: null,
|
||||||
|
stdin: "pipe",
|
||||||
|
stderr: "pipe",
|
||||||
|
env,
|
||||||
|
});
|
||||||
|
|
||||||
it("two valid argument, should succeed", async () => {
|
const err = await stderr.text();
|
||||||
const { stderr } = spawn({
|
// Should not contain error message
|
||||||
cmd: [execPath, "upgrade", "--stable", "--profile"],
|
expect(err.split(/\r?\n/)).not.toContain(
|
||||||
cwd,
|
"error: This command updates Bun itself, and does not take package names.",
|
||||||
stdout: null,
|
);
|
||||||
stdin: "pipe",
|
expect(err.split(/\r?\n/)).not.toContain("note: Use `bun update --stable --profile` instead.");
|
||||||
stderr: "pipe",
|
|
||||||
env,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const err = await stderr.text();
|
it("zero arguments, should succeed", async () => {
|
||||||
// Should not contain error message
|
const tagName = bunExe().includes("-debug") ? "canary" : `bun-v${Bun.version}`;
|
||||||
expect(err.split(/\r?\n/)).not.toContain("error: This command updates Bun itself, and does not take package names.");
|
using server = Bun.serve({
|
||||||
expect(err.split(/\r?\n/)).not.toContain("note: Use `bun update --stable --profile` instead.");
|
tls: tls,
|
||||||
});
|
port: 0,
|
||||||
|
async fetch() {
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
"tag_name": tagName,
|
||||||
|
"assets": [
|
||||||
|
{
|
||||||
|
"url": "foo",
|
||||||
|
"content_type": "application/zip",
|
||||||
|
"name": "bun-windows-x64.zip",
|
||||||
|
"browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-windows-x64.zip`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "foo",
|
||||||
|
"content_type": "application/zip",
|
||||||
|
"name": "bun-windows-x64-baseline.zip",
|
||||||
|
"browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-windows-x64-baseline.zip`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "foo",
|
||||||
|
"content_type": "application/zip",
|
||||||
|
"name": "bun-linux-x64.zip",
|
||||||
|
"browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-linux-x64.zip`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "foo",
|
||||||
|
"content_type": "application/zip",
|
||||||
|
"name": "bun-linux-x64-baseline.zip",
|
||||||
|
"browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-linux-x64-baseline.zip`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "foo",
|
||||||
|
"content_type": "application/zip",
|
||||||
|
"name": "bun-darwin-x64.zip",
|
||||||
|
"browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-darwin-x64.zip`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "foo",
|
||||||
|
"content_type": "application/zip",
|
||||||
|
"name": "bun-darwin-x64-baseline.zip",
|
||||||
|
"browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-darwin-x64-baseline.zip`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "foo",
|
||||||
|
"content_type": "application/zip",
|
||||||
|
"name": "bun-darwin-aarch64.zip",
|
||||||
|
"browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-darwin-aarch64.zip`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
it("zero arguments, should succeed", async () => {
|
// On windows, open the temporary directory without FILE_SHARE_DELETE before spawning
|
||||||
const tagName = bunExe().includes("-debug") ? "canary" : `bun-v${Bun.version}`;
|
// the upgrade process. This is to test for EBUSY errors
|
||||||
using server = Bun.serve({
|
openTempDirWithoutSharingDelete();
|
||||||
tls: tls,
|
const cwd = tmpdirSync();
|
||||||
port: 0,
|
const execPath = join(cwd, basename(bunExe()));
|
||||||
async fetch() {
|
await copyFile(bunExe(), execPath);
|
||||||
return new Response(
|
|
||||||
JSON.stringify({
|
const { stderr } = Bun.spawn({
|
||||||
"tag_name": tagName,
|
cmd: [execPath, "upgrade"],
|
||||||
"assets": [
|
cwd,
|
||||||
{
|
stdout: null,
|
||||||
"url": "foo",
|
stdin: "pipe",
|
||||||
"content_type": "application/zip",
|
stderr: "pipe",
|
||||||
"name": "bun-windows-x64.zip",
|
env: {
|
||||||
"browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-windows-x64.zip`,
|
...env,
|
||||||
},
|
NODE_TLS_REJECT_UNAUTHORIZED: "0",
|
||||||
{
|
GITHUB_API_DOMAIN: `${server.hostname}:${server.port}`,
|
||||||
"url": "foo",
|
},
|
||||||
"content_type": "application/zip",
|
});
|
||||||
"name": "bun-windows-x64-baseline.zip",
|
|
||||||
"browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-windows-x64-baseline.zip`,
|
closeTempDirHandle();
|
||||||
},
|
|
||||||
{
|
// Should not contain error message
|
||||||
"url": "foo",
|
expect(await stderr.text()).not.toContain("error:");
|
||||||
"content_type": "application/zip",
|
|
||||||
"name": "bun-linux-x64.zip",
|
|
||||||
"browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-linux-x64.zip`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "foo",
|
|
||||||
"content_type": "application/zip",
|
|
||||||
"name": "bun-linux-x64-baseline.zip",
|
|
||||||
"browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-linux-x64-baseline.zip`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "foo",
|
|
||||||
"content_type": "application/zip",
|
|
||||||
"name": "bun-darwin-x64.zip",
|
|
||||||
"browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-darwin-x64.zip`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "foo",
|
|
||||||
"content_type": "application/zip",
|
|
||||||
"name": "bun-darwin-x64-baseline.zip",
|
|
||||||
"browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-darwin-x64-baseline.zip`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "foo",
|
|
||||||
"content_type": "application/zip",
|
|
||||||
"name": "bun-darwin-aarch64.zip",
|
|
||||||
"browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-darwin-aarch64.zip`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// On windows, open the temporary directory without FILE_SHARE_DELETE before spawning
|
|
||||||
// the upgrade process. This is to test for EBUSY errors
|
|
||||||
openTempDirWithoutSharingDelete();
|
|
||||||
|
|
||||||
const { stderr } = spawnSync({
|
|
||||||
cmd: [execPath, "upgrade"],
|
|
||||||
cwd,
|
|
||||||
stdout: null,
|
|
||||||
stdin: "pipe",
|
|
||||||
stderr: "pipe",
|
|
||||||
env: {
|
|
||||||
...env,
|
|
||||||
NODE_TLS_REJECT_UNAUTHORIZED: "0",
|
|
||||||
GITHUB_API_DOMAIN: `${server.hostname}:${server.port}`,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
closeTempDirHandle();
|
|
||||||
|
|
||||||
// Should not contain error message
|
|
||||||
expect(stderr.toString()).not.toContain("error:");
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -811,6 +811,16 @@ export async function toBeWorkspaceLink(actual: string, expectedLinkPath: string
|
|||||||
return { pass, message };
|
return { pass, message };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getFDCount(): number {
|
||||||
|
if (isMacOS || isLinux) {
|
||||||
|
return fs.readdirSync(isMacOS ? "/dev/fd" : "/proc/self/fd").length;
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxFD = openSync("/dev/null", "r");
|
||||||
|
closeSync(maxFD);
|
||||||
|
return maxFD;
|
||||||
|
}
|
||||||
|
|
||||||
export function getMaxFD(): number {
|
export function getMaxFD(): number {
|
||||||
if (isMacOS || isLinux) {
|
if (isMacOS || isLinux) {
|
||||||
let max = -1;
|
let max = -1;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { describe, test } from "bun:test";
|
|||||||
import { bunEnv, bunExe, isASAN, isBroken, isLinux, nodeExe } from "harness";
|
import { bunEnv, bunExe, isASAN, isBroken, isLinux, nodeExe } from "harness";
|
||||||
import { basename, join } from "path";
|
import { basename, join } from "path";
|
||||||
|
|
||||||
describe("AsyncLocalStorage passes context to callbacks", () => {
|
describe.concurrent("AsyncLocalStorage passes context to callbacks", () => {
|
||||||
let files = [...new Glob(join(import.meta.dir, "async-context", "async-context-*.js")).scanSync()];
|
let files = [...new Glob(join(import.meta.dir, "async-context", "async-context-*.js")).scanSync()];
|
||||||
|
|
||||||
let todos = ["async-context-worker_threads-message.js"];
|
let todos = ["async-context-worker_threads-message.js"];
|
||||||
|
|||||||
Reference in New Issue
Block a user