ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / runner / testServer.js
Source Blame History 269 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 testServer_exports = {};
f7eb47b… lmata 30 __export(testServer_exports, {
f7eb47b… lmata 31 TestServerDispatcher: () => TestServerDispatcher,
f7eb47b… lmata 32 runTestServer: () => runTestServer,
f7eb47b… lmata 33 runUIMode: () => runUIMode
f7eb47b… lmata 34 });
f7eb47b… lmata 35 module.exports = __toCommonJS(testServer_exports);
f7eb47b… lmata 36 var import_util = __toESM(require("util"));
f7eb47b… lmata 37 var import_server = require("playwright-core/lib/server");
f7eb47b… lmata 38 var import_utils = require("playwright-core/lib/utils");
f7eb47b… lmata 39 var import_utilsBundle = require("playwright-core/lib/utilsBundle");
f7eb47b… lmata 40 var import_configLoader = require("../common/configLoader");
f7eb47b… lmata 41 var import_list = __toESM(require("../reporters/list"));
f7eb47b… lmata 42 var import_reporters = require("./reporters");
f7eb47b… lmata 43 var import_sigIntWatcher = require("./sigIntWatcher");
f7eb47b… lmata 44 var import_testRunner = require("./testRunner");
f7eb47b… lmata 45 const originalDebugLog = import_utilsBundle.debug.log;
f7eb47b… lmata 46 const originalStdoutWrite = process.stdout.write;
f7eb47b… lmata 47 const originalStderrWrite = process.stderr.write;
f7eb47b… lmata 48 const originalStdinIsTTY = process.stdin.isTTY;
f7eb47b… lmata 49 class TestServer {
f7eb47b… lmata 50 constructor(configLocation, configCLIOverrides) {
f7eb47b… lmata 51 this._configLocation = configLocation;
f7eb47b… lmata 52 this._configCLIOverrides = configCLIOverrides;
f7eb47b… lmata 53 }
f7eb47b… lmata 54 async start(options) {
f7eb47b… lmata 55 this._dispatcher = new TestServerDispatcher(this._configLocation, this._configCLIOverrides);
f7eb47b… lmata 56 return await (0, import_server.startTraceViewerServer)({ ...options, transport: this._dispatcher.transport });
f7eb47b… lmata 57 }
f7eb47b… lmata 58 async stop() {
f7eb47b… lmata 59 await this._dispatcher?.stop();
f7eb47b… lmata 60 }
f7eb47b… lmata 61 }
f7eb47b… lmata 62 class TestServerDispatcher {
f7eb47b… lmata 63 constructor(configLocation, configCLIOverrides) {
f7eb47b… lmata 64 this._serializer = require.resolve("./uiModeReporter");
f7eb47b… lmata 65 this._closeOnDisconnect = false;
f7eb47b… lmata 66 this._testRunner = new import_testRunner.TestRunner(configLocation, configCLIOverrides);
f7eb47b… lmata 67 this.transport = {
f7eb47b… lmata 68 onconnect: () => {
f7eb47b… lmata 69 },
f7eb47b… lmata 70 dispatch: (method, params) => this[method](params),
f7eb47b… lmata 71 onclose: () => {
f7eb47b… lmata 72 if (this._closeOnDisconnect)
f7eb47b… lmata 73 (0, import_utils.gracefullyProcessExitDoNotHang)(0);
f7eb47b… lmata 74 }
f7eb47b… lmata 75 };
f7eb47b… lmata 76 this._dispatchEvent = (method, params) => this.transport.sendEvent?.(method, params);
f7eb47b… lmata 77 this._testRunner.on(import_testRunner.TestRunnerEvent.TestFilesChanged, (testFiles) => this._dispatchEvent("testFilesChanged", { testFiles }));
f7eb47b… lmata 78 this._testRunner.on(import_testRunner.TestRunnerEvent.TestPaused, (params) => this._dispatchEvent("testPaused", { errors: params.errors }));
f7eb47b… lmata 79 }
f7eb47b… lmata 80 async _wireReporter(messageSink) {
f7eb47b… lmata 81 return await (0, import_reporters.createReporterForTestServer)(this._serializer, messageSink);
f7eb47b… lmata 82 }
f7eb47b… lmata 83 async _collectingReporter() {
f7eb47b… lmata 84 const report = [];
f7eb47b… lmata 85 return {
f7eb47b… lmata 86 reporter: await (0, import_reporters.createReporterForTestServer)(this._serializer, (e) => report.push(e)),
f7eb47b… lmata 87 report
f7eb47b… lmata 88 };
f7eb47b… lmata 89 }
f7eb47b… lmata 90 async initialize(params) {
f7eb47b… lmata 91 this._serializer = params.serializer || require.resolve("./uiModeReporter");
f7eb47b… lmata 92 this._closeOnDisconnect = !!params.closeOnDisconnect;
f7eb47b… lmata 93 await this._testRunner.initialize({
f7eb47b… lmata 94 ...params
f7eb47b… lmata 95 });
f7eb47b… lmata 96 this._setInterceptStdio(!!params.interceptStdio);
f7eb47b… lmata 97 }
f7eb47b… lmata 98 async ping() {
f7eb47b… lmata 99 }
f7eb47b… lmata 100 async open(params) {
f7eb47b… lmata 101 if ((0, import_utils.isUnderTest)())
f7eb47b… lmata 102 return;
f7eb47b… lmata 103 (0, import_utilsBundle.open)("vscode://file/" + params.location.file + ":" + params.location.line).catch((e) => console.error(e));
f7eb47b… lmata 104 }
f7eb47b… lmata 105 async resizeTerminal(params) {
f7eb47b… lmata 106 this._testRunner.resizeTerminal(params);
f7eb47b… lmata 107 }
f7eb47b… lmata 108 async checkBrowsers() {
f7eb47b… lmata 109 return { hasBrowsers: this._testRunner.hasSomeBrowsers() };
f7eb47b… lmata 110 }
f7eb47b… lmata 111 async installBrowsers() {
f7eb47b… lmata 112 await this._testRunner.installBrowsers();
f7eb47b… lmata 113 }
f7eb47b… lmata 114 async runGlobalSetup(params) {
f7eb47b… lmata 115 const { reporter, report } = await this._collectingReporter();
f7eb47b… lmata 116 this._globalSetupReport = report;
f7eb47b… lmata 117 const { status, env } = await this._testRunner.runGlobalSetup([reporter, new import_list.default()]);
f7eb47b… lmata 118 return { report, status, env };
f7eb47b… lmata 119 }
f7eb47b… lmata 120 async runGlobalTeardown() {
f7eb47b… lmata 121 const { status } = await this._testRunner.runGlobalTeardown();
f7eb47b… lmata 122 const report = this._globalSetupReport || [];
f7eb47b… lmata 123 this._globalSetupReport = void 0;
f7eb47b… lmata 124 return { status, report };
f7eb47b… lmata 125 }
f7eb47b… lmata 126 async startDevServer(params) {
f7eb47b… lmata 127 await this.stopDevServer({});
f7eb47b… lmata 128 const { reporter, report } = await this._collectingReporter();
f7eb47b… lmata 129 const { status } = await this._testRunner.startDevServer(reporter, "out-of-process");
f7eb47b… lmata 130 return { report, status };
f7eb47b… lmata 131 }
f7eb47b… lmata 132 async stopDevServer(params) {
f7eb47b… lmata 133 const { status } = await this._testRunner.stopDevServer();
f7eb47b… lmata 134 const report = this._devServerReport || [];
f7eb47b… lmata 135 this._devServerReport = void 0;
f7eb47b… lmata 136 return { status, report };
f7eb47b… lmata 137 }
f7eb47b… lmata 138 async clearCache(params) {
f7eb47b… lmata 139 await this._testRunner.clearCache();
f7eb47b… lmata 140 }
f7eb47b… lmata 141 async listFiles(params) {
f7eb47b… lmata 142 const { reporter, report } = await this._collectingReporter();
f7eb47b… lmata 143 const { status } = await this._testRunner.listFiles(reporter, params.projects);
f7eb47b… lmata 144 return { report, status };
f7eb47b… lmata 145 }
f7eb47b… lmata 146 async listTests(params) {
f7eb47b… lmata 147 const { reporter, report } = await this._collectingReporter();
f7eb47b… lmata 148 const { status } = await this._testRunner.listTests(reporter, params);
f7eb47b… lmata 149 return { report, status };
f7eb47b… lmata 150 }
f7eb47b… lmata 151 async runTests(params) {
f7eb47b… lmata 152 const wireReporter = await this._wireReporter((e) => this._dispatchEvent("report", e));
f7eb47b… lmata 153 const { status } = await this._testRunner.runTests(wireReporter, {
f7eb47b… lmata 154 ...params,
f7eb47b… lmata 155 doNotRunDepsOutsideProjectFilter: true,
f7eb47b… lmata 156 pauseAtEnd: params.pauseAtEnd,
f7eb47b… lmata 157 pauseOnError: params.pauseOnError
f7eb47b… lmata 158 });
f7eb47b… lmata 159 return { status };
f7eb47b… lmata 160 }
f7eb47b… lmata 161 async watch(params) {
f7eb47b… lmata 162 await this._testRunner.watch(params.fileNames);
f7eb47b… lmata 163 }
f7eb47b… lmata 164 async findRelatedTestFiles(params) {
f7eb47b… lmata 165 return this._testRunner.findRelatedTestFiles(params.files);
f7eb47b… lmata 166 }
f7eb47b… lmata 167 async stopTests() {
f7eb47b… lmata 168 await this._testRunner.stopTests();
f7eb47b… lmata 169 }
f7eb47b… lmata 170 async stop() {
f7eb47b… lmata 171 this._setInterceptStdio(false);
f7eb47b… lmata 172 await this._testRunner.stop();
f7eb47b… lmata 173 }
f7eb47b… lmata 174 async closeGracefully() {
f7eb47b… lmata 175 await this._testRunner.closeGracefully();
f7eb47b… lmata 176 }
f7eb47b… lmata 177 _setInterceptStdio(interceptStdio) {
f7eb47b… lmata 178 if (process.env.PWTEST_DEBUG)
f7eb47b… lmata 179 return;
f7eb47b… lmata 180 if (interceptStdio) {
f7eb47b… lmata 181 if (import_utilsBundle.debug.log === originalDebugLog) {
f7eb47b… lmata 182 import_utilsBundle.debug.log = (...args) => {
f7eb47b… lmata 183 const string = import_util.default.format(...args) + "\n";
f7eb47b… lmata 184 return originalStderrWrite.apply(process.stderr, [string]);
f7eb47b… lmata 185 };
f7eb47b… lmata 186 }
f7eb47b… lmata 187 const stdoutWrite = (chunk) => {
f7eb47b… lmata 188 this._dispatchEvent("stdio", chunkToPayload("stdout", chunk));
f7eb47b… lmata 189 return true;
f7eb47b… lmata 190 };
f7eb47b… lmata 191 const stderrWrite = (chunk) => {
f7eb47b… lmata 192 this._dispatchEvent("stdio", chunkToPayload("stderr", chunk));
f7eb47b… lmata 193 return true;
f7eb47b… lmata 194 };
f7eb47b… lmata 195 process.stdout.write = stdoutWrite;
f7eb47b… lmata 196 process.stderr.write = stderrWrite;
f7eb47b… lmata 197 process.stdin.isTTY = void 0;
f7eb47b… lmata 198 } else {
f7eb47b… lmata 199 import_utilsBundle.debug.log = originalDebugLog;
f7eb47b… lmata 200 process.stdout.write = originalStdoutWrite;
f7eb47b… lmata 201 process.stderr.write = originalStderrWrite;
f7eb47b… lmata 202 process.stdin.isTTY = originalStdinIsTTY;
f7eb47b… lmata 203 }
f7eb47b… lmata 204 }
f7eb47b… lmata 205 }
f7eb47b… lmata 206 async function runUIMode(configFile, configCLIOverrides, options) {
f7eb47b… lmata 207 const configLocation = (0, import_configLoader.resolveConfigLocation)(configFile);
f7eb47b… lmata 208 return await innerRunTestServer(configLocation, configCLIOverrides, options, async (server, cancelPromise) => {
f7eb47b… lmata 209 await (0, import_server.installRootRedirect)(server, void 0, { ...options, webApp: "uiMode.html" });
f7eb47b… lmata 210 if (options.host !== void 0 || options.port !== void 0) {
f7eb47b… lmata 211 await (0, import_server.openTraceInBrowser)(server.urlPrefix("human-readable"));
f7eb47b… lmata 212 } else {
f7eb47b… lmata 213 const channel = await installedChromiumChannelForUI(configLocation, configCLIOverrides);
f7eb47b… lmata 214 const page = await (0, import_server.openTraceViewerApp)(server.urlPrefix("precise"), "chromium", {
f7eb47b… lmata 215 headless: (0, import_utils.isUnderTest)() && process.env.PWTEST_HEADED_FOR_TEST !== "1",
f7eb47b… lmata 216 persistentContextOptions: {
f7eb47b… lmata 217 handleSIGINT: false,
f7eb47b… lmata 218 channel
f7eb47b… lmata 219 }
f7eb47b… lmata 220 });
f7eb47b… lmata 221 page.on("close", () => cancelPromise.resolve());
f7eb47b… lmata 222 }
f7eb47b… lmata 223 });
f7eb47b… lmata 224 }
f7eb47b… lmata 225 async function installedChromiumChannelForUI(configLocation, configCLIOverrides) {
f7eb47b… lmata 226 const config = await (0, import_configLoader.loadConfig)(configLocation, configCLIOverrides).catch((e) => null);
f7eb47b… lmata 227 if (!config)
f7eb47b… lmata 228 return void 0;
f7eb47b… lmata 229 if (config.projects.some((p) => (!p.project.use.browserName || p.project.use.browserName === "chromium") && !p.project.use.channel))
f7eb47b… lmata 230 return void 0;
f7eb47b… lmata 231 for (const channel of ["chromium", "chrome", "msedge"]) {
f7eb47b… lmata 232 if (config.projects.some((p) => p.project.use.channel === channel))
f7eb47b… lmata 233 return channel;
f7eb47b… lmata 234 }
f7eb47b… lmata 235 return void 0;
f7eb47b… lmata 236 }
f7eb47b… lmata 237 async function runTestServer(configFile, configCLIOverrides, options) {
f7eb47b… lmata 238 const configLocation = (0, import_configLoader.resolveConfigLocation)(configFile);
f7eb47b… lmata 239 return await innerRunTestServer(configLocation, configCLIOverrides, options, async (server) => {
f7eb47b… lmata 240 console.log("Listening on " + server.urlPrefix("precise").replace("http:", "ws:") + "/" + server.wsGuid());
f7eb47b… lmata 241 });
f7eb47b… lmata 242 }
f7eb47b… lmata 243 async function innerRunTestServer(configLocation, configCLIOverrides, options, openUI) {
f7eb47b… lmata 244 const testServer = new TestServer(configLocation, configCLIOverrides);
f7eb47b… lmata 245 const cancelPromise = new import_utils.ManualPromise();
f7eb47b… lmata 246 const sigintWatcher = new import_sigIntWatcher.SigIntWatcher();
f7eb47b… lmata 247 process.stdin.on("close", () => (0, import_utils.gracefullyProcessExitDoNotHang)(0));
f7eb47b… lmata 248 void sigintWatcher.promise().then(() => cancelPromise.resolve());
f7eb47b… lmata 249 try {
f7eb47b… lmata 250 const server = await testServer.start(options);
f7eb47b… lmata 251 await openUI(server, cancelPromise);
f7eb47b… lmata 252 await cancelPromise;
f7eb47b… lmata 253 } finally {
f7eb47b… lmata 254 await testServer.stop();
f7eb47b… lmata 255 sigintWatcher.disarm();
f7eb47b… lmata 256 }
f7eb47b… lmata 257 return sigintWatcher.hadSignal() ? "interrupted" : "passed";
f7eb47b… lmata 258 }
f7eb47b… lmata 259 function chunkToPayload(type, chunk) {
f7eb47b… lmata 260 if (chunk instanceof Uint8Array)
f7eb47b… lmata 261 return { type, buffer: chunk.toString("base64") };
f7eb47b… lmata 262 return { type, text: chunk };
f7eb47b… lmata 263 }
f7eb47b… lmata 264 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 265 0 && (module.exports = {
f7eb47b… lmata 266 TestServerDispatcher,
f7eb47b… lmata 267 runTestServer,
f7eb47b… lmata 268 runUIMode
f7eb47b… lmata 269 });

Keyboard Shortcuts

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