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,25 +1,20 @@
|
||||
import { spawn, spawnSync } from "bun";
|
||||
import { spawn } from "bun";
|
||||
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 { copyFileSync } from "node:fs";
|
||||
import { copyFile } from "node:fs/promises";
|
||||
import { basename, join } from "path";
|
||||
const { openTempDirWithoutSharingDelete, closeTempDirHandle } = upgrade_test_helpers;
|
||||
|
||||
let cwd: string;
|
||||
let execPath: string;
|
||||
|
||||
beforeAll(() => {
|
||||
setDefaultTimeout(1000 * 60 * 5);
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
cwd = tmpdirSync();
|
||||
execPath = join(cwd, basename(bunExe()));
|
||||
copyFileSync(bunExe(), execPath);
|
||||
});
|
||||
|
||||
describe.concurrent(() => {
|
||||
it("two invalid arguments, should display error message and suggest command", async () => {
|
||||
const cwd = tmpdirSync();
|
||||
const execPath = join(cwd, basename(bunExe()));
|
||||
await copyFile(bunExe(), execPath);
|
||||
const { stderr } = spawn({
|
||||
cmd: [execPath, "upgrade", "bun-types", "--dev"],
|
||||
cwd,
|
||||
@@ -35,6 +30,9 @@ it("two invalid arguments, should display error message and suggest command", as
|
||||
});
|
||||
|
||||
it("two invalid arguments flipped, should display error message and suggest command", async () => {
|
||||
const cwd = tmpdirSync();
|
||||
const execPath = join(cwd, basename(bunExe()));
|
||||
await copyFile(bunExe(), execPath);
|
||||
const { stderr } = spawn({
|
||||
cmd: [execPath, "upgrade", "--dev", "bun-types"],
|
||||
cwd,
|
||||
@@ -50,6 +48,9 @@ it("two invalid arguments flipped, should display error message and suggest comm
|
||||
});
|
||||
|
||||
it("one invalid argument, should display error message and suggest command", async () => {
|
||||
const cwd = tmpdirSync();
|
||||
const execPath = join(cwd, basename(bunExe()));
|
||||
await copyFile(bunExe(), execPath);
|
||||
const { stderr } = spawn({
|
||||
cmd: [execPath, "upgrade", "bun-types"],
|
||||
cwd,
|
||||
@@ -65,6 +66,9 @@ it("one invalid argument, should display error message and suggest command", asy
|
||||
});
|
||||
|
||||
it("one valid argument, should succeed", async () => {
|
||||
const cwd = tmpdirSync();
|
||||
const execPath = join(cwd, basename(bunExe()));
|
||||
await copyFile(bunExe(), execPath);
|
||||
const { stderr } = spawn({
|
||||
cmd: [execPath, "upgrade", "--help"],
|
||||
cwd,
|
||||
@@ -76,11 +80,16 @@ it("one valid argument, should succeed", async () => {
|
||||
|
||||
const err = await stderr.text();
|
||||
// Should not contain error message
|
||||
expect(err.split(/\r?\n/)).not.toContain("error: This command updates bun itself, and does not take package names.");
|
||||
expect(err.split(/\r?\n/)).not.toContain(
|
||||
"error: This command updates bun itself, and does not take package names.",
|
||||
);
|
||||
expect(err.split(/\r?\n/)).not.toContain("note: Use `bun update --help` instead.");
|
||||
});
|
||||
|
||||
it("two valid argument, should succeed", async () => {
|
||||
const cwd = tmpdirSync();
|
||||
const execPath = join(cwd, basename(bunExe()));
|
||||
await copyFile(bunExe(), execPath);
|
||||
const { stderr } = spawn({
|
||||
cmd: [execPath, "upgrade", "--stable", "--profile"],
|
||||
cwd,
|
||||
@@ -92,7 +101,9 @@ it("two valid argument, should succeed", async () => {
|
||||
|
||||
const err = await stderr.text();
|
||||
// Should not contain error message
|
||||
expect(err.split(/\r?\n/)).not.toContain("error: This command updates Bun itself, and does not take package names.");
|
||||
expect(err.split(/\r?\n/)).not.toContain(
|
||||
"error: This command updates Bun itself, and does not take package names.",
|
||||
);
|
||||
expect(err.split(/\r?\n/)).not.toContain("note: Use `bun update --stable --profile` instead.");
|
||||
});
|
||||
|
||||
@@ -157,8 +168,11 @@ it("zero arguments, should succeed", async () => {
|
||||
// On windows, open the temporary directory without FILE_SHARE_DELETE before spawning
|
||||
// the upgrade process. This is to test for EBUSY errors
|
||||
openTempDirWithoutSharingDelete();
|
||||
const cwd = tmpdirSync();
|
||||
const execPath = join(cwd, basename(bunExe()));
|
||||
await copyFile(bunExe(), execPath);
|
||||
|
||||
const { stderr } = spawnSync({
|
||||
const { stderr } = Bun.spawn({
|
||||
cmd: [execPath, "upgrade"],
|
||||
cwd,
|
||||
stdout: null,
|
||||
@@ -174,5 +188,6 @@ it("zero arguments, should succeed", async () => {
|
||||
closeTempDirHandle();
|
||||
|
||||
// Should not contain error message
|
||||
expect(stderr.toString()).not.toContain("error:");
|
||||
expect(await stderr.text()).not.toContain("error:");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -811,6 +811,16 @@ export async function toBeWorkspaceLink(actual: string, expectedLinkPath: string
|
||||
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 {
|
||||
if (isMacOS || isLinux) {
|
||||
let max = -1;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { describe, test } from "bun:test";
|
||||
import { bunEnv, bunExe, isASAN, isBroken, isLinux, nodeExe } from "harness";
|
||||
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 todos = ["async-context-worker_threads-message.js"];
|
||||
|
||||
Reference in New Issue
Block a user