node test: run bun:test tests with bun test

This commit is contained in:
chloe caruso
2025-01-18 16:43:36 -08:00
parent 5d3cbfecde
commit 0c2e1f324a
3 changed files with 12 additions and 8 deletions

View File

@@ -256,7 +256,8 @@ async function runTests() {
const absoluteTestPath = join(testsPath, testPath);
const title = relative(cwd, absoluteTestPath).replaceAll(sep, "/");
if (isNodeParallelTest(testPath)) {
const subcommand = title.includes("needs-test") ? "test" : "run";
const runWithBunTest = title.includes("needs-test") || readFileSync(absoluteTestPath, "utf-8").includes('bun:test');
const subcommand = runWithBunTest ? "test" : "run";
await runTest(title, async () => {
const { ok, error, stdout } = await spawnBun(execPath, {
cwd: cwd,

View File

@@ -5519,6 +5519,7 @@ pub const NodeFS = struct {
// We cannot use removefileat() on macOS because it does not handle write-protected files as expected.
if (args.recursive) {
zigDeleteTree(std.fs.cwd(), args.path.slice(), .file) catch |err| {
bun.handleErrorReturnTrace(err, @errorReturnTrace());
const errno: E = switch (@as(anyerror, err)) {
// error.InvalidHandle => .BADF,
error.AccessDenied => .ACCES,
@@ -5563,14 +5564,16 @@ pub const NodeFS = struct {
const dest = args.path.sliceZ(&this.sync_error_buf);
std.posix.unlinkZ(dest) catch |er| {
std.posix.unlinkZ(dest) catch |err1| {
bun.handleErrorReturnTrace(err1, @errorReturnTrace());
// empircally, it seems to return AccessDenied when the
// file is actually a directory on macOS.
if (args.recursive and
(er == error.IsDir or er == error.NotDir or er == error.AccessDenied))
(err1 == error.IsDir or err1 == error.NotDir or err1 == error.AccessDenied))
{
std.posix.rmdirZ(dest) catch |err| {
const code: E = switch (err) {
std.posix.rmdirZ(dest) catch |err2| {
bun.handleErrorReturnTrace(err2, @errorReturnTrace());
const code: E = switch (err2) {
error.AccessDenied => .ACCES,
error.SymLinkLoop => .LOOP,
error.NameTooLong => .NAMETOOLONG,
@@ -5598,7 +5601,7 @@ pub const NodeFS = struct {
}
{
const code: E = switch (er) {
const code: E = switch (err1) {
error.AccessDenied => .ACCES,
error.SymLinkLoop => .LOOP,
error.NameTooLong => .NAMETOOLONG,

View File

@@ -463,7 +463,7 @@ describe("ENOENT", () => {
await Bun.write(file, "contents", ...opts);
expect(fs.existsSync(file)).toBe(true);
} finally {
fs.rmSync(dir, { force: true });
fs.rmSync(dir, { recursive: true, force: true });
}
});
};
@@ -483,7 +483,7 @@ describe("ENOENT", () => {
);
expect(fs.existsSync(file)).toBe(false);
} finally {
fs.rmSync(dir, { force: true });
fs.rmSync(dir, { recursive: true, force: true });
}
});