ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / isomorphic / testServerConnection.js
Source Blame History 225 lines
f7eb47b… lmata 1 "use strict";
f7eb47b… lmata 2 var __create = Object.create;
f7eb47b… lmata 3 var __defProp = Object.defineProperty;
f7eb47b… lmata 4 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
f7eb47b… lmata 5 var __getOwnPropNames = Object.getOwnPropertyNames;
f7eb47b… lmata 6 var __getProtoOf = Object.getPrototypeOf;
f7eb47b… lmata 7 var __hasOwnProp = Object.prototype.hasOwnProperty;
f7eb47b… lmata 8 var __export = (target, all) => {
f7eb47b… lmata 9 for (var name in all)
f7eb47b… lmata 10 __defProp(target, name, { get: all[name], enumerable: true });
f7eb47b… lmata 11 };
f7eb47b… lmata 12 var __copyProps = (to, from, except, desc) => {
f7eb47b… lmata 13 if (from && typeof from === "object" || typeof from === "function") {
f7eb47b… lmata 14 for (let key of __getOwnPropNames(from))
f7eb47b… lmata 15 if (!__hasOwnProp.call(to, key) && key !== except)
f7eb47b… lmata 16 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
f7eb47b… lmata 17 }
f7eb47b… lmata 18 return to;
f7eb47b… lmata 19 };
f7eb47b… lmata 20 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
f7eb47b… lmata 21 // If the importer is in node compatibility mode or this is not an ESM
f7eb47b… lmata 22 // file that has been converted to a CommonJS file using a Babel-
f7eb47b… lmata 23 // compatible transform (i.e. "__esModule" has not been set), then set
f7eb47b… lmata 24 // "default" to the CommonJS "module.exports" for node compatibility.
f7eb47b… lmata 25 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
f7eb47b… lmata 26 mod
f7eb47b… lmata 27 ));
f7eb47b… lmata 28 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
f7eb47b… lmata 29 var testServerConnection_exports = {};
f7eb47b… lmata 30 __export(testServerConnection_exports, {
f7eb47b… lmata 31 TestServerConnection: () => TestServerConnection,
f7eb47b… lmata 32 TestServerConnectionClosedError: () => TestServerConnectionClosedError,
f7eb47b… lmata 33 WebSocketTestServerTransport: () => WebSocketTestServerTransport
f7eb47b… lmata 34 });
f7eb47b… lmata 35 module.exports = __toCommonJS(testServerConnection_exports);
f7eb47b… lmata 36 var events = __toESM(require("./events"));
f7eb47b… lmata 37 class TestServerConnectionClosedError extends Error {
f7eb47b… lmata 38 constructor() {
f7eb47b… lmata 39 super("Test server connection closed");
f7eb47b… lmata 40 }
f7eb47b… lmata 41 }
f7eb47b… lmata 42 class WebSocketTestServerTransport {
f7eb47b… lmata 43 constructor(url) {
f7eb47b… lmata 44 this._ws = new WebSocket(url);
f7eb47b… lmata 45 }
f7eb47b… lmata 46 onmessage(listener) {
f7eb47b… lmata 47 this._ws.addEventListener("message", (event) => listener(event.data.toString()));
f7eb47b… lmata 48 }
f7eb47b… lmata 49 onopen(listener) {
f7eb47b… lmata 50 this._ws.addEventListener("open", listener);
f7eb47b… lmata 51 }
f7eb47b… lmata 52 onerror(listener) {
f7eb47b… lmata 53 this._ws.addEventListener("error", listener);
f7eb47b… lmata 54 }
f7eb47b… lmata 55 onclose(listener) {
f7eb47b… lmata 56 this._ws.addEventListener("close", listener);
f7eb47b… lmata 57 }
f7eb47b… lmata 58 send(data) {
f7eb47b… lmata 59 this._ws.send(data);
f7eb47b… lmata 60 }
f7eb47b… lmata 61 close() {
f7eb47b… lmata 62 this._ws.close();
f7eb47b… lmata 63 }
f7eb47b… lmata 64 }
f7eb47b… lmata 65 class TestServerConnection {
f7eb47b… lmata 66 constructor(transport) {
f7eb47b… lmata 67 this._onCloseEmitter = new events.EventEmitter();
f7eb47b… lmata 68 this._onReportEmitter = new events.EventEmitter();
f7eb47b… lmata 69 this._onStdioEmitter = new events.EventEmitter();
f7eb47b… lmata 70 this._onTestFilesChangedEmitter = new events.EventEmitter();
f7eb47b… lmata 71 this._onLoadTraceRequestedEmitter = new events.EventEmitter();
f7eb47b… lmata 72 this._onTestPausedEmitter = new events.EventEmitter();
f7eb47b… lmata 73 this._lastId = 0;
f7eb47b… lmata 74 this._callbacks = /* @__PURE__ */ new Map();
f7eb47b… lmata 75 this._isClosed = false;
f7eb47b… lmata 76 this.onClose = this._onCloseEmitter.event;
f7eb47b… lmata 77 this.onReport = this._onReportEmitter.event;
f7eb47b… lmata 78 this.onStdio = this._onStdioEmitter.event;
f7eb47b… lmata 79 this.onTestFilesChanged = this._onTestFilesChangedEmitter.event;
f7eb47b… lmata 80 this.onLoadTraceRequested = this._onLoadTraceRequestedEmitter.event;
f7eb47b… lmata 81 this.onTestPaused = this._onTestPausedEmitter.event;
f7eb47b… lmata 82 this._transport = transport;
f7eb47b… lmata 83 this._transport.onmessage((data) => {
f7eb47b… lmata 84 const message = JSON.parse(data);
f7eb47b… lmata 85 const { id, result, error, method, params } = message;
f7eb47b… lmata 86 if (id) {
f7eb47b… lmata 87 const callback = this._callbacks.get(id);
f7eb47b… lmata 88 if (!callback)
f7eb47b… lmata 89 return;
f7eb47b… lmata 90 this._callbacks.delete(id);
f7eb47b… lmata 91 if (error)
f7eb47b… lmata 92 callback.reject(new Error(error));
f7eb47b… lmata 93 else
f7eb47b… lmata 94 callback.resolve(result);
f7eb47b… lmata 95 } else {
f7eb47b… lmata 96 this._dispatchEvent(method, params);
f7eb47b… lmata 97 }
f7eb47b… lmata 98 });
f7eb47b… lmata 99 const pingInterval = setInterval(() => this._sendMessage("ping").catch(() => {
f7eb47b… lmata 100 }), 3e4);
f7eb47b… lmata 101 this._connectedPromise = new Promise((f, r) => {
f7eb47b… lmata 102 this._transport.onopen(f);
f7eb47b… lmata 103 this._transport.onerror(r);
f7eb47b… lmata 104 });
f7eb47b… lmata 105 this._transport.onclose(() => {
f7eb47b… lmata 106 this._isClosed = true;
f7eb47b… lmata 107 this._onCloseEmitter.fire();
f7eb47b… lmata 108 clearInterval(pingInterval);
f7eb47b… lmata 109 for (const callback of this._callbacks.values())
f7eb47b… lmata 110 callback.reject(new TestServerConnectionClosedError());
f7eb47b… lmata 111 this._callbacks.clear();
f7eb47b… lmata 112 });
f7eb47b… lmata 113 }
f7eb47b… lmata 114 isClosed() {
f7eb47b… lmata 115 return this._isClosed;
f7eb47b… lmata 116 }
f7eb47b… lmata 117 async _sendMessage(method, params) {
f7eb47b… lmata 118 const logForTest = globalThis.__logForTest;
f7eb47b… lmata 119 logForTest?.({ method, params });
f7eb47b… lmata 120 await this._connectedPromise;
f7eb47b… lmata 121 const id = ++this._lastId;
f7eb47b… lmata 122 const message = { id, method, params };
f7eb47b… lmata 123 this._transport.send(JSON.stringify(message));
f7eb47b… lmata 124 return new Promise((resolve, reject) => {
f7eb47b… lmata 125 this._callbacks.set(id, { resolve, reject });
f7eb47b… lmata 126 });
f7eb47b… lmata 127 }
f7eb47b… lmata 128 _sendMessageNoReply(method, params) {
f7eb47b… lmata 129 this._sendMessage(method, params).catch(() => {
f7eb47b… lmata 130 });
f7eb47b… lmata 131 }
f7eb47b… lmata 132 _dispatchEvent(method, params) {
f7eb47b… lmata 133 if (method === "report")
f7eb47b… lmata 134 this._onReportEmitter.fire(params);
f7eb47b… lmata 135 else if (method === "stdio")
f7eb47b… lmata 136 this._onStdioEmitter.fire(params);
f7eb47b… lmata 137 else if (method === "testFilesChanged")
f7eb47b… lmata 138 this._onTestFilesChangedEmitter.fire(params);
f7eb47b… lmata 139 else if (method === "loadTraceRequested")
f7eb47b… lmata 140 this._onLoadTraceRequestedEmitter.fire(params);
f7eb47b… lmata 141 else if (method === "testPaused")
f7eb47b… lmata 142 this._onTestPausedEmitter.fire(params);
f7eb47b… lmata 143 }
f7eb47b… lmata 144 async initialize(params) {
f7eb47b… lmata 145 await this._sendMessage("initialize", params);
f7eb47b… lmata 146 }
f7eb47b… lmata 147 async ping(params) {
f7eb47b… lmata 148 await this._sendMessage("ping", params);
f7eb47b… lmata 149 }
f7eb47b… lmata 150 async pingNoReply(params) {
f7eb47b… lmata 151 this._sendMessageNoReply("ping", params);
f7eb47b… lmata 152 }
f7eb47b… lmata 153 async watch(params) {
f7eb47b… lmata 154 await this._sendMessage("watch", params);
f7eb47b… lmata 155 }
f7eb47b… lmata 156 watchNoReply(params) {
f7eb47b… lmata 157 this._sendMessageNoReply("watch", params);
f7eb47b… lmata 158 }
f7eb47b… lmata 159 async open(params) {
f7eb47b… lmata 160 await this._sendMessage("open", params);
f7eb47b… lmata 161 }
f7eb47b… lmata 162 openNoReply(params) {
f7eb47b… lmata 163 this._sendMessageNoReply("open", params);
f7eb47b… lmata 164 }
f7eb47b… lmata 165 async resizeTerminal(params) {
f7eb47b… lmata 166 await this._sendMessage("resizeTerminal", params);
f7eb47b… lmata 167 }
f7eb47b… lmata 168 resizeTerminalNoReply(params) {
f7eb47b… lmata 169 this._sendMessageNoReply("resizeTerminal", params);
f7eb47b… lmata 170 }
f7eb47b… lmata 171 async checkBrowsers(params) {
f7eb47b… lmata 172 return await this._sendMessage("checkBrowsers", params);
f7eb47b… lmata 173 }
f7eb47b… lmata 174 async installBrowsers(params) {
f7eb47b… lmata 175 await this._sendMessage("installBrowsers", params);
f7eb47b… lmata 176 }
f7eb47b… lmata 177 async runGlobalSetup(params) {
f7eb47b… lmata 178 return await this._sendMessage("runGlobalSetup", params);
f7eb47b… lmata 179 }
f7eb47b… lmata 180 async runGlobalTeardown(params) {
f7eb47b… lmata 181 return await this._sendMessage("runGlobalTeardown", params);
f7eb47b… lmata 182 }
f7eb47b… lmata 183 async startDevServer(params) {
f7eb47b… lmata 184 return await this._sendMessage("startDevServer", params);
f7eb47b… lmata 185 }
f7eb47b… lmata 186 async stopDevServer(params) {
f7eb47b… lmata 187 return await this._sendMessage("stopDevServer", params);
f7eb47b… lmata 188 }
f7eb47b… lmata 189 async clearCache(params) {
f7eb47b… lmata 190 return await this._sendMessage("clearCache", params);
f7eb47b… lmata 191 }
f7eb47b… lmata 192 async listFiles(params) {
f7eb47b… lmata 193 return await this._sendMessage("listFiles", params);
f7eb47b… lmata 194 }
f7eb47b… lmata 195 async listTests(params) {
f7eb47b… lmata 196 return await this._sendMessage("listTests", params);
f7eb47b… lmata 197 }
f7eb47b… lmata 198 async runTests(params) {
f7eb47b… lmata 199 return await this._sendMessage("runTests", params);
f7eb47b… lmata 200 }
f7eb47b… lmata 201 async findRelatedTestFiles(params) {
f7eb47b… lmata 202 return await this._sendMessage("findRelatedTestFiles", params);
f7eb47b… lmata 203 }
f7eb47b… lmata 204 async stopTests(params) {
f7eb47b… lmata 205 await this._sendMessage("stopTests", params);
f7eb47b… lmata 206 }
f7eb47b… lmata 207 stopTestsNoReply(params) {
f7eb47b… lmata 208 this._sendMessageNoReply("stopTests", params);
f7eb47b… lmata 209 }
f7eb47b… lmata 210 async closeGracefully(params) {
f7eb47b… lmata 211 await this._sendMessage("closeGracefully", params);
f7eb47b… lmata 212 }
f7eb47b… lmata 213 close() {
f7eb47b… lmata 214 try {
f7eb47b… lmata 215 this._transport.close();
f7eb47b… lmata 216 } catch {
f7eb47b… lmata 217 }
f7eb47b… lmata 218 }
f7eb47b… lmata 219 }
f7eb47b… lmata 220 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 221 0 && (module.exports = {
f7eb47b… lmata 222 TestServerConnection,
f7eb47b… lmata 223 TestServerConnectionClosedError,
f7eb47b… lmata 224 WebSocketTestServerTransport
f7eb47b… lmata 225 });

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button