mirror of
https://github.com/oven-sh/bun
synced 2026-02-15 21:32:05 +00:00
Merge branch 'main' into kai/http-chunks
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import assert from "assert";
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { bunEnv, bunExe, tempDirWithFiles } from "harness";
|
||||
import path, { join } from "path";
|
||||
import assert from "assert";
|
||||
import { buildNoThrow } from "./buildNoThrow";
|
||||
|
||||
describe("Bun.build", () => {
|
||||
|
||||
@@ -122,7 +122,23 @@ describe("@types/bun integration test", () => {
|
||||
"error TS2339: Property 'write' does not exist on type 'ReadableByteStreamController'.",
|
||||
|
||||
"websocket.ts",
|
||||
"error TS2353: Object literal may only specify known properties, and 'headers' does not exist in type 'string[]'.",
|
||||
`error TS2353: Object literal may only specify known properties, and 'protocols' does not exist in type 'string[]'.`,
|
||||
`error TS2353: Object literal may only specify known properties, and 'protocol' does not exist in type 'string[]'.`,
|
||||
`error TS2353: Object literal may only specify known properties, and 'protocol' does not exist in type 'string[]'.`,
|
||||
`error TS2353: Object literal may only specify known properties, and 'headers' does not exist in type 'string[]'.`,
|
||||
`error TS2353: Object literal may only specify known properties, and 'protocols' does not exist in type 'string[]'.`,
|
||||
`error TS2554: Expected 2 arguments, but got 0.`,
|
||||
`error TS2551: Property 'URL' does not exist on type 'WebSocket'. Did you mean 'url'?`,
|
||||
`error TS2322: Type '"nodebuffer"' is not assignable to type 'BinaryType'.`,
|
||||
`error TS2339: Property 'ping' does not exist on type 'WebSocket'.`,
|
||||
`error TS2339: Property 'ping' does not exist on type 'WebSocket'.`,
|
||||
`error TS2339: Property 'ping' does not exist on type 'WebSocket'.`,
|
||||
`error TS2339: Property 'ping' does not exist on type 'WebSocket'.`,
|
||||
`error TS2339: Property 'pong' does not exist on type 'WebSocket'.`,
|
||||
`error TS2339: Property 'pong' does not exist on type 'WebSocket'.`,
|
||||
`error TS2339: Property 'pong' does not exist on type 'WebSocket'.`,
|
||||
`error TS2339: Property 'pong' does not exist on type 'WebSocket'.`,
|
||||
`error TS2339: Property 'terminate' does not exist on type 'WebSocket'.`,
|
||||
|
||||
"worker.ts",
|
||||
"error TS2339: Property 'ref' does not exist on type 'Worker'.",
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
import { dns as bun_dns } from "bun";
|
||||
import * as dns from "node:dns";
|
||||
import { expectType } from "./utilities";
|
||||
|
||||
dns.resolve("asdf", "A", () => {});
|
||||
dns.reverse("asdf", () => {});
|
||||
dns.getServers();
|
||||
|
||||
expectType(Bun.dns.getCacheStats()).is<{
|
||||
cacheHitsCompleted: number;
|
||||
cacheHitsInflight: number;
|
||||
cacheMisses: number;
|
||||
size: number;
|
||||
errors: number;
|
||||
totalCount: number;
|
||||
}>();
|
||||
|
||||
expectType(Bun.dns.V4MAPPED).is<number>();
|
||||
expectType(bun_dns.prefetch("bun.sh")).is<void>();
|
||||
|
||||
@@ -22,6 +22,8 @@ import * as sqlite from "bun:sqlite";
|
||||
sqlite.Database;
|
||||
|
||||
Bun satisfies typeof import("bun");
|
||||
expectType(Bun).is<typeof import("bun")>();
|
||||
expectType<typeof import("bun")>().is<typeof Bun>();
|
||||
|
||||
type ConstructorOf<T> = new (...args: any[]) => T;
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { TOML } from "bun";
|
||||
import data from "./bunfig.toml";
|
||||
import { expectType } from "./utilities";
|
||||
|
||||
expectType<any>(data);
|
||||
expectType(Bun.TOML.parse(data)).is<object>();
|
||||
expectType(TOML.parse(data)).is<object>();
|
||||
|
||||
@@ -1,15 +1,271 @@
|
||||
export class TestWebSocketClient {
|
||||
#ws: WebSocket;
|
||||
import { expectType } from "./utilities";
|
||||
|
||||
constructor() {
|
||||
this.#ws = new WebSocket("wss://dev.local", {
|
||||
headers: {
|
||||
cookie: "test=test",
|
||||
},
|
||||
});
|
||||
}
|
||||
// WebSocket constructor tests
|
||||
{
|
||||
// Constructor with string URL only
|
||||
new WebSocket("wss://dev.local");
|
||||
|
||||
close() {
|
||||
if (this.#ws != null) this.#ws.close();
|
||||
}
|
||||
// Constructor with string URL and protocols array
|
||||
new WebSocket("wss://dev.local", ["proto1", "proto2"]);
|
||||
|
||||
// Constructor with string URL and single protocol string
|
||||
new WebSocket("wss://dev.local", "proto1");
|
||||
|
||||
// Constructor with URL object only
|
||||
new WebSocket(new URL("wss://dev.local"));
|
||||
|
||||
// Constructor with URL object and protocols array
|
||||
new WebSocket(new URL("wss://dev.local"), ["proto1", "proto2"]);
|
||||
|
||||
// Constructor with URL object and single protocol string
|
||||
new WebSocket(new URL("wss://dev.local"), "proto1");
|
||||
|
||||
// Constructor with string URL and options object with protocols
|
||||
new WebSocket("wss://dev.local", {
|
||||
protocols: ["proto1", "proto2"],
|
||||
});
|
||||
|
||||
// Constructor with string URL and options object with protocol
|
||||
new WebSocket("wss://dev.local", {
|
||||
protocol: "proto1",
|
||||
});
|
||||
|
||||
// Constructor with URL object and options with TLS settings
|
||||
new WebSocket(new URL("wss://dev.local"), {
|
||||
protocol: "proto1",
|
||||
tls: {
|
||||
rejectUnauthorized: false,
|
||||
},
|
||||
});
|
||||
|
||||
// Constructor with headers
|
||||
new WebSocket("wss://dev.local", {
|
||||
headers: {
|
||||
"Cookie": "session=123456",
|
||||
"User-Agent": "BunWebSocketTest",
|
||||
},
|
||||
});
|
||||
|
||||
// Constructor with full options object
|
||||
new WebSocket("wss://dev.local", {
|
||||
protocols: ["proto1", "proto2"],
|
||||
headers: {
|
||||
"Cookie": "session=123456",
|
||||
},
|
||||
tls: {
|
||||
rejectUnauthorized: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Assignability test
|
||||
{
|
||||
function toAny<T>(value: T): any {
|
||||
return value;
|
||||
}
|
||||
|
||||
const AnySocket = toAny(WebSocket);
|
||||
|
||||
const ws: WebSocket = new AnySocket("wss://dev.local");
|
||||
|
||||
ws.close();
|
||||
ws.addEventListener("open", e => expectType(e).is<Event>());
|
||||
ws.addEventListener("message", e => expectType(e).is<MessageEvent>());
|
||||
ws.addEventListener("message", (e: MessageEvent<string>) => expectType(e).is<MessageEvent<string>>());
|
||||
ws.addEventListener("message", (e: MessageEvent<string>) => expectType(e.data).is<string>());
|
||||
}
|
||||
|
||||
// WebSocket static properties test
|
||||
{
|
||||
expectType(WebSocket.CONNECTING).is<0>();
|
||||
expectType(WebSocket.OPEN).is<1>();
|
||||
expectType(WebSocket.CLOSING).is<2>();
|
||||
expectType(WebSocket.CLOSED).is<3>();
|
||||
|
||||
const instance: WebSocket = null as never;
|
||||
expectType(instance.CONNECTING).is<0>();
|
||||
expectType(instance.OPEN).is<1>();
|
||||
expectType(instance.CLOSING).is<2>();
|
||||
expectType(instance.CLOSED).is<3>();
|
||||
}
|
||||
|
||||
// WebSocket event handlers test
|
||||
{
|
||||
const ws = new WebSocket("wss://dev.local");
|
||||
|
||||
// Using event handler properties
|
||||
ws.onopen = (event: Event) => {
|
||||
expectType(event).is<Event>();
|
||||
};
|
||||
|
||||
ws.onmessage = (event: MessageEvent<string>) => {
|
||||
expectType(event.data).is<string>();
|
||||
};
|
||||
|
||||
ws.onerror = (event: Event) => {
|
||||
expectType(event).is<Event>();
|
||||
};
|
||||
|
||||
ws.onclose = (event: CloseEvent) => {
|
||||
expectType(event).is<CloseEvent>();
|
||||
expectType(event.code).is<number>();
|
||||
expectType(event.reason).is<string>();
|
||||
expectType(event.wasClean).is<boolean>();
|
||||
};
|
||||
|
||||
// Using event handler properties without typing the agument
|
||||
ws.onopen = event => {
|
||||
expectType(event).is<Event>();
|
||||
};
|
||||
|
||||
ws.onmessage = event => {
|
||||
expectType(event.data).is<any>();
|
||||
|
||||
if (typeof event.data === "string") {
|
||||
expectType(event.data).is<string>();
|
||||
} else if (event.data instanceof ArrayBuffer) {
|
||||
expectType(event.data).is<ArrayBuffer>();
|
||||
}
|
||||
};
|
||||
|
||||
ws.onerror = event => {
|
||||
expectType(event).is<Event>();
|
||||
};
|
||||
|
||||
ws.onclose = event => {
|
||||
expectType(event).is<CloseEvent>();
|
||||
expectType(event.code).is<number>();
|
||||
expectType(event.reason).is<string>();
|
||||
expectType(event.wasClean).is<boolean>();
|
||||
};
|
||||
}
|
||||
|
||||
// WebSocket addEventListener test
|
||||
{
|
||||
const ws = new WebSocket("wss://dev.local");
|
||||
|
||||
// Event handler functions
|
||||
const handleOpen = (event: Event) => {
|
||||
expectType(event).is<Event>();
|
||||
};
|
||||
|
||||
const handleMessage = (event: MessageEvent<string>) => {
|
||||
expectType(event.data).is<string>();
|
||||
};
|
||||
|
||||
const handleError = (event: Event) => {
|
||||
expectType(event).is<Event>();
|
||||
};
|
||||
|
||||
const handleClose = (event: CloseEvent) => {
|
||||
expectType(event).is<CloseEvent>();
|
||||
expectType(event.code).is<number>();
|
||||
expectType(event.reason).is<string>();
|
||||
expectType(event.wasClean).is<boolean>();
|
||||
};
|
||||
|
||||
// Add event listeners
|
||||
ws.addEventListener("open", handleOpen);
|
||||
ws.addEventListener("message", handleMessage);
|
||||
ws.addEventListener("error", handleError);
|
||||
ws.addEventListener("close", handleClose);
|
||||
|
||||
// Remove event listeners
|
||||
ws.removeEventListener("open", handleOpen);
|
||||
ws.removeEventListener("message", handleMessage);
|
||||
ws.removeEventListener("error", handleError);
|
||||
ws.removeEventListener("close", handleClose);
|
||||
}
|
||||
|
||||
// WebSocket property access test
|
||||
{
|
||||
const ws = new WebSocket("wss://dev.local");
|
||||
|
||||
// Read various properties
|
||||
expectType(ws.readyState).is<0 | 2 | 1 | 3>();
|
||||
expectType(ws.bufferedAmount).is<number>();
|
||||
expectType(ws.url).is<string>();
|
||||
expectType(ws.protocol).is<string>();
|
||||
expectType(ws.extensions).is<string>();
|
||||
|
||||
// Legacy URL property (deprecated but exists)
|
||||
expectType(ws.URL).is<string>();
|
||||
|
||||
// Set binary type
|
||||
ws.binaryType = "arraybuffer";
|
||||
ws.binaryType = "nodebuffer";
|
||||
}
|
||||
|
||||
// WebSocket send method test
|
||||
{
|
||||
const ws = new WebSocket("wss://dev.local");
|
||||
|
||||
// Send string data
|
||||
ws.send("Hello, server!");
|
||||
|
||||
// Send ArrayBuffer
|
||||
const buffer = new ArrayBuffer(10);
|
||||
ws.send(buffer);
|
||||
|
||||
// Send ArrayBufferView (Uint8Array)
|
||||
const uint8Array = new Uint8Array(buffer);
|
||||
ws.send(uint8Array);
|
||||
|
||||
// --------------------------------------- //
|
||||
// `.send(blob)` is not supported yet
|
||||
// --------------------------------------- //
|
||||
// // Send Blob
|
||||
// const blob = new Blob(["Hello, server!"]);
|
||||
// ws.send(blob);
|
||||
// --------------------------------------- //
|
||||
}
|
||||
|
||||
// WebSocket close method test
|
||||
{
|
||||
const ws = new WebSocket("wss://dev.local");
|
||||
|
||||
// Close without parameters
|
||||
ws.close();
|
||||
|
||||
// Close with code
|
||||
ws.close(1000);
|
||||
|
||||
// Close with code and reason
|
||||
ws.close(1001, "Going away");
|
||||
}
|
||||
|
||||
// Bun-specific WebSocket extensions test
|
||||
{
|
||||
const ws = new WebSocket("wss://dev.local");
|
||||
|
||||
// Send ping frame with no data
|
||||
ws.ping();
|
||||
|
||||
// Send ping frame with string data
|
||||
ws.ping("ping data");
|
||||
|
||||
// Send ping frame with ArrayBuffer
|
||||
const pingBuffer = new ArrayBuffer(4);
|
||||
ws.ping(pingBuffer);
|
||||
|
||||
// Send ping frame with ArrayBufferView
|
||||
const pingView = new Uint8Array(pingBuffer);
|
||||
ws.ping(pingView);
|
||||
|
||||
// Send pong frame with no data
|
||||
ws.pong();
|
||||
|
||||
// Send pong frame with string data
|
||||
ws.pong("pong data");
|
||||
|
||||
// Send pong frame with ArrayBuffer
|
||||
const pongBuffer = new ArrayBuffer(4);
|
||||
ws.pong(pongBuffer);
|
||||
|
||||
// Send pong frame with ArrayBufferView
|
||||
const pongView = new Uint8Array(pongBuffer);
|
||||
ws.pong(pongView);
|
||||
|
||||
// Terminate the connection immediately
|
||||
ws.terminate();
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { WebSocket, WebSocketServer } from "ws";
|
||||
|
||||
const ws = new WebSocket("ws://www.host.com/path");
|
||||
|
||||
ws.send("asdf");
|
||||
|
||||
const wss = new WebSocketServer({
|
||||
port: 8080,
|
||||
perMessageDeflate: false,
|
||||
});
|
||||
wss;
|
||||
@@ -5,20 +5,21 @@ import path from "path";
|
||||
const words: Record<string, { reason: string; limit?: number; regex?: boolean }> = {
|
||||
" != undefined": { reason: "This is by definition Undefined Behavior." },
|
||||
" == undefined": { reason: "This is by definition Undefined Behavior." },
|
||||
'@import("root").bun.': { reason: "Only import 'bun' once" },
|
||||
"undefined != ": { reason: "This is by definition Undefined Behavior." },
|
||||
"undefined == ": { reason: "This is by definition Undefined Behavior." },
|
||||
|
||||
'@import("bun").': { reason: "Only import 'bun' once" },
|
||||
"std.debug.assert": { reason: "Use bun.assert instead", limit: 26 },
|
||||
"std.debug.dumpStackTrace": { reason: "Use bun.handleErrorReturnTrace or bun.crash_handler.dumpStackTrace instead" },
|
||||
"std.debug.print": { reason: "Don't let this be committed", limit: 0 },
|
||||
"std.mem.indexOfAny(u8": { reason: "Use bun.strings.indexOfAny", limit: 3 },
|
||||
"undefined != ": { reason: "This is by definition Undefined Behavior." },
|
||||
"undefined == ": { reason: "This is by definition Undefined Behavior." },
|
||||
"bun.toFD(std.fs.cwd().fd)": { reason: "Use bun.FD.cwd()" },
|
||||
"std.StringArrayHashMapUnmanaged(": { reason: "bun.StringArrayHashMapUnmanaged has a faster `eql`", limit: 12 },
|
||||
"std.StringArrayHashMap(": { reason: "bun.StringArrayHashMap has a faster `eql`", limit: 1 },
|
||||
"std.StringHashMapUnmanaged(": { reason: "bun.StringHashMapUnmanaged has a faster `eql`" },
|
||||
"std.StringHashMap(": { reason: "bun.StringHashMap has a faster `eql`" },
|
||||
"std.enums.tagName(": { reason: "Use bun.tagName instead", limit: 2 },
|
||||
"std.unicode": { reason: "Use bun.strings instead", limit: 36 },
|
||||
|
||||
"allocator.ptr ==": { reason: "The std.mem.Allocator context pointer can be undefined, which makes this comparison undefined behavior" },
|
||||
"allocator.ptr !=": { reason: "The std.mem.Allocator context pointer can be undefined, which makes this comparison undefined behavior", limit: 1 },
|
||||
"== allocator.ptr": { reason: "The std.mem.Allocator context pointer can be undefined, which makes this comparison undefined behavior" },
|
||||
@@ -27,8 +28,15 @@ const words: Record<string, { reason: string; limit?: number; regex?: boolean }>
|
||||
"alloc.ptr !=": { reason: "The std.mem.Allocator context pointer can be undefined, which makes this comparison undefined behavior" },
|
||||
"== alloc.ptr": { reason: "The std.mem.Allocator context pointer can be undefined, which makes this comparison undefined behavior" },
|
||||
"!= alloc.ptr": { reason: "The std.mem.Allocator context pointer can be undefined, which makes this comparison undefined behavior" },
|
||||
|
||||
[String.raw`: [a-zA-Z0-9_\.\*\?\[\]\(\)]+ = undefined,`]: { reason: "Do not default a struct field to undefined", limit: 242, regex: true },
|
||||
"usingnamespace": { reason: "Zig deprecates this, and will not support it in incremental compilation.", limit: 370 },
|
||||
"usingnamespace": { reason: "Zig deprecates this, and will not support it in incremental compilation.", limit: 50 },
|
||||
|
||||
"std.fs.Dir": { reason: "Prefer bun.sys + bun.FD instead of std.fs", limit: 180 },
|
||||
"std.fs.cwd": { reason: "Prefer bun.FD.cwd()", limit: 103 },
|
||||
"std.fs.File": { reason: "Prefer bun.sys + bun.FD instead of std.fs", limit: 71 },
|
||||
".stdFile()": { reason: "Prefer bun.sys + bun.FD instead of std.fs.File. Zig hides 'errno' when Bun wants to match libuv", limit: 18 },
|
||||
".stdDir()": { reason: "Prefer bun.sys + bun.FD instead of std.fs.File. Zig hides 'errno' when Bun wants to match libuv", limit: 48 },
|
||||
};
|
||||
const words_keys = [...Object.keys(words)];
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { spawn } from "bun";
|
||||
import { afterAll, describe, expect, mock, test } from "bun:test";
|
||||
import { describe, expect, mock, test } from "bun:test";
|
||||
import { bunEnv, bunExe } from "harness";
|
||||
|
||||
describe("Streaming body via", () => {
|
||||
@@ -28,24 +28,18 @@ describe("Streaming body via", () => {
|
||||
});
|
||||
|
||||
test("async generator function throws an error but continues to send the headers", async () => {
|
||||
let subprocess;
|
||||
|
||||
afterAll(() => {
|
||||
subprocess?.kill();
|
||||
});
|
||||
|
||||
const onMessage = mock(async url => {
|
||||
const response = await fetch(url);
|
||||
expect(response.headers.get("X-Hey")).toBe("123");
|
||||
subprocess?.kill();
|
||||
});
|
||||
|
||||
subprocess = spawn({
|
||||
await using subprocess = spawn({
|
||||
cwd: import.meta.dirname,
|
||||
cmd: [bunExe(), "async-iterator-throws.fixture.js"],
|
||||
env: bunEnv,
|
||||
ipc: onMessage,
|
||||
stdout: "ignore",
|
||||
stdout: "inherit",
|
||||
stderr: "pipe",
|
||||
});
|
||||
|
||||
|
||||
34
test/js/bun/test/fixtures/failing-test-done-test-fails.fixture.ts
vendored
Normal file
34
test/js/bun/test/fixtures/failing-test-done-test-fails.fixture.ts
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { describe, test, expect } from "bun:test";
|
||||
|
||||
describe("test.failing with a done callback", () => {
|
||||
test.failing("fails when done is called with no args", done => {
|
||||
done();
|
||||
});
|
||||
|
||||
test.failing("fails when done is called with undefined", done => {
|
||||
done(undefined);
|
||||
});
|
||||
|
||||
test.failing("fails when all expectations are met and done is called without an error", done => {
|
||||
expect(1).toBe(1);
|
||||
done();
|
||||
});
|
||||
|
||||
describe("when test fn is async", () => {
|
||||
// NOTE: tests that resolve/reject immediately hit a different code path
|
||||
test.failing("fails when done() is called immediately", async done => {
|
||||
done();
|
||||
});
|
||||
|
||||
test.failing("fails when done() is called on the next tick", async done => {
|
||||
await new Promise(resolve => process.nextTick(resolve));
|
||||
done();
|
||||
});
|
||||
|
||||
test.failing("fails when all expectations are met and done is called", async done => {
|
||||
await Bun.sleep(5);
|
||||
expect(1).toBe(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
42
test/js/bun/test/fixtures/failing-test-done-test-succeeds.fixture.ts
vendored
Normal file
42
test/js/bun/test/fixtures/failing-test-done-test-succeeds.fixture.ts
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import { describe, test } from "bun:test";
|
||||
|
||||
describe("test.failing with a done callback", () => {
|
||||
test.failing("passes when an error is thrown", done => {
|
||||
throw new Error("test error");
|
||||
});
|
||||
|
||||
test.failing("passes when done() is called with an error", done => {
|
||||
done(new Error("test error"));
|
||||
});
|
||||
|
||||
describe("when test fn is asynchronous but does not return a promise", () => {
|
||||
test.failing("passes when done(err) is called on next tick", done => {
|
||||
process.nextTick(() => {
|
||||
done(new Error("test error"));
|
||||
});
|
||||
});
|
||||
|
||||
test.failing("passes when done(err) is called on next event loop cycle", done => {
|
||||
setTimeout(() => {
|
||||
done(new Error("test error"));
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when test fn is async", () => {
|
||||
// NOTE: tests that resolve/reject immediately hit a different code path
|
||||
test.failing("passes when a promise rejects", async _done => {
|
||||
await Bun.sleep(5);
|
||||
throw new Error("test error");
|
||||
});
|
||||
|
||||
test.failing("passes when a promise rejects immediately", async _done => {
|
||||
throw new Error("test error");
|
||||
});
|
||||
|
||||
test.failing("passes when done() is called with an error", async done => {
|
||||
await Bun.sleep(5);
|
||||
done(new Error("test error"));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,20 @@
|
||||
import { isCI, isWindows } from "harness";
|
||||
|
||||
jest.setTimeout(5);
|
||||
test.failing("timeouts still count as failures", async () => {
|
||||
await Bun.sleep(1000);
|
||||
|
||||
describe("test.failing", () => {
|
||||
test.failing("Timeouts still count as failures", async () => {
|
||||
await Bun.sleep(1000);
|
||||
});
|
||||
|
||||
// fixme: hangs on windows. Timer callback never fires
|
||||
describe.skipIf(isWindows && isCI)("when using a done() callback", () => {
|
||||
test.failing("fails when an async test never calls done()", async _done => {
|
||||
// nada
|
||||
});
|
||||
|
||||
test.failing("fails when a sync test never calls done()", _done => {
|
||||
// nada
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { $, spawnSync } from "bun";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { describe, expect, it, test } from "bun:test";
|
||||
import { bunEnv, bunExe, DirectoryTree, tempDirWithFiles } from "harness";
|
||||
import { bunEnv, bunExe, DirectoryTree, isDebug, tempDirWithFiles } from "harness";
|
||||
|
||||
function test1000000(arg1: any, arg218718132: any) {}
|
||||
|
||||
@@ -185,7 +185,7 @@ class SnapshotTester {
|
||||
contents: string,
|
||||
opts: { shouldNotError?: boolean; shouldGrow?: boolean; skipSnapshot?: boolean } = {},
|
||||
) {
|
||||
test(label, async () => await this.update(contents, opts));
|
||||
test(label, async () => await this.update(contents, opts), isDebug ? 100_000 : 5_000);
|
||||
}
|
||||
async update(
|
||||
contents: string,
|
||||
|
||||
@@ -39,7 +39,37 @@ describe("test.failing", () => {
|
||||
if (result.exitCode === 0) {
|
||||
fail("Expected exit code to be non-zero\n\n" + stderr);
|
||||
}
|
||||
expect(stderr).toContain(" 1 fail\n");
|
||||
expect(stderr).toContain(" 0 pass\n");
|
||||
expect(stderr).toMatch(/timed out after \d+ms/i);
|
||||
});
|
||||
|
||||
describe("when using a done() callback", () => {
|
||||
it("when a test throws, rejects, or passes an error to done(), the test passes", async () => {
|
||||
const result = await $.cwd(
|
||||
fixtureDir,
|
||||
).nothrow()`${bunExe()} test ./failing-test-done-test-succeeds.fixture.ts`.quiet();
|
||||
const stderr = result.stderr.toString();
|
||||
try {
|
||||
expect(stderr).toContain("0 fail");
|
||||
expect(result.exitCode).toBe(0);
|
||||
} catch (e) {
|
||||
console.error(stderr);
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it("when the test doesn't throw, or otherwise fail, the test does not pass", async () => {
|
||||
const result = await $.cwd(
|
||||
fixtureDir,
|
||||
).nothrow()`${bunExe()} test ./failing-test-done-test-fails.fixture.ts`.quiet();
|
||||
const stderr = result.stderr.toString();
|
||||
try {
|
||||
expect(stderr).toContain("0 pass");
|
||||
expect(result.exitCode).not.toBe(0);
|
||||
} catch (e) {
|
||||
console.error(stderr);
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2371,3 +2371,49 @@ it("Empty requests should not be Transfer-Encoding: chunked", async () => {
|
||||
server.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("should reject non-standard body writes when rejectNonStandardBodyWrites is true", async () => {
|
||||
{
|
||||
let body_not_allowed_on_write;
|
||||
let body_not_allowed_on_end;
|
||||
|
||||
for (const rejectNonStandardBodyWrites of [true, false, undefined]) {
|
||||
await using server = http.createServer({
|
||||
rejectNonStandardBodyWrites,
|
||||
});
|
||||
|
||||
server.on("request", (req, res) => {
|
||||
body_not_allowed_on_write = false;
|
||||
body_not_allowed_on_end = false;
|
||||
res.writeHead(204);
|
||||
|
||||
try {
|
||||
res.write("bun");
|
||||
} catch (e: any) {
|
||||
expect(e?.code).toBe("ERR_HTTP_BODY_NOT_ALLOWED");
|
||||
body_not_allowed_on_write = true;
|
||||
}
|
||||
try {
|
||||
res.end("bun");
|
||||
} catch (e: any) {
|
||||
expect(e?.code).toBe("ERR_HTTP_BODY_NOT_ALLOWED");
|
||||
body_not_allowed_on_end = true;
|
||||
// if we throw here, we need to call end() to actually end the request
|
||||
res.end();
|
||||
}
|
||||
});
|
||||
|
||||
await once(server.listen(0), "listening");
|
||||
const url = `http://localhost:${server.address().port}`;
|
||||
|
||||
{
|
||||
await fetch(url, {
|
||||
method: "GET",
|
||||
}).then(res => res.text());
|
||||
|
||||
expect(body_not_allowed_on_write).toBe(rejectNonStandardBodyWrites || false);
|
||||
expect(body_not_allowed_on_end).toBe(rejectNonStandardBodyWrites || false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -509,7 +509,7 @@ describe("express.text()", function () {
|
||||
});
|
||||
});
|
||||
|
||||
function createApp(options) {
|
||||
function createApp(options?) {
|
||||
var app = express();
|
||||
|
||||
app.use(express.text(options));
|
||||
|
||||
41
test/js/third_party/next-auth/fixture/.gitignore
vendored
Normal file
41
test/js/third_party/next-auth/fixture/.gitignore
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/versions
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
14
test/js/third_party/next-auth/fixture/eslint.config.mjs
vendored
Normal file
14
test/js/third_party/next-auth/fixture/eslint.config.mjs
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { FlatCompat } from "@eslint/eslintrc";
|
||||
import { dirname } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
const compat = new FlatCompat({
|
||||
baseDirectory: __dirname,
|
||||
});
|
||||
|
||||
const eslintConfig = [...compat.extends("next/core-web-vitals", "next/typescript")];
|
||||
|
||||
export default eslintConfig;
|
||||
10
test/js/third_party/next-auth/fixture/next.config.ts
vendored
Normal file
10
test/js/third_party/next-auth/fixture/next.config.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
/* config options here */
|
||||
eslint: {
|
||||
ignoreDuringBuilds: true,
|
||||
},
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
28
test/js/third_party/next-auth/fixture/package.json
vendored
Normal file
28
test/js/third_party/next-auth/fixture/package.json
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "next",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "15.3.0",
|
||||
"next-auth": "5.0.0-beta.25",
|
||||
"react": "19.0.0",
|
||||
"react-dom": "19.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3",
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "15.3.0",
|
||||
"tailwindcss": "^4",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
5
test/js/third_party/next-auth/fixture/postcss.config.mjs
vendored
Normal file
5
test/js/third_party/next-auth/fixture/postcss.config.mjs
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
const config = {
|
||||
plugins: ["@tailwindcss/postcss"],
|
||||
};
|
||||
|
||||
export default config;
|
||||
1
test/js/third_party/next-auth/fixture/public/file.svg
vendored
Normal file
1
test/js/third_party/next-auth/fixture/public/file.svg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
||||
|
After Width: | Height: | Size: 391 B |
1
test/js/third_party/next-auth/fixture/public/globe.svg
vendored
Normal file
1
test/js/third_party/next-auth/fixture/public/globe.svg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
1
test/js/third_party/next-auth/fixture/public/next.svg
vendored
Normal file
1
test/js/third_party/next-auth/fixture/public/next.svg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
1
test/js/third_party/next-auth/fixture/public/vercel.svg
vendored
Normal file
1
test/js/third_party/next-auth/fixture/public/vercel.svg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
||||
|
After Width: | Height: | Size: 128 B |
1
test/js/third_party/next-auth/fixture/public/window.svg
vendored
Normal file
1
test/js/third_party/next-auth/fixture/public/window.svg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
||||
|
After Width: | Height: | Size: 385 B |
63
test/js/third_party/next-auth/fixture/server.js
vendored
Normal file
63
test/js/third_party/next-auth/fixture/server.js
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
import net from "net";
|
||||
import { parse } from "url";
|
||||
import http from "http";
|
||||
import next from "next";
|
||||
import { expect } from "bun:test";
|
||||
function test(port) {
|
||||
const payload = Buffer.from(JSON.stringify({ message: "bun" }));
|
||||
|
||||
function sendRequest(socket) {
|
||||
const { promise, resolve } = Promise.withResolvers();
|
||||
let first = true;
|
||||
socket.on("data", data => {
|
||||
if (first) {
|
||||
first = false;
|
||||
const statusText = data.toString("utf8").split("HTTP/1.1")[1]?.split("\r\n")[0]?.trim();
|
||||
try {
|
||||
expect(statusText).toBe("200 OK");
|
||||
resolve();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
socket.write(
|
||||
`POST /api/echo HTTP/1.1\r\nHost: localhost:8080\r\nConnection: keep-alive\r\nContent-Length: ${payload.byteLength}\r\n\r\n`,
|
||||
);
|
||||
socket.write(payload);
|
||||
|
||||
return promise;
|
||||
}
|
||||
const socket = net.connect({ port: port, host: "127.0.0.1" }, async () => {
|
||||
const timer = setTimeout(() => {
|
||||
console.error("timeout");
|
||||
process.exit(1);
|
||||
}, 30_000).unref();
|
||||
await sendRequest(socket);
|
||||
await sendRequest(socket);
|
||||
await sendRequest(socket);
|
||||
console.log("request sent");
|
||||
clearTimeout(timer);
|
||||
process.exit(0);
|
||||
});
|
||||
socket.on("error", err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
const app = next({ dev: true, dir: import.meta.dirname, quiet: true });
|
||||
const handle = app.getRequestHandler();
|
||||
|
||||
app.prepare().then(() => {
|
||||
const server = http
|
||||
.createServer((req, res) => {
|
||||
const parsedUrl = parse(req.url, true);
|
||||
handle(req, res, parsedUrl);
|
||||
})
|
||||
.listen(0, "127.0.0.1", () => {
|
||||
console.log("server listening", server.address().port);
|
||||
test(server.address().port);
|
||||
});
|
||||
});
|
||||
3
test/js/third_party/next-auth/fixture/src/app/api/auth/[...nextauth]/route.ts
vendored
Normal file
3
test/js/third_party/next-auth/fixture/src/app/api/auth/[...nextauth]/route.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { handlers } from "@/auth";
|
||||
|
||||
export const { GET, POST } = handlers;
|
||||
10
test/js/third_party/next-auth/fixture/src/app/api/echo/route.ts
vendored
Normal file
10
test/js/third_party/next-auth/fixture/src/app/api/echo/route.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { NextRequest } from 'next/server';
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
return Response.json(body);
|
||||
} catch (error) {
|
||||
return Response.json({ error: 'Invalid JSON' }, { status: 400 });
|
||||
}
|
||||
}
|
||||
75
test/js/third_party/next-auth/fixture/src/app/echo/page.tsx
vendored
Normal file
75
test/js/third_party/next-auth/fixture/src/app/echo/page.tsx
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import Link from 'next/link';
|
||||
|
||||
export default function EchoPage() {
|
||||
const [input, setInput] = useState('');
|
||||
const [response, setResponse] = useState<any>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/echo', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ message: input }),
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
setResponse(data);
|
||||
} catch (error) {
|
||||
setResponse({ error: 'Failed to fetch' });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen flex-col items-center justify-center p-8">
|
||||
<main className="w-full max-w-md">
|
||||
<h1 className="text-2xl font-bold mb-6">Echo API Demo</h1>
|
||||
|
||||
<form onSubmit={handleSubmit} className="mb-6">
|
||||
<div className="flex flex-col gap-4">
|
||||
<input
|
||||
type="text"
|
||||
value={input}
|
||||
onChange={(e) => setInput(e.target.value)}
|
||||
placeholder="Enter a message"
|
||||
className="p-3 border rounded-md"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="p-3 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 disabled:opacity-50"
|
||||
>
|
||||
{loading ? 'Sending...' : 'Send'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{response && (
|
||||
<div className="w-full p-4 border rounded-md mb-6">
|
||||
<h2 className="text-lg font-bold mb-2">Response:</h2>
|
||||
<pre className="bg-gray-100 p-3 rounded overflow-auto">
|
||||
{JSON.stringify(response, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Link
|
||||
href="/"
|
||||
className="text-indigo-600 hover:underline"
|
||||
>
|
||||
← Back to home
|
||||
</Link>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
BIN
test/js/third_party/next-auth/fixture/src/app/favicon.ico
vendored
Normal file
BIN
test/js/third_party/next-auth/fixture/src/app/favicon.ico
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
26
test/js/third_party/next-auth/fixture/src/app/globals.css
vendored
Normal file
26
test/js/third_party/next-auth/fixture/src/app/globals.css
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
:root {
|
||||
--background: #ffffff;
|
||||
--foreground: #171717;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--font-sans: var(--font-geist-sans);
|
||||
--font-mono: var(--font-geist-mono);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--background: #0a0a0a;
|
||||
--foreground: #ededed;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background);
|
||||
color: var(--foreground);
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
34
test/js/third_party/next-auth/fixture/src/app/layout.tsx
vendored
Normal file
34
test/js/third_party/next-auth/fixture/src/app/layout.tsx
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import "./globals.css";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Create Next App",
|
||||
description: "Generated by create next app",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
>
|
||||
{children}
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
9
test/js/third_party/next-auth/fixture/src/app/page.tsx
vendored
Normal file
9
test/js/third_party/next-auth/fixture/src/app/page.tsx
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { auth } from "@/auth";
|
||||
|
||||
export default async function Home() {
|
||||
const session = await auth();
|
||||
|
||||
return (
|
||||
<div>Hello</div>
|
||||
);
|
||||
}
|
||||
20
test/js/third_party/next-auth/fixture/src/app/protected/page.tsx
vendored
Normal file
20
test/js/third_party/next-auth/fixture/src/app/protected/page.tsx
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import { auth, signOut } from "@/auth";
|
||||
|
||||
export default async function ProtectedPage() {
|
||||
const session = await auth();
|
||||
|
||||
return (
|
||||
<div >
|
||||
<form action={async () => {
|
||||
"use server";
|
||||
await signOut({ redirectTo: "/" });
|
||||
}}>
|
||||
<button
|
||||
type="submit"
|
||||
>
|
||||
Sign out
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
62
test/js/third_party/next-auth/fixture/src/auth.ts
vendored
Normal file
62
test/js/third_party/next-auth/fixture/src/auth.ts
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
import NextAuth from "next-auth";
|
||||
import type { NextAuthConfig } from "next-auth";
|
||||
import CredentialsProvider from "next-auth/providers/credentials";
|
||||
import GoogleProvider from "next-auth/providers/google";
|
||||
|
||||
export const authConfig: NextAuthConfig = {
|
||||
pages: {
|
||||
signIn: "/login",
|
||||
},
|
||||
callbacks: {
|
||||
authorized({ auth, request: { nextUrl } }) {
|
||||
const isLoggedIn = !!auth?.user;
|
||||
const isOnProtectedPage = nextUrl.pathname.startsWith("/protected");
|
||||
if (isOnProtectedPage) {
|
||||
if (isLoggedIn) return true;
|
||||
return false; // Redirect to login page
|
||||
} else if (isLoggedIn) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
async jwt({ token, user }) {
|
||||
if (user) {
|
||||
token.user = user;
|
||||
}
|
||||
return token;
|
||||
},
|
||||
async session({ session, token }) {
|
||||
//@ts-ignore
|
||||
session.user = token.user;
|
||||
return session;
|
||||
},
|
||||
},
|
||||
providers: [
|
||||
CredentialsProvider({
|
||||
name: "Credentials",
|
||||
credentials: {
|
||||
email: { label: "Email", type: "email" },
|
||||
password: { label: "Password", type: "password" }
|
||||
},
|
||||
async authorize(credentials) {
|
||||
// This is a demo authentication - in a real app you would validate against a database
|
||||
if (credentials?.email === "user@example.com" && credentials?.password === "password") {
|
||||
return {
|
||||
id: "1",
|
||||
email: "user@example.com",
|
||||
name: "Demo User",
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
})
|
||||
],
|
||||
|
||||
session: {
|
||||
strategy: "jwt",
|
||||
},
|
||||
};
|
||||
|
||||
export const { auth, signIn, signOut, handlers } = NextAuth(authConfig);
|
||||
16
test/js/third_party/next-auth/fixture/src/client/session.tsx
vendored
Normal file
16
test/js/third_party/next-auth/fixture/src/client/session.tsx
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
"use client"
|
||||
import { useSession } from "next-auth/react"
|
||||
import { useEffect } from "react"
|
||||
|
||||
export function SessionState() {
|
||||
|
||||
const { data: session, status } = useSession()
|
||||
|
||||
useEffect( ()=> {
|
||||
|
||||
|
||||
});
|
||||
|
||||
return <div>status: {status}</div>
|
||||
|
||||
}
|
||||
10
test/js/third_party/next-auth/fixture/src/client/test.tsx
vendored
Normal file
10
test/js/third_party/next-auth/fixture/src/client/test.tsx
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
"use client"
|
||||
import { SessionProvider } from "next-auth/react"
|
||||
import { SessionState } from './session';
|
||||
|
||||
export function ClientComponent() {
|
||||
|
||||
|
||||
return <SessionProvider> <SessionState/></SessionProvider>
|
||||
|
||||
}
|
||||
3
test/js/third_party/next-auth/fixture/src/middleware.ts
vendored
Normal file
3
test/js/third_party/next-auth/fixture/src/middleware.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { auth } from "./auth";
|
||||
|
||||
export default auth;
|
||||
27
test/js/third_party/next-auth/fixture/tsconfig.json
vendored
Normal file
27
test/js/third_party/next-auth/fixture/tsconfig.json
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2017",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
19
test/js/third_party/next-auth/next-auth.test.ts
vendored
Normal file
19
test/js/third_party/next-auth/next-auth.test.ts
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { describe, it, expect } from "bun:test";
|
||||
import { bunRun, runBunInstall, bunEnv } from "harness";
|
||||
import { join } from "path";
|
||||
describe("next-auth", () => {
|
||||
it("should be able to call server action multiple times using auth middleware #18977", async () => {
|
||||
await runBunInstall(bunEnv, join(import.meta.dir, "fixture"), {
|
||||
allowWarnings: true,
|
||||
allowErrors: true,
|
||||
savesLockfile: false,
|
||||
});
|
||||
const result = bunRun(join(import.meta.dir, "fixture", "server.js"), {
|
||||
AUTH_SECRET: "I7Jiq12TSMlPlAzyVAT+HxYX7OQb/TTqIbfTTpr1rg8=",
|
||||
});
|
||||
expect(result.stderr).toBe("");
|
||||
expect(result.stdout).toBeDefined();
|
||||
const lines = result.stdout?.split("\n") ?? [];
|
||||
expect(lines[lines.length - 1]).toMatch(/request sent/);
|
||||
}, 30_000);
|
||||
});
|
||||
Reference in New Issue
Block a user