diff options
author | 2023-04-04 16:47:57 -0700 | |
---|---|---|
committer | 2023-04-04 16:47:57 -0700 | |
commit | 54d6f95f43774f92dddcbd91a669eec4a9f24d38 (patch) | |
tree | 67cd00278f8e054192c48547b642ec337f17e7c3 | |
parent | 76adc5be8a4f35730bbd81f06f043073e7160af8 (diff) | |
download | bun-54d6f95f43774f92dddcbd91a669eec4a9f24d38.tar.gz bun-54d6f95f43774f92dddcbd91a669eec4a9f24d38.tar.zst bun-54d6f95f43774f92dddcbd91a669eec4a9f24d38.zip |
Dylan/fix some failing tests (#2544)
* handle `umask()` invalid arguments
* move `bktree-fast` to test root, fix postinstall
* fix fs test
* could be baseline
* handle different timezones
* accidentally deleted tests
* fix hang in `AbortSignal.timeout`
* bring abort tests back
* Revert "bring abort tests back"
This reverts commit 0ff2ad5bf408694ac719b8ba0a38b16070e10201.
* bunx node-gyp
* bun x
* fix typecheck
* test
* Update inspect.test.js
---------
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
-rw-r--r-- | src/bun.js/bindings/Process.cpp | 30 | ||||
-rw-r--r-- | src/bun.js/bindings/webcore/AbortSignal.cpp | 9 | ||||
-rwxr-xr-x | test/bun.lockb | bin | 36018 -> 36018 bytes | |||
-rw-r--r-- | test/js/bun/util/inspect.test.js | 17 | ||||
-rw-r--r-- | test/js/node/fs/fs.test.ts | 2 | ||||
-rw-r--r-- | test/js/node/process/process.test.js | 25 | ||||
-rwxr-xr-x | test/js/third_party/napi_create_external/bun.lockb | bin | 1496 -> 0 bytes | |||
-rw-r--r-- | test/js/third_party/napi_create_external/package.json | 13 | ||||
-rw-r--r-- | test/package.json | 3 | ||||
-rw-r--r-- | test/tsconfig.json | 2 |
10 files changed, 72 insertions, 29 deletions
diff --git a/src/bun.js/bindings/Process.cpp b/src/bun.js/bindings/Process.cpp index 6be74ec6d..ed7992b41 100644 --- a/src/bun.js/bindings/Process.cpp +++ b/src/bun.js/bindings/Process.cpp @@ -284,16 +284,38 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen, JSC_DEFINE_HOST_FUNCTION(Process_functionUmask, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) { - if (callFrame->argumentCount() == 0) { - return JSC::JSValue::encode(JSC::jsNumber(umask(0))); + if (callFrame->argumentCount() == 0 || callFrame->argument(0).isUndefined()) { + mode_t currentMask = umask(0); + umask(currentMask); + return JSC::JSValue::encode(JSC::jsNumber(currentMask)); } auto& vm = globalObject->vm(); auto throwScope = DECLARE_THROW_SCOPE(vm); - int umaskValue = callFrame->argument(0).toInt32(globalObject); + JSValue numberValue = callFrame->argument(0); + + if (!numberValue.isNumber()) { + throwTypeError(globalObject, throwScope, "The \"mask\" argument must be a number"_s); + return JSValue::encode({}); + } + + if (!numberValue.isAnyInt()) { + throwRangeError(globalObject, throwScope, "The \"mask\" argument must be an integer"_s); + return JSValue::encode({}); + } + + double number = numberValue.toNumber(globalObject); + int64_t newUmask = isInt52(number) ? tryConvertToInt52(number) : numberValue.toInt32(globalObject); RETURN_IF_EXCEPTION(throwScope, JSC::JSValue::encode(JSC::JSValue {})); + if (newUmask < 0 || newUmask > 4294967295) { + StringBuilder messageBuilder; + messageBuilder.append("The \"mask\" value must be in range [0, 4294967295]. Received value: "_s); + messageBuilder.append(int52ToString(vm, newUmask, 10)->getString(globalObject)); + throwRangeError(globalObject, throwScope, messageBuilder.toString()); + return JSValue::encode({}); + } - return JSC::JSValue::encode(JSC::jsNumber(umask(umaskValue))); + return JSC::JSValue::encode(JSC::jsNumber(umask(newUmask))); } extern "C" uint64_t Bun__readOriginTimer(void*); diff --git a/src/bun.js/bindings/webcore/AbortSignal.cpp b/src/bun.js/bindings/webcore/AbortSignal.cpp index febc610b7..28a60d9e0 100644 --- a/src/bun.js/bindings/webcore/AbortSignal.cpp +++ b/src/bun.js/bindings/webcore/AbortSignal.cpp @@ -71,7 +71,14 @@ Ref<AbortSignal> AbortSignal::timeout(ScriptExecutionContext& context, uint64_t Locker locker { vm.apiLock() }; signal->signalAbort(toJS(globalObject, globalObject, DOMException::create(TimeoutError))); }; - context.postTaskOnTimeout(WTFMove(action), Seconds::fromMilliseconds(milliseconds)); + + if (milliseconds == 0) { + // immediately write to task queue + context.postTask(WTFMove(action)); + } else { + context.postTaskOnTimeout(WTFMove(action), Seconds::fromMilliseconds(milliseconds)); + } + return signal; } diff --git a/test/bun.lockb b/test/bun.lockb Binary files differindex e9e97d1aa..267386e00 100755 --- a/test/bun.lockb +++ b/test/bun.lockb diff --git a/test/js/bun/util/inspect.test.js b/test/js/bun/util/inspect.test.js index 8409a07c4..5d2f27c61 100644 --- a/test/js/bun/util/inspect.test.js +++ b/test/js/bun/util/inspect.test.js @@ -339,11 +339,18 @@ it("possibly formatted emojis log", () => { }); it("new Date(..)", () => { - expect(Bun.inspect(new Date(1679911059000))).toBe("2023-03-27T09:54:00.000Z"); - expect(Bun.inspect(new Date("March 27, 2023 09:54:00"))).toBe("2023-03-27T09:54:00.000Z"); - expect(Bun.inspect(new Date("2023-03-27T09:54:00"))).toBe("2023-03-27T09:54:00.000Z"); - expect(Bun.inspect(new Date(2023, 02, 27))).toBe("2023-03-27T00:00:00.000Z"); - expect(Bun.inspect(new Date(2023, 02, 27, 09, 54, 0))).toBe("2023-03-27T09:54:00.000Z"); + let s = Bun.inspect(new Date(1679911059000 - new Date().getTimezoneOffset())); + expect(s).toContain("2023-03-27T"); + expect(s).toHaveLength(24); + let offset = new Date().getTimezoneOffset() / 60; + let hour = (9 - offset).toString(); + if (hour.length === 1) { + hour = "0" + hour; + } + expect(Bun.inspect(new Date("March 27, 2023 " + hour + ":54:00"))).toBe("2023-03-27T09:54:00.000Z"); + expect(Bun.inspect(new Date("2023-03-27T" + hour + ":54:00"))).toBe("2023-03-27T09:54:00.000Z"); + expect(Bun.inspect(new Date(2023, 02, 27, -offset))).toBe("2023-03-27T00:00:00.000Z"); + expect(Bun.inspect(new Date(2023, 02, 27, 09 - offset, 54, 0))).toBe("2023-03-27T09:54:00.000Z"); expect(Bun.inspect(new Date("1679911059000"))).toBe("Invalid Date"); expect(Bun.inspect(new Date("hello world"))).toBe("Invalid Date"); diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts index 80f6c7dfe..fa27ab246 100644 --- a/test/js/node/fs/fs.test.ts +++ b/test/js/node/fs/fs.test.ts @@ -530,7 +530,7 @@ describe("rmdir", () => { } catch (e) {} expect(existsSync(path + "/file.txt")).toBe(true); rmdir(path, err => { - expect("ENOTEMPTY").toContain(err!.code); + expect("ENOTEMPTY EPERM").toContain(err!.code); done(); }); expect(existsSync(path + "/file.txt")).toBe(true); diff --git a/test/js/node/process/process.test.js b/test/js/node/process/process.test.js index 68d72e056..414392a79 100644 --- a/test/js/node/process/process.test.js +++ b/test/js/node/process/process.test.js @@ -66,10 +66,10 @@ it("process.hrtime.bigint()", () => { it("process.release", () => { expect(process.release.name).toBe("bun"); - expect(process.release.sourceUrl).toBe( + expect(process.release.sourceUrl).toContain( `https://github.com/oven-sh/bun/release/bun-v${process.versions.bun}/bun-${process.platform}-${ { arm64: "aarch64", x64: "x64" }[process.arch] || process.arch - }.zip`, + }`, ); }); @@ -117,9 +117,26 @@ it("process.uptime()", () => { }); it("process.umask()", () => { - const orig = process.umask(777); + let notNumbers = [265n, "string", true, false, null, {}, [], () => {}, Symbol("symbol"), BigInt(1)]; + for (let notNumber of notNumbers) { + expect(() => { + process.umask(notNumber); + }).toThrow('The "mask" argument must be a number'); + } + + let rangeErrors = [NaN, -1.4, Infinity, -Infinity, -1, 1.3, 4294967296]; + for (let rangeError of rangeErrors) { + expect(() => { + process.umask(rangeError); + }).toThrow(RangeError); + } + + const orig = process.umask(0o777); expect(orig).toBeGreaterThan(0); - expect(process.umask(orig)).toBe(777); + expect(process.umask()).toBe(0o777); + expect(process.umask(undefined)).toBe(0o777); + expect(process.umask(Number(orig))).toBe(0o777); + expect(process.umask()).toBe(orig); }); const versions = existsSync(import.meta.dir + "/../../src/generated_versions_list.zig"); diff --git a/test/js/third_party/napi_create_external/bun.lockb b/test/js/third_party/napi_create_external/bun.lockb Binary files differdeleted file mode 100755 index 7f6d3e95d..000000000 --- a/test/js/third_party/napi_create_external/bun.lockb +++ /dev/null diff --git a/test/js/third_party/napi_create_external/package.json b/test/js/third_party/napi_create_external/package.json deleted file mode 100644 index 659b279b2..000000000 --- a/test/js/third_party/napi_create_external/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "napi-create-external-test", - "type": "module", - "version": "1.0.0", - "description": "Test for napi_create_external", - "dependencies": { - "bktree-fast": "0.0.7", - "lodash": "^4.17.21" - }, - "scripts": { - "postinstall": "cd node_modules/bktree-fast && node-gyp configure" - } -} diff --git a/test/package.json b/test/package.json index d3fe8e70c..bd2295ddd 100644 --- a/test/package.json +++ b/test/package.json @@ -17,6 +17,7 @@ }, "private": true, "scripts": { - "typecheck": "tsc --noEmit" + "typecheck": "tsc --noEmit", + "postinstall": "cd node_modules/bktree-fast && bun x node-gyp configure build" } } diff --git a/test/tsconfig.json b/test/tsconfig.json index facc02cd3..7d6e245cc 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -11,6 +11,8 @@ "module": "ESNext", "target": "ESNext", "moduleResolution": "bundler", + "moduleDetection": "force", + "allowImportingTsExtensions": true, "strict": true, "downlevelIteration": true, "skipLibCheck": true, |