From 39008587ffd87a1e5ba3b776c6842c07101f3218 Mon Sep 17 00:00:00 2001 From: ConnorQi01 Date: Tue, 23 Jun 2026 11:29:24 +0800 Subject: [PATCH] Add ScriptImporter URL unit tests --- test/debugger/scriptImporter.test.ts | 62 ++++++++++++++++++++++++++++ test/index.ts | 1 + 2 files changed, 63 insertions(+) create mode 100644 test/debugger/scriptImporter.test.ts diff --git a/test/debugger/scriptImporter.test.ts b/test/debugger/scriptImporter.test.ts new file mode 100644 index 000000000..8d304721b --- /dev/null +++ b/test/debugger/scriptImporter.test.ts @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +import assert = require("assert"); +import { ScriptImporter } from "../../src/debugger/scriptImporter"; + +suite("scriptImporter", function () { + let scriptImporter: ScriptImporter; + + setup(function () { + scriptImporter = new ScriptImporter("localhost", 8081, "sources"); + }); + + suite("prepareDebuggerWorkerURL", function () { + test("returns the legacy worker URL for RN versions before 0.50", function () { + assert.strictEqual( + scriptImporter.prepareDebuggerWorkerURL("0.49.0"), + "http://localhost:8081/debuggerWorker.js", + ); + }); + + test("returns the debugger UI worker URL for RN 0.50 and later", function () { + assert.strictEqual( + scriptImporter.prepareDebuggerWorkerURL("0.50.0"), + "http://localhost:8081/debugger-ui/debuggerWorker.js", + ); + }); + + test("returns the debugger UI worker URL for canary RN versions", function () { + assert.strictEqual( + scriptImporter.prepareDebuggerWorkerURL("0.0.0"), + "http://localhost:8081/debugger-ui/debuggerWorker.js", + ); + }); + + test("uses the explicit debugger worker URL path when provided", function () { + assert.strictEqual( + scriptImporter.prepareDebuggerWorkerURL("0.55.4", ""), + "http://localhost:8081/debuggerWorker.js", + ); + assert.strictEqual( + scriptImporter.prepareDebuggerWorkerURL("0.55.4", "new-debugger/"), + "http://localhost:8081/new-debugger/debuggerWorker.js", + ); + assert.strictEqual( + scriptImporter.prepareDebuggerWorkerURL("0.49.0", "debugger-ui/"), + "http://localhost:8081/debugger-ui/debuggerWorker.js", + ); + }); + }); + + suite("overridePackagerPort", function () { + test("replaces localhost URL port without changing query string", function () { + assert.strictEqual( + (scriptImporter).overridePackagerPort( + "http://localhost:19000/index.bundle?platform=ios&dev=true&minify=false", + ), + "http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false", + ); + }); + }); +}); diff --git a/test/index.ts b/test/index.ts index 3153a772d..8c87c2a51 100644 --- a/test/index.ts +++ b/test/index.ts @@ -116,6 +116,7 @@ export async function run(): Promise { // Exclude smoke test bundle and localization driver; only run unit/integration tests here return Promise.all([ + getTestFiles("debugger/scriptImporter.test.js", testsRoot), getTestFiles("extension/**/*.test.js", testsRoot), getTestFiles("cdp-proxy/**/*.test.js", testsRoot), ])