mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
* Improve support for \`debug-adapter-protocol\` * More improvements, fix formatting in debug console * Fix attaching * Prepare for source maps * Start of source map support, breakpoints work * Source map support * add some package.jsons * wip * Update package.json * More fixes * Make source maps safer if exception occurs * Check bun version if it fails * Fix console.log formatting * Fix source maps partly * More source map fixes * Prepare for extension * watch mode with dap * Improve preview code * Prepare for extension 2 --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import { beforeAll, afterAll, test, expect } from "bun:test";
|
|
import type { JSC } from "../../bun-inspector-protocol";
|
|
import { WebSocketInspector } from "../../bun-inspector-protocol";
|
|
import type { PipedSubprocess } from "bun";
|
|
import { spawn } from "bun";
|
|
import { remoteObjectToString } from "./preview";
|
|
|
|
let subprocess: PipedSubprocess | undefined;
|
|
let objects: JSC.Runtime.RemoteObject[] = [];
|
|
|
|
beforeAll(async () => {
|
|
subprocess = spawn({
|
|
cwd: import.meta.dir,
|
|
cmd: [process.argv0, "--inspect-wait=0", "fixtures/preview.js"],
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
stdin: "pipe",
|
|
});
|
|
const decoder = new TextDecoder();
|
|
let url: URL;
|
|
for await (const chunk of subprocess!.stdout) {
|
|
const text = decoder.decode(chunk);
|
|
if (text.includes("ws://")) {
|
|
url = new URL(/(ws:\/\/.*)/.exec(text)![0]);
|
|
break;
|
|
}
|
|
}
|
|
objects = await new Promise((resolve, reject) => {
|
|
const inspector = new WebSocketInspector({
|
|
url,
|
|
listener: {
|
|
["Inspector.connected"]: () => {
|
|
inspector.send("Inspector.enable");
|
|
inspector.send("Runtime.enable");
|
|
inspector.send("Console.enable");
|
|
inspector.send("Debugger.enable");
|
|
inspector.send("Debugger.resume");
|
|
inspector.send("Inspector.initialized");
|
|
},
|
|
["Inspector.disconnected"]: error => {
|
|
reject(error);
|
|
},
|
|
["Console.messageAdded"]: ({ message }) => {
|
|
const { parameters } = message;
|
|
resolve(parameters!);
|
|
inspector.close();
|
|
},
|
|
},
|
|
});
|
|
inspector.start();
|
|
});
|
|
});
|
|
|
|
afterAll(() => {
|
|
subprocess?.kill();
|
|
});
|
|
|
|
test("remoteObjectToString", () => {
|
|
for (const object of objects) {
|
|
expect(remoteObjectToString(object)).toMatchSnapshot();
|
|
}
|
|
});
|