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>
84 lines
2.4 KiB
TypeScript
84 lines
2.4 KiB
TypeScript
import { afterAll, beforeAll, mock, test, expect } from "bun:test";
|
|
import type { JSC } from "..";
|
|
import type { InspectorListener } from ".";
|
|
import { WebSocketInspector } from "./websocket";
|
|
import { sleep, spawn } from "bun";
|
|
|
|
let inspectee: any;
|
|
let url: string;
|
|
|
|
beforeAll(async () => {
|
|
const { pathname } = new URL("fixtures/inspectee.js", import.meta.url);
|
|
inspectee = spawn({
|
|
cmd: [process.argv0, "--inspect", pathname],
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
url = await new Promise(async resolve => {
|
|
for await (const chunk of inspectee.stdout) {
|
|
const text = new TextDecoder().decode(chunk);
|
|
const match = /(wss?:\/\/.*:[0-9]+\/.*)/.exec(text);
|
|
if (!match) {
|
|
continue;
|
|
}
|
|
const [_, url] = match;
|
|
resolve(url);
|
|
}
|
|
});
|
|
});
|
|
|
|
afterAll(() => {
|
|
inspectee?.kill();
|
|
});
|
|
|
|
test(
|
|
"WebSocketInspector",
|
|
async () => {
|
|
const listener: InspectorListener = {
|
|
["Inspector.connected"]: mock((...args) => {
|
|
expect(args).toBeEmpty();
|
|
}),
|
|
["Inspector.disconnected"]: mock((error?: Error) => {
|
|
expect(error).toBeUndefined();
|
|
}),
|
|
["Debugger.scriptParsed"]: mock((event: JSC.Debugger.ScriptParsedEvent) => {
|
|
expect(event).toMatchObject({
|
|
endColumn: expect.any(Number),
|
|
endLine: expect.any(Number),
|
|
isContentScript: expect.any(Boolean),
|
|
module: expect.any(Boolean),
|
|
scriptId: expect.any(String),
|
|
startColumn: expect.any(Number),
|
|
startLine: expect.any(Number),
|
|
url: expect.any(String),
|
|
});
|
|
}),
|
|
};
|
|
const inspector = new WebSocketInspector({
|
|
url,
|
|
listener,
|
|
});
|
|
inspector.start();
|
|
inspector.send("Runtime.enable");
|
|
inspector.send("Debugger.enable");
|
|
//expect(inspector.send("Runtime.enable")).resolves.toBeEmpty();
|
|
//expect(inspector.send("Debugger.enable")).resolves.toBeEmpty();
|
|
expect(inspector.send("Runtime.evaluate", { expression: "1 + 1" })).resolves.toMatchObject({
|
|
result: {
|
|
type: "number",
|
|
value: 2,
|
|
description: "2",
|
|
},
|
|
wasThrown: false,
|
|
});
|
|
expect(listener["Inspector.connected"]).toHaveBeenCalled();
|
|
expect(listener["Debugger.scriptParsed"]).toHaveBeenCalled();
|
|
inspector.close();
|
|
expect(inspector.closed).toBeTrue();
|
|
expect(listener["Inspector.disconnected"]).toHaveBeenCalled();
|
|
},
|
|
{
|
|
timeout: 100000,
|
|
},
|
|
);
|