From c538bf87d1d45451ac99bf8098d8476a7211c238 Mon Sep 17 00:00:00 2001 From: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Date: Mon, 29 Jan 2024 15:17:23 -0800 Subject: [PATCH] fix(windows): transpiler cache and other test fixes (#8471) * umask * process args * update reportError.test.ts * file exists * transpiler cache * back to const * remove failing comments * [autofix.ci] apply automated fixes * update comment * debug assert and remmove branch * oops * escape * path sep * seekTo * disable --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Jarred Sumner --- src/bun.js/RuntimeTranspilerCache.zig | 26 ++++++++++++++--------- src/bun.js/bindings/BunProcess.cpp | 9 ++++---- src/bun.js/webcore/blob.zig | 7 +----- src/bun.zig | 15 +++++++++++++ src/cli.zig | 17 +++++++++++++-- src/cli/create_command.zig | 2 ++ src/cli/init_command.zig | 2 ++ src/cli/install_completions_command.zig | 4 ++++ src/darwin_c.zig | 2 +- src/feature_flags.zig | 1 - src/fs.zig | 4 ++++ src/install/install.zig | 3 +++ src/linux_c.zig | 1 + src/sys.zig | 5 ++++- src/sys_uv.zig | 2 +- src/tmp.zig | 4 ++-- src/windows_c.zig | 6 ++++++ test/bundler/bundler_edgecase.test.ts | 3 ++- test/cli/run/run-process-env.test.ts | 7 +++--- test/cli/run/transpiler-cache.test.ts | 1 - test/js/bun/util/bun-file-exists.test.js | 1 - test/js/bun/util/reportError.test.ts | 6 +++--- test/js/node/process/process-args.test.js | 4 ++-- test/js/node/process/process.test.js | 23 +++++++++++++------- 24 files changed, 106 insertions(+), 49 deletions(-) diff --git a/src/bun.js/RuntimeTranspilerCache.zig b/src/bun.js/RuntimeTranspilerCache.zig index 891e3e4866..0bc5536c6a 100644 --- a/src/bun.js/RuntimeTranspilerCache.zig +++ b/src/bun.js/RuntimeTranspilerCache.zig @@ -210,16 +210,16 @@ pub const RuntimeTranspilerCache = struct { break :brk metadata_buf[0..metadata_stream.pos]; }; - const vecs: []const std.os.iovec_const = if (output_bytes.len > 0) + const vecs: []const bun.PlatformIOVecConst = if (output_bytes.len > 0) &.{ - .{ .iov_base = metadata_bytes.ptr, .iov_len = metadata_bytes.len }, - .{ .iov_base = output_bytes.ptr, .iov_len = output_bytes.len }, - .{ .iov_base = sourcemap.ptr, .iov_len = sourcemap.len }, + bun.platformIOVecConstCreate(metadata_bytes), + bun.platformIOVecConstCreate(output_bytes), + bun.platformIOVecConstCreate(sourcemap), } else &.{ - .{ .iov_base = metadata_bytes.ptr, .iov_len = metadata_bytes.len }, - .{ .iov_base = sourcemap.ptr, .iov_len = sourcemap.len }, + bun.platformIOVecConstCreate(metadata_bytes), + bun.platformIOVecConstCreate(sourcemap), }; var position: isize = 0; @@ -228,8 +228,13 @@ pub const RuntimeTranspilerCache = struct { if (bun.Environment.allow_assert) { var total: usize = 0; for (vecs) |v| { - std.debug.assert(v.iov_len > 0); - total += v.iov_len; + if (comptime bun.Environment.isWindows) { + std.debug.assert(v.len > 0); + total += v.len; + } else { + std.debug.assert(v.iov_len > 0); + total += v.iov_len; + } } std.debug.assert(end_position == total); } @@ -246,7 +251,7 @@ pub const RuntimeTranspilerCache = struct { } } - try tmpfile.finish(destination_path.sliceAssumeZ()); + try tmpfile.finish(@ptrCast(std.fs.path.basename(destination_path.slice()))); } pub fn load( @@ -481,6 +486,7 @@ pub const RuntimeTranspilerCache = struct { const file = cache_fd.asFile(); const metadata_bytes = try file.preadAll(&metadata_bytes_buf, 0); + if (comptime bun.Environment.isWindows) try file.seekTo(0); var metadata_stream = std.io.fixedBufferStream(metadata_bytes_buf[0..metadata_bytes]); var entry = Entry{ @@ -539,7 +545,7 @@ pub const RuntimeTranspilerCache = struct { const cache_dir_fd = brk: { if (std.fs.path.dirname(cache_file_path)) |dirname| { const dir = try std.fs.cwd().makeOpenPath(dirname, .{ .access_sub_paths = true }); - break :brk bun.toFD(dir.fd); + break :brk bun.toLibUVOwnedFD(dir.fd); } break :brk bun.toFD(std.fs.cwd().fd); diff --git a/src/bun.js/bindings/BunProcess.cpp b/src/bun.js/bindings/BunProcess.cpp index 2d6aef1963..a383be2ed8 100644 --- a/src/bun.js/bindings/BunProcess.cpp +++ b/src/bun.js/bindings/BunProcess.cpp @@ -32,6 +32,10 @@ #include #include #include +// Using the same typedef and define for `mode_t` and `umask` as node on windows. +// https://github.com/nodejs/node/blob/ad5e2dab4c8306183685973387829c2f69e793da/src/node_process_methods.cc#L29 +#define umask _umask +typedef int mode_t; #endif #include "JSNextTickQueue.h" #include "ProcessBindingUV.h" @@ -342,8 +346,6 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen, JSC_DEFINE_HOST_FUNCTION(Process_functionUmask, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { -#if !OS(WINDOWS) - if (callFrame->argumentCount() == 0 || callFrame->argument(0).isUndefined()) { mode_t currentMask = umask(0); umask(currentMask); @@ -376,9 +378,6 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionUmask, } return JSC::JSValue::encode(JSC::jsNumber(umask(newUmask))); -#else - return JSC::JSValue::encode(JSC::jsNumber(0)); -#endif } extern "C" uint64_t Bun__readOriginTimer(void*); diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index 29b439e287..e01a81d86d 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -2900,14 +2900,9 @@ pub const Blob = struct { return JSValue.jsBoolean(true); } - if (comptime Environment.isWindows) { - this.globalThis.throwTODO("exists is not implemented on Windows"); - return JSValue.jsUndefined(); - } - // We say regular files and pipes exist. // This is mostly meant for "Can we use this in new Response(file)?" - return JSValue.jsBoolean(bun.isRegularFile(store.data.file.mode) or std.os.S.ISFIFO(store.data.file.mode)); + return JSValue.jsBoolean(bun.isRegularFile(store.data.file.mode) or bun.C.S.ISFIFO(store.data.file.mode)); } // This mostly means 'can it be read?' diff --git a/src/bun.zig b/src/bun.zig index aebeb4f2ac..64eb4c5b61 100644 --- a/src/bun.zig +++ b/src/bun.zig @@ -130,6 +130,11 @@ pub const PlatformIOVec = if (Environment.isWindows) else std.os.iovec; +pub const PlatformIOVecConst = if (Environment.isWindows) + windows.libuv.uv_buf_t +else + std.os.iovec_const; + pub fn platformIOVecCreate(input: []const u8) PlatformIOVec { if (Environment.isWindows) return windows.libuv.uv_buf_t.init(input); if (Environment.allow_assert) { @@ -140,6 +145,16 @@ pub fn platformIOVecCreate(input: []const u8) PlatformIOVec { return .{ .iov_len = @intCast(input.len), .iov_base = @constCast(input.ptr) }; } +pub fn platformIOVecConstCreate(input: []const u8) PlatformIOVecConst { + if (Environment.isWindows) return windows.libuv.uv_buf_t.init(input); + if (Environment.allow_assert) { + if (input.len > @as(usize, std.math.maxInt(u32))) { + Output.debugWarn("call to bun.PlatformIOVecConst.init with length larger than u32, this will overflow on windows", .{}); + } + } + return .{ .iov_len = @intCast(input.len), .iov_base = input.ptr }; +} + pub fn platformIOVecToSlice(iovec: PlatformIOVec) []u8 { if (Environment.isWindows) return windows.libuv.uv_buf_t.slice(iovec); return iovec.base[0..iovec.len]; diff --git a/src/cli.zig b/src/cli.zig index a6bd336d3f..12e726d3e6 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -1779,6 +1779,8 @@ pub const Command = struct { const script_name_to_search = ctx.args.entry_points[0]; + var absolute_script_path: ?string = null; + var file_path = script_name_to_search; const file_: anyerror!std.fs.File = brk: { if (std.fs.path.isAbsoluteWindows(script_name_to_search)) { @@ -1787,6 +1789,7 @@ pub const Command = struct { if (comptime Environment.isWindows) { resolved = resolve_path.normalizeString(resolved, true, .windows); } + absolute_script_path = resolved; break :brk bun.openFile( resolved, .{ .mode = .read_only }, @@ -1822,7 +1825,17 @@ pub const Command = struct { Global.configureAllocator(.{ .long_running = true }); // the case where this doesn't work is if the script name on disk doesn't end with a known JS-like file extension - const absolute_script_path = bun.getFdPath(file.handle, &script_name_buf) catch return false; + absolute_script_path = absolute_script_path orelse brk: { + if (comptime !Environment.isWindows) break :brk bun.getFdPath(file.handle, &script_name_buf) catch return false; + + var fd_path_buf: bun.PathBuffer = undefined; + const path = bun.getFdPath(file.handle, &fd_path_buf) catch return false; + break :brk resolve_path.normalizeString( + resolve_path.PosixToWinNormalizer.resolveCWDWithExternalBufZ(&script_name_buf, path) catch @panic("Could not resolve path"), + true, + .windows, + ); + }; if (!ctx.debug.loaded_bunfig) { bun.CLI.Arguments.loadConfigPath(ctx.allocator, true, "bunfig.toml", ctx, .RunCommand) catch {}; @@ -1830,7 +1843,7 @@ pub const Command = struct { BunJS.Run.boot( ctx.*, - absolute_script_path, + absolute_script_path.?, ) catch |err| { if (Output.enable_ansi_colors) { ctx.log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), true) catch {}; diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig index df48d36b09..99cfcbba52 100644 --- a/src/cli/create_command.zig +++ b/src/cli/create_command.zig @@ -555,6 +555,7 @@ pub const CreateCommand = struct { package_json_contents = try MutableString.init(ctx.allocator, size); package_json_contents.list.expandToCapacity(); + const prev_file_pos = if (comptime Environment.isWindows) try pkg.getPos() else 0; _ = pkg.preadAll(package_json_contents.list.items, 0) catch |err| { package_json_file = null; @@ -565,6 +566,7 @@ pub const CreateCommand = struct { Output.prettyErrorln("Error reading package.json: {s}", .{@errorName(err)}); break :read_package_json; }; + if (comptime Environment.isWindows) try pkg.seekTo(prev_file_pos); // The printer doesn't truncate, so we must do so manually std.os.ftruncate(pkg.handle, 0) catch {}; diff --git a/src/cli/init_command.zig b/src/cli/init_command.zig index fa982cf214..05153b35dc 100644 --- a/src/cli/init_command.zig +++ b/src/cli/init_command.zig @@ -136,10 +136,12 @@ pub const InitCommand = struct { package_json_contents = try MutableString.init(alloc, size); package_json_contents.list.expandToCapacity(); + const prev_file_pos = if (comptime Environment.isWindows) try pkg.getPos() else 0; _ = pkg.preadAll(package_json_contents.list.items, 0) catch { package_json_file = null; break :read_package_json; }; + if (comptime Environment.isWindows) try pkg.seekTo(prev_file_pos); } } diff --git a/src/cli/install_completions_command.zig b/src/cli/install_completions_command.zig index b2cf708249..b0953d9b99 100644 --- a/src/cli/install_completions_command.zig +++ b/src/cli/install_completions_command.zig @@ -446,6 +446,10 @@ pub const InstallCompletionsCommand = struct { 0, ) catch break :brk true; + if (comptime Environment.isWindows) { + try dot_zshrc.seekTo(0); + } + const contents = buf[0..read]; // Do they possibly have it in the file already? diff --git a/src/darwin_c.zig b/src/darwin_c.zig index d3f715fc45..b3ec5b1015 100644 --- a/src/darwin_c.zig +++ b/src/darwin_c.zig @@ -775,8 +775,8 @@ pub const preallocate_length = std.math.maxInt(u51); pub const Mode = std.os.mode_t; pub const E = std.os.E; +pub const S = std.os.S; pub fn getErrno(rc: anytype) E { return std.c.getErrno(rc); } - pub extern "c" fn umask(Mode) Mode; diff --git a/src/feature_flags.zig b/src/feature_flags.zig index 4c3874bc40..d42ae89f68 100644 --- a/src/feature_flags.zig +++ b/src/feature_flags.zig @@ -177,5 +177,4 @@ pub const concurrent_transpiler = !env.isWindows; // https://github.com/oven-sh/bun/issues/5426#issuecomment-1813865316 pub const disable_auto_js_to_ts_in_node_modules = true; -// TODO: implement the IO for rtc for windows pub const runtime_transpiler_cache = !env.isWindows; diff --git a/src/fs.zig b/src/fs.zig index dab45f0df6..973e54ce6a 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -1133,10 +1133,12 @@ pub const FileSystem = struct { while (true) { // We use pread to ensure if the file handle was open, it doesn't seek from the last position + const prev_file_pos = if (comptime Environment.isWindows) try file.getPos() else 0; const read_count = file.preadAll(shared_buffer.list.items[offset..], offset) catch |err| { fs.readFileError(path, err); return err; }; + if (comptime Environment.isWindows) try file.seekTo(prev_file_pos); shared_buffer.list.items = shared_buffer.list.items[0 .. read_count + offset]; file_contents = shared_buffer.list.items; debug("pread({d}, {d}) = {d}", .{ file.handle, size, read_count }); @@ -1179,10 +1181,12 @@ pub const FileSystem = struct { // stick a zero at the end buf[size] = 0; + const prev_file_pos = if (comptime Environment.isWindows) try file.getPos() else 0; const read_count = file.preadAll(buf, 0) catch |err| { fs.readFileError(path, err); return err; }; + if (comptime Environment.isWindows) try file.seekTo(prev_file_pos); file_contents = buf[0..read_count]; debug("pread({d}, {d}) = {d}", .{ file.handle, size, read_count }); diff --git a/src/install/install.zig b/src/install/install.zig index 41fd42c9e5..2a07a5a6d8 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -6582,6 +6582,7 @@ pub const PackageManager = struct { current_package_json_buf, 0, ); + if (comptime Environment.isWindows) try manager.root_package_json_file.seekTo(0); const package_json_source = logger.Source.initPathString( package_json_cwd, @@ -6757,6 +6758,7 @@ pub const PackageManager = struct { current_package_json_buf, 0, ); + if (comptime Environment.isWindows) try manager.root_package_json_file.seekTo(0); const package_json_source = logger.Source.initPathString( package_json_cwd, @@ -7462,6 +7464,7 @@ pub const PackageManager = struct { current_package_json_buf, 0, ); + if (comptime Environment.isWindows) try manager.root_package_json_file.seekTo(0); const package_json_source = logger.Source.initPathString( package_json_cwd, diff --git a/src/linux_c.zig b/src/linux_c.zig index f15eb555c5..19f289f9d5 100644 --- a/src/linux_c.zig +++ b/src/linux_c.zig @@ -576,6 +576,7 @@ pub const IFF_LOOPBACK = net_c.IFF_LOOPBACK; pub const Mode = u32; pub const E = std.os.E; +pub const S = std.os.S; pub extern "c" fn umask(Mode) Mode; diff --git a/src/sys.zig b/src/sys.zig index f978375452..d96b738ea2 100644 --- a/src/sys.zig +++ b/src/sys.zig @@ -872,7 +872,10 @@ pub fn writev(fd: bun.FileDescriptor, buffers: []std.os.iovec) Maybe(usize) { } } -pub fn pwritev(fd: bun.FileDescriptor, buffers: []const std.os.iovec_const, position: isize) Maybe(usize) { +pub fn pwritev(fd: bun.FileDescriptor, buffers: []const bun.PlatformIOVecConst, position: isize) Maybe(usize) { + if (comptime Environment.isWindows) { + return sys_uv.pwritev(fd, buffers, position); + } if (comptime Environment.isMac) { const rc = pwritev_sym(fd.cast(), buffers.ptr, @as(i32, @intCast(buffers.len)), position); if (comptime Environment.allow_assert) diff --git a/src/sys_uv.zig b/src/sys_uv.zig index 696302b6c5..f1ef3de9b5 100644 --- a/src/sys_uv.zig +++ b/src/sys_uv.zig @@ -333,7 +333,7 @@ pub fn preadv(fd: FileDescriptor, bufs: []const bun.PlatformIOVec, position: i64 } } -pub fn pwritev(fd: FileDescriptor, bufs: []const bun.PlatformIOVec, position: i64) Maybe(usize) { +pub fn pwritev(fd: FileDescriptor, bufs: []const bun.PlatformIOVecConst, position: i64) Maybe(usize) { const uv_fd = bun.uvfdcast(fd); comptime std.debug.assert(bun.PlatformIOVec == uv.uv_buf_t); diff --git a/src/tmp.zig b/src/tmp.zig index ce30a8b058..2efd8c82ec 100644 --- a/src/tmp.zig +++ b/src/tmp.zig @@ -28,7 +28,7 @@ pub const Tmpfile = struct { if (comptime allow_tmpfile) { switch (bun.sys.openat(destination_dir, ".", O.WRONLY | O.TMPFILE | O.CLOEXEC, perm)) { .result => |fd| { - tmpfile.fd = fd; + tmpfile.fd = bun.toLibUVOwnedFD(fd); break :open; }, .err => |err| { @@ -43,7 +43,7 @@ pub const Tmpfile = struct { } tmpfile.fd = switch (bun.sys.openat(destination_dir, tmpfilename, O.CREAT | O.CLOEXEC | O.WRONLY, perm)) { - .result => |fd| fd, + .result => |fd| bun.toLibUVOwnedFD(fd), .err => |err| return .{ .err = err }, }; break :open; diff --git a/src/windows_c.zig b/src/windows_c.zig index 37c6fb5d83..964451f719 100644 --- a/src/windows_c.zig +++ b/src/windows_c.zig @@ -1269,6 +1269,12 @@ pub fn renameAtW( new_path_w: []const u16, replace_if_exists: bool, ) Maybe(void) { + if (comptime bun.Environment.allow_assert) { + // if the directories are the same and the destination path is absolute, the old path name is kept + if (old_dir_fd == new_dir_fd) { + std.debug.assert(!std.fs.path.isAbsoluteWindowsWTF16(new_path_w)); + } + } const src_fd = switch (bun.sys.ntCreateFile( old_dir_fd, old_path_w, diff --git a/test/bundler/bundler_edgecase.test.ts b/test/bundler/bundler_edgecase.test.ts index f9a427ab0f..ea9cd810e2 100644 --- a/test/bundler/bundler_edgecase.test.ts +++ b/test/bundler/bundler_edgecase.test.ts @@ -1,5 +1,6 @@ import assert from "assert"; import dedent from "dedent"; +import { sep } from "path"; import { itBundled, testForFile } from "./expectBundled"; var { describe, test, expect } = testForFile(import.meta.path); @@ -36,7 +37,7 @@ describe("bundler", () => { }, target: "bun", run: { - stdout: "a/b", + stdout: `a${sep}b`, }, }); itBundled("edgecase/ImportStarFunction", { diff --git a/test/cli/run/run-process-env.test.ts b/test/cli/run/run-process-env.test.ts index af4f86b541..44bc169824 100644 --- a/test/cli/run/run-process-env.test.ts +++ b/test/cli/run/run-process-env.test.ts @@ -1,4 +1,3 @@ -// @known-failing-on-windows: 1 failing import { describe, expect, test } from "bun:test"; import { bunExe, bunRunAsScript, tempDirWithFiles } from "harness"; @@ -7,7 +6,7 @@ describe("process.env", () => { const scriptName = "start:dev"; const dir = tempDirWithFiles("processenv", { - "package.json": `{'scripts': {'${scriptName}': '${bunExe()} run index.ts'}}`, + "package.json": JSON.stringify({ "scripts": { [`${scriptName}`]: `${bunExe()} run index.ts` } }), "index.ts": "console.log(process.env.npm_lifecycle_event);", }); @@ -18,9 +17,9 @@ describe("process.env", () => { // https://github.com/oven-sh/bun/issues/3589 test("npm_lifecycle_event should have the value of the last call", () => { const dir = tempDirWithFiles("processenv_ls_call", { - "package.json": `{"scripts": { "first": "${bunExe()} run --cwd lsc second" } }`, + "package.json": JSON.stringify({ scripts: { first: `${bunExe()} run --cwd lsc second` } }), "lsc": { - "package.json": `{"scripts": { "second": "${bunExe()} run index.ts" } }`, + "package.json": JSON.stringify({ scripts: { second: `${bunExe()} run index.ts` } }), "index.ts": "console.log(process.env.npm_lifecycle_event);", }, }); diff --git a/test/cli/run/transpiler-cache.test.ts b/test/cli/run/transpiler-cache.test.ts index cc4a915912..2ce052cdfb 100644 --- a/test/cli/run/transpiler-cache.test.ts +++ b/test/cli/run/transpiler-cache.test.ts @@ -1,4 +1,3 @@ -// @known-failing-on-windows: 1 failing import assert from "assert"; import { Subprocess } from "bun"; import { beforeEach, describe, expect, test } from "bun:test"; diff --git a/test/js/bun/util/bun-file-exists.test.js b/test/js/bun/util/bun-file-exists.test.js index 603c7adf34..cca28e3599 100644 --- a/test/js/bun/util/bun-file-exists.test.js +++ b/test/js/bun/util/bun-file-exists.test.js @@ -1,4 +1,3 @@ -// @known-failing-on-windows: 1 failing import { test, expect } from "bun:test"; import { join } from "path"; import { tmpdir } from "os"; diff --git a/test/js/bun/util/reportError.test.ts b/test/js/bun/util/reportError.test.ts index 223e0f626a..f6520b90b7 100644 --- a/test/js/bun/util/reportError.test.ts +++ b/test/js/bun/util/reportError.test.ts @@ -1,12 +1,12 @@ -// @known-failing-on-windows: 1 failing import { test, expect } from "bun:test"; import { spawnSync } from "bun"; +import { join } from "path"; import { bunEnv, bunExe } from "harness"; test("reportError", () => { const cwd = import.meta.dir; const { stderr } = spawnSync({ - cmd: [bunExe(), new URL("./reportError.ts", import.meta.url).pathname], + cmd: [bunExe(), join(import.meta.dir, "reportError.ts")], cwd, env: { ...bunEnv, @@ -14,6 +14,6 @@ test("reportError", () => { BUN_JSC_showPrivateScriptsInStackTraces: "0", }, }); - const output = stderr.toString().replaceAll(cwd, ""); + const output = stderr.toString().replaceAll(cwd, "").replaceAll("\\", "/"); expect(output).toMatchSnapshot(); }); diff --git a/test/js/node/process/process-args.test.js b/test/js/node/process/process-args.test.js index cb9bda00d0..c95d2e22b6 100644 --- a/test/js/node/process/process-args.test.js +++ b/test/js/node/process/process-args.test.js @@ -1,11 +1,11 @@ -// @known-failing-on-windows: 1 failing import { spawn } from "bun"; import { test, expect } from "bun:test"; +import { join } from "path"; import { bunExe } from "harness"; test("args exclude run", async () => { const arg0 = process.argv[0]; - const arg1 = import.meta.dir + "/print-process-args.js"; + const arg1 = join(import.meta.dir, "/print-process-args.js"); const exe = bunExe(); const { stdout: s1 } = spawn([exe, "print-process-args.js"], { cwd: import.meta.dir, diff --git a/test/js/node/process/process.test.js b/test/js/node/process/process.test.js index d2d18b4dbb..ffdd7ab269 100644 --- a/test/js/node/process/process.test.js +++ b/test/js/node/process/process.test.js @@ -9,13 +9,14 @@ it("process", () => { // this property isn't implemented yet but it should at least return a string const isNode = !process.isBun; - if (!isNode && process.title !== "bun") throw new Error("process.title is not 'bun'"); + if (!isNode && process.platform !== "win32" && process.title !== "bun") throw new Error("process.title is not 'bun'"); if (typeof process.env.USER !== "string") throw new Error("process.env is not an object"); if (process.env.USER.length === 0) throw new Error("process.env is missing a USER property"); - if (process.platform !== "darwin" && process.platform !== "linux") throw new Error("process.platform is invalid"); + if (process.platform !== "darwin" && process.platform !== "linux" && process.platform !== "win32") + throw new Error("process.platform is invalid"); if (isNode) throw new Error("process.isBun is invalid"); @@ -68,8 +69,9 @@ it("process.hrtime.bigint()", () => { it("process.release", () => { expect(process.release.name).toBe("node"); + const platform = process.platform == "win32" ? "windows" : process.platform; expect(process.release.sourceUrl).toContain( - `https://github.com/oven-sh/bun/release/bun-v${process.versions.bun}/bun-${process.platform}-${ + `https://github.com/oven-sh/bun/release/bun-v${process.versions.bun}/bun-${platform}-${ { arm64: "aarch64", x64: "x64" }[process.arch] || process.arch }`, ); @@ -155,11 +157,16 @@ it("process.umask()", () => { }).toThrow(RangeError); } - const orig = process.umask(0o777); - expect(orig).toBeGreaterThan(0); - expect(process.umask()).toBe(0o777); - expect(process.umask(undefined)).toBe(0o777); - expect(process.umask(Number(orig))).toBe(0o777); + const mask = process.platform == "win32" ? 0o600 : 0o777; + const orig = process.umask(mask); + if (process.platform == "win32") { + expect(orig).toBe(0); + } else { + expect(orig).toBeGreaterThan(0); + } + expect(process.umask()).toBe(mask); + expect(process.umask(undefined)).toBe(mask); + expect(process.umask(Number(orig))).toBe(mask); expect(process.umask()).toBe(orig); });