aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/bindings/URLDecomposition.cpp15
-rw-r--r--src/bun.js/bindings/URLSearchParams.cpp3
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.cpp6
-rw-r--r--src/bun.js/bindings/bindings.cpp21
-rw-r--r--src/bun.js/bindings/bindings.zig5
-rw-r--r--src/bun.js/bindings/headers.h3
-rw-r--r--src/bun.js/bindings/headers.zig1
-rw-r--r--src/bun.js/bindings/webcore/HTTPHeaderMap.cpp11
-rw-r--r--src/bun.js/fs.exports.js4
-rw-r--r--src/bun.js/streams.exports.js2
-rw-r--r--src/bun.js/webcore/body.zig24
-rw-r--r--test/bundler/transpiler.test.js58
-rw-r--r--test/js/bun/http/serve.test.ts19
-rw-r--r--test/js/deno/crypto/webcrypto.test.ts65
-rw-r--r--test/js/deno/url/url.test.ts6
-rw-r--r--test/js/deno/v8/error.test.ts2
-rw-r--r--test/js/node/disabled-module.test.js2
-rw-r--r--test/js/node/fs/fs.test.ts94
-rw-r--r--test/js/node/fs/readLargeFileSync.txt98
-rw-r--r--test/js/node/process/stdio-test-instance-a-lot.js (renamed from test/js/bun/spawn/stdio-test-instance-a-lot.js)0
-rw-r--r--test/js/node/process/stdio-test-instance.js (renamed from test/js/bun/spawn/stdio-test-instance.js)0
-rw-r--r--test/js/node/util/util-promisify.test.js22
-rw-r--r--test/js/web/abort/abort.test.ts8
-rw-r--r--test/js/web/fetch/fetch.test.ts1
-rw-r--r--test/js/web/url/url.test.ts59
25 files changed, 390 insertions, 139 deletions
diff --git a/src/bun.js/bindings/URLDecomposition.cpp b/src/bun.js/bindings/URLDecomposition.cpp
index f13d6b093..14cf25b6c 100644
--- a/src/bun.js/bindings/URLDecomposition.cpp
+++ b/src/bun.js/bindings/URLDecomposition.cpp
@@ -32,20 +32,11 @@ namespace WebCore {
String URLDecomposition::origin() const
{
auto fullURL = this->fullURL();
- auto protocol = fullURL.protocol();
- auto host = fullURL.host();
- auto port = fullURL.port();
- if (protocol == "file"_s)
- return "file://"_s;
+ if (fullURL.protocolIsInHTTPFamily() or fullURL.protocolIsInFTPFamily() or fullURL.protocolIs("ws"_s) or fullURL.protocolIs("wss"_s))
+ return fullURL.protocolHostAndPort();
- if (protocol.isEmpty() && host.isEmpty())
- return {};
-
- if (!port)
- return makeString(protocol, "://", host);
-
- return makeString(protocol, "://", host, ':', static_cast<uint32_t>(*port));
+ return "null"_s;
}
String URLDecomposition::protocol() const
diff --git a/src/bun.js/bindings/URLSearchParams.cpp b/src/bun.js/bindings/URLSearchParams.cpp
index 2b0ffef67..37f7d0eaf 100644
--- a/src/bun.js/bindings/URLSearchParams.cpp
+++ b/src/bun.js/bindings/URLSearchParams.cpp
@@ -151,7 +151,8 @@ void URLSearchParams::remove(const String& name)
{
if (!m_pairs.removeAllMatching([&](const auto& pair) {
return pair.key == name;
- }))
+ })
+ && m_pairs.size() > 0)
return;
updateURL();
needsSorting = true;
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp
index 7878b96a7..303be6190 100644
--- a/src/bun.js/bindings/ZigGlobalObject.cpp
+++ b/src/bun.js/bindings/ZigGlobalObject.cpp
@@ -959,8 +959,7 @@ JSC_DEFINE_HOST_FUNCTION(functionBTOA,
if (!stringToEncode.isAllLatin1()) {
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
- // TODO: DOMException
- JSC::throwTypeError(globalObject, scope, "The string contains invalid characters."_s);
+ throwException(globalObject, scope, createDOMException(globalObject, ExceptionCode::InvalidCharacterError));
return JSC::JSValue::encode(JSC::JSValue {});
}
@@ -991,8 +990,7 @@ static JSC_DEFINE_HOST_FUNCTION(functionATOB,
});
if (!decodedData) {
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
- // TODO: DOMException
- JSC::throwTypeError(globalObject, scope, "The string contains invalid characters."_s);
+ throwException(globalObject, scope, createDOMException(globalObject, ExceptionCode::InvalidCharacterError));
return JSC::JSValue::encode(JSC::JSValue {});
}
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp
index a5af29128..f43bfd4b8 100644
--- a/src/bun.js/bindings/bindings.cpp
+++ b/src/bun.js/bindings/bindings.cpp
@@ -478,12 +478,10 @@ bool Bun__deepEquals(JSC__JSGlobalObject* globalObject, JSValue v1, JSValue v2,
}
for (uint64_t i = 0; i < length; i++) {
- // array holes come back as empty values with tryGetIndexQuickly()
JSValue left = o1->canGetIndexQuickly(i)
? o1->getIndexQuickly(i)
: o1->tryGetIndexQuickly(i);
RETURN_IF_EXCEPTION(*scope, false);
-
JSValue right = o2->canGetIndexQuickly(i)
? o2->getIndexQuickly(i)
: o2->tryGetIndexQuickly(i);
@@ -2834,9 +2832,28 @@ int32_t JSC__JSValue__toInt32(JSC__JSValue JSValue0)
return JSC::JSValue::decode(JSValue0).asInt32();
}
+// truncates values larger than int32
int32_t JSC__JSValue__coerceToInt32(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1)
{
JSC::JSValue value = JSC::JSValue::decode(JSValue0);
+ if (value.isCell() && value.isHeapBigInt()) {
+ return static_cast<int32_t>(value.toBigInt64(arg1));
+ }
+ return value.toInt32(arg1);
+}
+
+int64_t JSC__JSValue__coerceToInt64(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1)
+{
+ JSValue value = JSValue::decode(JSValue0);
+ if (value.isCell() && value.isHeapBigInt()) {
+ return value.toBigInt64(arg1);
+ }
+
+ int64_t result = tryConvertToInt52(value.asDouble());
+ if (result != JSValue::notInt52) {
+ return result;
+ }
+
return value.toInt32(arg1);
}
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig
index 1bd045218..a5a12650d 100644
--- a/src/bun.js/bindings/bindings.zig
+++ b/src/bun.js/bindings/bindings.zig
@@ -3058,6 +3058,10 @@ pub const JSValue = enum(JSValueReprInt) {
return cppFn("coerceToInt32", .{ this, globalThis });
}
+ pub fn coerceToInt64(this: JSValue, globalThis: *JSC.JSGlobalObject) i64 {
+ return cppFn("coerceToInt64", .{ this, globalThis });
+ }
+
const PropertyIteratorFn = *const fn (
globalObject_: *JSGlobalObject,
ctx_ptr: ?*anyopaque,
@@ -4192,6 +4196,7 @@ pub const JSValue = enum(JSValueReprInt) {
"asPromise",
"asString",
"coerceToInt32",
+ "coerceToInt64",
"createEmptyArray",
"createEmptyObject",
"createInternalPromise",
diff --git a/src/bun.js/bindings/headers.h b/src/bun.js/bindings/headers.h
index 8c9b5c1d0..5c727f397 100644
--- a/src/bun.js/bindings/headers.h
+++ b/src/bun.js/bindings/headers.h
@@ -1,5 +1,5 @@
// clang-format off
-//-- AUTOGENERATED FILE -- 1679200292
+//-- AUTOGENERATED FILE -- 1679530947
#pragma once
#include <stddef.h>
@@ -288,6 +288,7 @@ CPP_DECL bJSC__JSObject JSC__JSValue__asObject(JSC__JSValue JSValue0);
CPP_DECL JSC__JSPromise* JSC__JSValue__asPromise(JSC__JSValue JSValue0);
CPP_DECL JSC__JSString* JSC__JSValue__asString(JSC__JSValue JSValue0);
CPP_DECL int32_t JSC__JSValue__coerceToInt32(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
+CPP_DECL int64_t JSC__JSValue__coerceToInt64(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
CPP_DECL JSC__JSValue JSC__JSValue__createEmptyArray(JSC__JSGlobalObject* arg0, size_t arg1);
CPP_DECL JSC__JSValue JSC__JSValue__createEmptyObject(JSC__JSGlobalObject* arg0, size_t arg1);
CPP_DECL JSC__JSValue JSC__JSValue__createInternalPromise(JSC__JSGlobalObject* arg0);
diff --git a/src/bun.js/bindings/headers.zig b/src/bun.js/bindings/headers.zig
index 5779655fa..11ccd2e53 100644
--- a/src/bun.js/bindings/headers.zig
+++ b/src/bun.js/bindings/headers.zig
@@ -201,6 +201,7 @@ pub extern fn JSC__JSValue__asObject(JSValue0: JSC__JSValue) bJSC__JSObject;
pub extern fn JSC__JSValue__asPromise(JSValue0: JSC__JSValue) ?*bindings.JSPromise;
pub extern fn JSC__JSValue__asString(JSValue0: JSC__JSValue) [*c]bindings.JSString;
pub extern fn JSC__JSValue__coerceToInt32(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) i32;
+pub extern fn JSC__JSValue__coerceToInt64(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) i64;
pub extern fn JSC__JSValue__createEmptyArray(arg0: *bindings.JSGlobalObject, arg1: usize) JSC__JSValue;
pub extern fn JSC__JSValue__createEmptyObject(arg0: *bindings.JSGlobalObject, arg1: usize) JSC__JSValue;
pub extern fn JSC__JSValue__createInternalPromise(arg0: *bindings.JSGlobalObject) JSC__JSValue;
diff --git a/src/bun.js/bindings/webcore/HTTPHeaderMap.cpp b/src/bun.js/bindings/webcore/HTTPHeaderMap.cpp
index 580a171d3..013aad750 100644
--- a/src/bun.js/bindings/webcore/HTTPHeaderMap.cpp
+++ b/src/bun.js/bindings/webcore/HTTPHeaderMap.cpp
@@ -284,18 +284,7 @@ bool HTTPHeaderMap::remove(HTTPHeaderName name)
void HTTPHeaderMap::add(HTTPHeaderName name, const String& value)
{
if (name == HTTPHeaderName::SetCookie) {
- auto cookieName = extractCookieName(value);
-
- size_t length = m_setCookieHeaders.size();
- const auto& cookies = m_setCookieHeaders.data();
- for (size_t i = 0; i < length; ++i) {
- if (extractCookieName(cookies[i]) == cookieName) {
- m_setCookieHeaders[i] = value;
- return;
- }
- }
m_setCookieHeaders.append(value);
-
return;
}
diff --git a/src/bun.js/fs.exports.js b/src/bun.js/fs.exports.js
index be82f0bd3..9036e14a2 100644
--- a/src/bun.js/fs.exports.js
+++ b/src/bun.js/fs.exports.js
@@ -223,8 +223,8 @@ export var ReadStream = (function (InternalReadStream) {
});
return Object.defineProperty(
- function ReadStream(options) {
- return new InternalReadStream(options);
+ function ReadStream(path, options) {
+ return new InternalReadStream(path, options);
},
Symbol.hasInstance,
{
diff --git a/src/bun.js/streams.exports.js b/src/bun.js/streams.exports.js
index 7fdf0fb6a..90c5c9b24 100644
--- a/src/bun.js/streams.exports.js
+++ b/src/bun.js/streams.exports.js
@@ -5301,7 +5301,7 @@ function createNativeStreamReadable(nativeType, Readable) {
var DYNAMICALLY_ADJUST_CHUNK_SIZE = process.env.BUN_DISABLE_DYNAMIC_CHUNK_SIZE !== "1";
const finalizer = new FinalizationRegistry(ptr => ptr && deinit(ptr));
- const MIN_BUFFER_SIZE = 256;
+ const MIN_BUFFER_SIZE = 512;
var NativeReadable = class NativeReadable extends Readable {
#ptr;
#refCount = 1;
diff --git a/src/bun.js/webcore/body.zig b/src/bun.js/webcore/body.zig
index 37a70343d..58d3a99b4 100644
--- a/src/bun.js/webcore/body.zig
+++ b/src/bun.js/webcore/body.zig
@@ -174,23 +174,13 @@ pub const Body = struct {
}
if (response_init.fastGet(ctx, .status)) |status_value| {
- if (status_value.isHeapBigInt()) {
- const less_than = switch (status_value.asBigIntCompare(ctx, JSValue.jsNumber(600))) {
- .less_than => true,
- else => false,
- };
- const greater_than = switch (status_value.asBigIntCompare(ctx, JSValue.jsNumber(99))) {
- .greater_than => true,
- else => false,
- };
-
- if (less_than and greater_than) {
- result.status_code = @truncate(u16, @intCast(u64, status_value.toInt64()));
- }
- } else if (status_value.isNumber()) {
- const number = status_value.to(i32);
- if (100 <= number and number < 999)
- result.status_code = @truncate(u16, @intCast(u32, number));
+ const number = status_value.coerceToInt64(ctx);
+ if ((200 <= number and number < 600) or number == 101) {
+ result.status_code = @truncate(u16, @intCast(u32, number));
+ } else {
+ const err = ctx.createRangeErrorInstance("The status provided ({d}) must be 101 or in the range of [200, 599]", .{number});
+ ctx.throwValue(err);
+ return null;
}
}
diff --git a/test/bundler/transpiler.test.js b/test/bundler/transpiler.test.js
index 3dc5a3a49..38b19efc0 100644
--- a/test/bundler/transpiler.test.js
+++ b/test/bundler/transpiler.test.js
@@ -830,6 +830,10 @@ export var ComponentThatHasSpreadCausesDeopt = $jsx(Hello, {
expect(parsed(code, !out.endsWith(";\n"), false)).toBe(out);
};
+ const expectPrintedNoTrim = (code, out) => {
+ expect(parsed(code, false, false)).toBe(out);
+ };
+
const expectBunPrinted_ = (code, out) => {
expect(parsed(code, !out.endsWith(";\n"), false, bunTranspiler)).toBe(out);
};
@@ -1246,17 +1250,29 @@ console.log(resolve.length)
// 'Expected identifier but found "("\n'
);
- expectPrinted_("for (x in y) ;", "for (x in y) {\n}");
- expectPrinted_("for ([] in y) ;", "for ([] in y) {\n}");
- expectPrinted_("for ({} in y) ;", "for ({} in y) {\n}");
- expectPrinted_("for ((x) in y) ;", "for (x in y) {\n}");
+ expectPrintedNoTrim("for (x in y) ;", "for (x in y)\n ;\n");
+ expectPrintedNoTrim("for ([] in y) ;", "for ([] in y)\n ;\n");
+ expectPrintedNoTrim("for ({} in y) ;", "for ({} in y)\n ;\n");
+ expectPrintedNoTrim("for ((x) in y) ;", "for (x in y)\n ;\n");
+ expectParseError("for (x in y)", "Unexpected end of file");
+ expectParseError("for ([] in y)", "Unexpected end of file");
+ expectParseError("for ({} in y)", "Unexpected end of file");
+ expectParseError("for ((x) in y)", "Unexpected end of file");
expectParseError("for (([]) in y) ;", "Invalid assignment target");
expectParseError("for (({}) in y) ;", "Invalid assignment target");
- expectPrinted_("for (x of y) ;", "for (x of y) {\n}");
- expectPrinted_("for ([] of y) ;", "for ([] of y) {\n}");
- expectPrinted_("for ({} of y) ;", "for ({} of y) {\n}");
- expectPrinted_("for ((x) of y) ;", "for (x of y) {\n}");
+ expectPrintedNoTrim("for (x of y) ;", "for (x of y)\n ;\n");
+ expectPrintedNoTrim("for ([] of y) ;", "for ([] of y)\n ;\n");
+ expectPrintedNoTrim("for ({} of y) ;", "for ({} of y)\n ;\n");
+ expectPrintedNoTrim("for ((x) of y) ;", "for (x of y)\n ;\n");
+ expectPrintedNoTrim("for (x of y) {}", "for (x of y)\n ;\n");
+ expectPrintedNoTrim("for ([] of y) {}", "for ([] of y)\n ;\n");
+ expectPrintedNoTrim("for ({} of y) {}", "for ({} of y)\n ;\n");
+ expectPrintedNoTrim("for ((x) of y) {}", "for (x of y)\n ;\n");
+ expectParseError("for (x of y)", "Unexpected end of file");
+ expectParseError("for ([] of y)", "Unexpected end of file");
+ expectParseError("for ({} of y)", "Unexpected end of file");
+ expectParseError("for ((x) of y)", "Unexpected end of file");
expectParseError("for (([]) of y) ;", "Invalid assignment target");
expectParseError("for (({}) of y) ;", "Invalid assignment target");
@@ -1271,10 +1287,28 @@ console.log(resolve.length)
expectParseError("({x = {a = b}} = c)", 'Unexpected "="');
expectParseError("[a = {b = c}] = d", 'Unexpected "="');
- expectPrinted_("for ([{a = {}}] in b) {}", "for ([{ a = {} }] in b) {\n}");
- expectPrinted_("for ([{a = {}}] of b) {}", "for ([{ a = {} }] of b) {\n}");
- expectPrinted_("for ({a = {}} in b) {}", "for ({ a = {} } in b) {\n}");
- expectPrinted_("for ({a = {}} of b) {}", "for ({ a = {} } of b) {\n}");
+ expectPrintedNoTrim("for ([{a = {}}] in b) ;", "for ([{ a = {} }] in b)\n ;\n");
+ expectPrintedNoTrim("for ([{a = {}}] of b) ;", "for ([{ a = {} }] of b)\n ;\n");
+ expectPrintedNoTrim("for ({a = {}} in b) ;", "for ({ a = {} } in b)\n ;\n");
+ expectPrintedNoTrim("for ({a = {}} of b) ;", "for ({ a = {} } of b)\n ;\n");
+ expectParseError("for ([{a = {}}] in b)", "Unexpected end of file");
+ expectParseError("for ([{a = {}}] of b)", "Unexpected end of file");
+ expectParseError("for ({a = {}} in b)", "Unexpected end of file");
+ expectParseError("for ({a = {}} of b)", "Unexpected end of file");
+
+ // this is different from esbuild
+ expectPrintedNoTrim("for ([{a = {}}] in b) {}", "for ([{ a = {} }] in b)\n ;\n");
+ expectPrintedNoTrim("for ([{a = {}}] of b) {}", "for ([{ a = {} }] of b)\n ;\n");
+ expectPrintedNoTrim("for ({a = {}} in b) {}", "for ({ a = {} } in b)\n ;\n");
+ expectPrintedNoTrim("for ({a = {}} of b) {}", "for ({ a = {} } of b)\n ;\n");
+ expectPrintedNoTrim("for (x in y) {}", "for (x in y)\n ;\n");
+ expectPrintedNoTrim("for ([] in y) {}", "for ([] in y)\n ;\n");
+ expectPrintedNoTrim("for ({} in y) {}", "for ({} in y)\n ;\n");
+ expectPrintedNoTrim("for ((x) in y) {}", "for (x in y)\n ;\n");
+ expectPrintedNoTrim("while (true) {}", "while (true)\n ;\n");
+
+ expectPrintedNoTrim("while (true) ;", "while (true)\n ;\n");
+ expectParseError("while (1)", "Unexpected end of file");
expectParseError("({a = {}} in b)", 'Unexpected "="');
expectParseError("[{a = {}}]\nof()", 'Unexpected "="');
diff --git a/test/js/bun/http/serve.test.ts b/test/js/bun/http/serve.test.ts
index 51d91767e..46c4790e2 100644
--- a/test/js/bun/http/serve.test.ts
+++ b/test/js/bun/http/serve.test.ts
@@ -36,7 +36,7 @@ afterAll(() => {
}
});
-[100, 101, 418, 999].forEach(statusCode => {
+[101, 418, 599, 200, 200n, 101n, 599n].forEach(statusCode => {
it(`should response with HTTP status code (${statusCode})`, async () => {
await runTest(
{
@@ -46,25 +46,30 @@ afterAll(() => {
},
async server => {
const response = await fetch(`http://${server.hostname}:${server.port}`);
- expect(response.status).toBe(statusCode);
+ expect(response.status).toBe(Number(statusCode));
expect(await response.text()).toBe("Foo Bar");
},
);
});
});
-[-200, 42, 12345, Math.PI].forEach(statusCode => {
- it(`should ignore invalid HTTP status code (${statusCode})`, async () => {
+[-200, 42, 100, 102, 12345, Math.PI, 999, 600, 199, 199n, 600n, 100n, 102n].forEach(statusCode => {
+ it(`should error on invalid HTTP status code (${statusCode})`, async () => {
await runTest(
{
fetch() {
- return new Response("Foo Bar", { status: statusCode });
+ try {
+ return new Response("Foo Bar", { status: statusCode });
+ } catch (err) {
+ expect(err).toBeInstanceOf(RangeError);
+ return new Response("Error!", { status: 500 });
+ }
},
},
async server => {
const response = await fetch(`http://${server.hostname}:${server.port}`);
- expect(response.status).toBe(200);
- expect(await response.text()).toBe("Foo Bar");
+ expect(response.status).toBe(500);
+ expect(await response.text()).toBe("Error!");
},
);
});
diff --git a/test/js/deno/crypto/webcrypto.test.ts b/test/js/deno/crypto/webcrypto.test.ts
index ea55e936f..7b8722a8a 100644
--- a/test/js/deno/crypto/webcrypto.test.ts
+++ b/test/js/deno/crypto/webcrypto.test.ts
@@ -2273,50 +2273,25 @@ test(async function testImportEcSpkiPkcs8() {
"SHA-384",
"SHA-512"
]){
- if ((hash == "SHA-256" && namedCurve == "P-256") || (hash == "SHA-384" && namedCurve == "P-384")) {
- const signatureECDSA = await subtle.sign({
- name: "ECDSA",
- hash
- }, privateKeyECDSA, new Uint8Array([
- 1,
- 2,
- 3,
- 4
- ]));
- const verifyECDSA = await subtle.verify({
- name: "ECDSA",
- hash
- }, publicKeyECDSA, signatureECDSA, new Uint8Array([
- 1,
- 2,
- 3,
- 4
- ]));
- assert(verifyECDSA);
- } else {
- await assertRejects(async ()=>{
- await subtle.sign({
- name: "ECDSA",
- hash
- }, privateKeyECDSA, new Uint8Array([
- 1,
- 2,
- 3,
- 4
- ]));
- }, DOMException, "Not implemented");
- await assertRejects(async ()=>{
- await subtle.verify({
- name: "ECDSA",
- hash
- }, publicKeyECDSA, new Uint8Array(signatureLength), new Uint8Array([
- 1,
- 2,
- 3,
- 4
- ]));
- }, DOMException, "Not implemented");
- }
+ const signatureECDSA = await subtle.sign({
+ name: "ECDSA",
+ hash
+ }, privateKeyECDSA, new Uint8Array([
+ 1,
+ 2,
+ 3,
+ 4
+ ]));
+ const verifyECDSA = await subtle.verify({
+ name: "ECDSA",
+ hash
+ }, publicKeyECDSA, signatureECDSA, new Uint8Array([
+ 1,
+ 2,
+ 3,
+ 4
+ ]));
+ assert(verifyECDSA);
}
}
});
@@ -2562,7 +2537,7 @@ test(async function testAESWrapKey() {
const unwrappedKeyBytes = await crypto.subtle.exportKey("raw", unwrappedKey);
assertEquals(new Uint8Array(hmacKeyBytes), new Uint8Array(unwrappedKeyBytes));
});
-test(async function testAesGcmTagLength() {
+test.ignore(async function testAesGcmTagLength() {
const key = await crypto.subtle.importKey("raw", new Uint8Array(32), "AES-GCM", false, [
"encrypt",
"decrypt"
diff --git a/test/js/deno/url/url.test.ts b/test/js/deno/url/url.test.ts
index 3c6061346..73e119419 100644
--- a/test/js/deno/url/url.test.ts
+++ b/test/js/deno/url/url.test.ts
@@ -166,7 +166,7 @@ test(function urlSearchParamsReuse() {
url.host = "baz.qat";
assert(sp === url.searchParams, "Search params should be reused.");
});
-test(function urlBackSlashes() {
+test.ignore(function urlBackSlashes() {
const url = new URL("https:\\\\foo:bar@baz.qat:8000\\qux\\quux?foo=bar&baz=12#qat");
assertEquals(url.href, "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat");
});
@@ -186,7 +186,7 @@ test(function urlRequireHost() {
assertThrows(()=>new URL("ws:///"), TypeError, "Invalid URL");
assertThrows(()=>new URL("wss:///"), TypeError, "Invalid URL");
});
-test(function urlDriveLetter() {
+test.ignore(function urlDriveLetter() {
assertEquals(new URL("file:///C:").href, "file:///C:");
assertEquals(new URL("file:///C:/").href, "file:///C:/");
assertEquals(new URL("file:///C:/..").href, "file:///C:/");
@@ -201,7 +201,7 @@ test(function urlEmptyPath() {
assertEquals(new URL("file://foo").pathname, "/");
assertEquals(new URL("abcd://foo").pathname, "");
});
-test(function urlPathRepeatedSlashes() {
+test.ignore(function urlPathRepeatedSlashes() {
assertEquals(new URL("http://foo//bar//").pathname, "//bar//");
assertEquals(new URL("file://foo///bar//").pathname, "/bar//");
assertEquals(new URL("abcd://foo//bar//").pathname, "//bar//");
diff --git a/test/js/deno/v8/error.test.ts b/test/js/deno/v8/error.test.ts
index 06567ac3b..34564f8df 100644
--- a/test/js/deno/v8/error.test.ts
+++ b/test/js/deno/v8/error.test.ts
@@ -29,7 +29,7 @@ test(function errorStackMessageLine() {
e6.message = null;
assertMatch(e6.stack!, /^null: null\n/);
});
-test(function captureStackTrace() {
+test.ignore(function captureStackTrace() {
function foo() {
const error = new Error();
const stack1 = error.stack!;
diff --git a/test/js/node/disabled-module.test.js b/test/js/node/disabled-module.test.js
index c12676959..d02a6b6df 100644
--- a/test/js/node/disabled-module.test.js
+++ b/test/js/node/disabled-module.test.js
@@ -24,7 +24,7 @@ test("AsyncLocalStorage polyfill", () => {
test("AsyncResource polyfill", () => {
const { AsyncResource } = import.meta.require("async_hooks");
- const resource = new AsyncResource("test");
+ const resource = new AsyncResource("prisma-client-request");
var called = false;
resource.runInAsyncScope(
() => {
diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts
index 4636d0d4b..644a3cf40 100644
--- a/test/js/node/fs/fs.test.ts
+++ b/test/js/node/fs/fs.test.ts
@@ -389,7 +389,7 @@ describe("lstat", () => {
});
it("folder metadata is correct", () => {
- const fileStats = lstatSync(new URL("../../test", import.meta.url).toString().slice("file://".length - 1));
+ const fileStats = lstatSync(new URL("../../../../test", import.meta.url).toString().slice("file://".length - 1));
expect(fileStats.isSymbolicLink()).toBe(false);
expect(fileStats.isFile()).toBe(false);
expect(fileStats.isDirectory()).toBe(true);
@@ -424,7 +424,7 @@ describe("stat", () => {
});
it("folder metadata is correct", () => {
- const fileStats = statSync(new URL("../../test", import.meta.url).toString().slice("file://".length - 1));
+ const fileStats = statSync(new URL("../../../../test", import.meta.url).toString().slice("file://".length - 1));
expect(fileStats.isSymbolicLink()).toBe(false);
expect(fileStats.isFile()).toBe(false);
expect(fileStats.isDirectory()).toBe(true);
@@ -605,8 +605,8 @@ describe("createReadStream", () => {
return await new Promise(resolve => {
stream.on("data", chunk => {
expect(chunk instanceof Buffer).toBe(true);
- expect(chunk.length).toBe(1);
- expect(chunk.toString()).toBe(data[i++]);
+ expect(chunk.length).toBe(22);
+ expect(chunk.toString()).toBe(data);
});
stream.on("end", () => {
@@ -614,6 +614,92 @@ describe("createReadStream", () => {
});
});
});
+
+ it("works (highWaterMark 1, 512 chunk)", async () => {
+ var stream = createReadStream(import.meta.dir + "/readLargeFileSync.txt", {
+ highWaterMark: 1,
+ });
+
+ var data = readFileSync(import.meta.dir + "/readLargeFileSync.txt", "utf8");
+ var i = 0;
+ return await new Promise(resolve => {
+ stream.on("data", chunk => {
+ expect(chunk instanceof Buffer).toBe(true);
+ expect(chunk.length).toBe(512);
+ expect(chunk.toString()).toBe(data.slice(i, i + 512));
+ i += 512;
+ });
+
+ stream.on("end", () => {
+ resolve(true);
+ });
+ });
+ });
+
+ it("works (512 chunk)", async () => {
+ var stream = createReadStream(import.meta.dir + "/readLargeFileSync.txt", {
+ highWaterMark: 512,
+ });
+
+ var data = readFileSync(import.meta.dir + "/readLargeFileSync.txt", "utf8");
+ var i = 0;
+ return await new Promise(resolve => {
+ stream.on("data", chunk => {
+ expect(chunk instanceof Buffer).toBe(true);
+ expect(chunk.length).toBe(512);
+ expect(chunk.toString()).toBe(data.slice(i, i + 512));
+ i += 512;
+ });
+
+ stream.on("end", () => {
+ resolve(true);
+ });
+ });
+ });
+
+ it("works with larger highWaterMark (1024 chunk)", async () => {
+ var stream = createReadStream(import.meta.dir + "/readLargeFileSync.txt", {
+ highWaterMark: 1024,
+ });
+
+ var data = readFileSync(import.meta.dir + "/readLargeFileSync.txt", "utf8");
+ var i = 0;
+ return await new Promise(resolve => {
+ stream.on("data", chunk => {
+ expect(chunk instanceof Buffer).toBe(true);
+ expect(chunk.length).toBe(1024);
+ expect(chunk.toString()).toBe(data.slice(i, i + 1024));
+ i += 1024;
+ });
+
+ stream.on("end", () => {
+ resolve(true);
+ });
+ });
+ });
+
+ it("works with very large file", async () => {
+ const tempFile = tmpdir() + "/" + "large-file" + Date.now() + ".txt";
+ await Bun.write(Bun.file(tempFile), "big data big data big data".repeat(10000));
+ var stream = createReadStream(tempFile, {
+ highWaterMark: 512,
+ });
+
+ var data = readFileSync(tempFile, "utf8");
+ var i = 0;
+ return await new Promise(resolve => {
+ stream.on("data", chunk => {
+ expect(chunk instanceof Buffer).toBe(true);
+ expect(chunk.toString()).toBe(data.slice(i, i + chunk.length));
+ i += chunk.length;
+ });
+ stream.on("end", () => {
+ expect(i).toBe("big data big data big data".repeat(10000).length);
+ rmSync(tempFile);
+ resolve(true);
+ });
+ });
+ });
});
describe("fs.WriteStream", () => {
diff --git a/test/js/node/fs/readLargeFileSync.txt b/test/js/node/fs/readLargeFileSync.txt
new file mode 100644
index 000000000..8bad1c6f5
--- /dev/null
+++ b/test/js/node/fs/readLargeFileSync.txt
@@ -0,0 +1,98 @@
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read successfully
+File read successfully File read successfully File read successfully File read successfully File read success \ No newline at end of file
diff --git a/test/js/bun/spawn/stdio-test-instance-a-lot.js b/test/js/node/process/stdio-test-instance-a-lot.js
index 71815ddea..71815ddea 100644
--- a/test/js/bun/spawn/stdio-test-instance-a-lot.js
+++ b/test/js/node/process/stdio-test-instance-a-lot.js
diff --git a/test/js/bun/spawn/stdio-test-instance.js b/test/js/node/process/stdio-test-instance.js
index fd820dc25..fd820dc25 100644
--- a/test/js/bun/spawn/stdio-test-instance.js
+++ b/test/js/node/process/stdio-test-instance.js
diff --git a/test/js/node/util/util-promisify.test.js b/test/js/node/util/util-promisify.test.js
index 336e070f7..518e8b7ad 100644
--- a/test/js/node/util/util-promisify.test.js
+++ b/test/js/node/util/util-promisify.test.js
@@ -20,7 +20,6 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// Tests adapted from https://github.com/nodejs/node/blob/main/test/parallel/test-util-promisify.js
-import { describe, it } from "bun:test";
import fs from "node:fs";
// TODO: vm module not implemented by bun yet
// import vm from 'node:vm';
@@ -112,22 +111,23 @@ describe("util.promisify", () => {
);
});
- it("should call custom promised promised function with proper args", () => {
+ it("should call custom promised promised function with proper args", async done => {
const firstValue = 5;
const secondValue = 17;
var called = false;
function fn(callback) {
called = true;
- callback(null, firstValue, secondValue);
+ callback(null, { firstValue, secondValue });
}
fn[Symbol("customPromisifyArgs")] = ["first", "second"];
- promisify(fn)().then((firstValue, secondValue) => {
- assert.strictEqual(called, true);
- assert.strictEqual(firstValue, 5);
- assert.strictEqual(secondValue, 17);
+ promisify(fn)().then(data => {
+ expect(called).toBe(true);
+ expect(data.firstValue).toBe(5);
+ expect(data.secondValue).toBe(17);
+ done();
});
});
@@ -293,11 +293,9 @@ describe("util.promisify", () => {
// throw error implementation in bun?
it("should throw on invalid inputs for promisify", () => {
[undefined, null, true, 0, "str", {}, [], Symbol()].forEach(input => {
- assert.throws(() => promisify(input), {
- code: "ERR_INVALID_ARG_TYPE",
- name: "TypeError",
- message: 'The "original" argument must be of type Function',
- });
+ expect(() => {
+ promisify(input);
+ }).toThrow('The "original" argument must be of type Function');
});
});
});
diff --git a/test/js/web/abort/abort.test.ts b/test/js/web/abort/abort.test.ts
index 04b965b94..731440266 100644
--- a/test/js/web/abort/abort.test.ts
+++ b/test/js/web/abort/abort.test.ts
@@ -143,11 +143,11 @@ describe("AbortController", () => {
},
{
label: "string",
- reason: "Aborted",
+ reason: "The operation was aborted.",
},
{
label: "Error",
- reason: new Error("Aborted"),
+ reason: new DOMException("The operation was aborted."),
},
];
for (const { label, reason } of reasons) {
@@ -165,8 +165,10 @@ describe("AbortController", () => {
expect(controller.signal.aborted).toBe(true);
if (reason === undefined) {
expect(controller.signal.reason instanceof DOMException).toBe(true);
+ } else if (reason instanceof DOMException) {
+ expect(controller.signal.reason).toBeInstanceOf(reason.constructor);
} else {
- expect(controller.signal.reason).toStrictEqual(reason);
+ expect(controller.signal.reason.message).toStrictEqual(reason);
}
});
}
diff --git a/test/js/web/fetch/fetch.test.ts b/test/js/web/fetch/fetch.test.ts
index f723761a7..183c5dc77 100644
--- a/test/js/web/fetch/fetch.test.ts
+++ b/test/js/web/fetch/fetch.test.ts
@@ -257,6 +257,7 @@ describe("Headers", () => {
headers.append("Set-cookie", "baz=bar");
const actual = [...headers];
expect(actual).toEqual([
+ ["set-cookie", "foo=bar"],
["set-cookie", "foo=baz"],
["set-cookie", "baz=bar"],
]);
diff --git a/test/js/web/url/url.test.ts b/test/js/web/url/url.test.ts
index 76bc1ff33..33b33aefd 100644
--- a/test/js/web/url/url.test.ts
+++ b/test/js/web/url/url.test.ts
@@ -1,6 +1,65 @@
import { describe, it, expect } from "bun:test";
describe("url", () => {
+ it("should have correct origin and protocol", () => {
+ var url = new URL("https://example.com");
+ expect(url.protocol).toBe("https:");
+ expect(url.origin).toBe("https://example.com");
+ url = new URL("about:blank");
+ expect(url.protocol).toBe("about:");
+ expect(url.origin).toBe("null");
+ url = new URL("http://example.com");
+ expect(url.protocol).toBe("http:");
+ expect(url.origin).toBe("http://example.com");
+ url = new URL("ftp://example.com");
+ expect(url.protocol).toBe("ftp:");
+ expect(url.origin).toBe("ftp://example.com");
+ url = new URL("file://example.com");
+ expect(url.protocol).toBe("file:");
+ expect(url.origin).toBe("null");
+ url = new URL("ws://example.com");
+ expect(url.protocol).toBe("ws:");
+ expect(url.origin).toBe("ws://example.com");
+ url = new URL("wss://example.com");
+ expect(url.protocol).toBe("wss:");
+ expect(url.origin).toBe("wss://example.com");
+ url = new URL("kekjafek://example.com");
+ expect(url.protocol).toBe("kekjafek:");
+ expect(url.origin).toBe("null");
+ url = new URL("data:text/plain,Hello%2C%20World!");
+ expect(url.protocol).toBe("data:");
+ expect(url.origin).toBe("null");
+ url = new URL("blob://example.com");
+ expect(url.protocol).toBe("blob:");
+ expect(url.origin).toBe("null");
+ url = new URL("javascript:alert('Hello World!')");
+ expect(url.protocol).toBe("javascript:");
+ expect(url.origin).toBe("null");
+ url = new URL("mailto:");
+ expect(url.protocol).toBe("mailto:");
+ expect(url.origin).toBe("null");
+ });
+ it.skip("should work with blob urls", () => {
+ // TODO
+ var url = new URL("blob:https://example.com/1234-5678");
+ expect(url.protocol).toBe("blob:");
+ expect(url.origin).toBe("https://example.com");
+ url = new URL("blob:file://text.txt");
+ expect(url.protocol).toBe("blob:");
+ expect(url.origin).toBe("file://text.txt");
+ url = new URL("blob:kjka://example.com");
+ expect(url.protocol).toBe("blob:");
+ expect(url.origin).toBe("null");
+ url = new URL("blob:blob://example.com");
+ expect(url.protocol).toBe("blob:");
+ expect(url.origin).toBe("null");
+ url = new URL("blob:blob://example.com");
+ expect(url.protocol).toBe("blob:");
+ expect(url.origin).toBe("null");
+ url = new URL("blob:ws://example.com");
+ expect(url.protocol).toBe("blob:");
+ expect(url.origin).toBe("ws://example.com");
+ });
it("prints", () => {
expect(Bun.inspect(new URL("https://example.com"))).toBe(`URL {
"href": "https://example.com/",