workerHost.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. "use strict";
  2. var __create = Object.create;
  3. var __defProp = Object.defineProperty;
  4. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5. var __getOwnPropNames = Object.getOwnPropertyNames;
  6. var __getProtoOf = Object.getPrototypeOf;
  7. var __hasOwnProp = Object.prototype.hasOwnProperty;
  8. var __export = (target, all) => {
  9. for (var name in all)
  10. __defProp(target, name, { get: all[name], enumerable: true });
  11. };
  12. var __copyProps = (to, from, except, desc) => {
  13. if (from && typeof from === "object" || typeof from === "function") {
  14. for (let key of __getOwnPropNames(from))
  15. if (!__hasOwnProp.call(to, key) && key !== except)
  16. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  17. }
  18. return to;
  19. };
  20. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  21. // If the importer is in node compatibility mode or this is not an ESM
  22. // file that has been converted to a CommonJS file using a Babel-
  23. // compatible transform (i.e. "__esModule" has not been set), then set
  24. // "default" to the CommonJS "module.exports" for node compatibility.
  25. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  26. mod
  27. ));
  28. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  29. var workerHost_exports = {};
  30. __export(workerHost_exports, {
  31. WorkerHost: () => WorkerHost
  32. });
  33. module.exports = __toCommonJS(workerHost_exports);
  34. var import_fs = __toESM(require("fs"));
  35. var import_path = __toESM(require("path"));
  36. var import_utils = require("playwright-core/lib/utils");
  37. var import_processHost = require("./processHost");
  38. var import_ipc = require("../common/ipc");
  39. var import_folders = require("../isomorphic/folders");
  40. let lastWorkerIndex = 0;
  41. class WorkerHost extends import_processHost.ProcessHost {
  42. constructor(testGroup, options) {
  43. const workerIndex = lastWorkerIndex++;
  44. super(require.resolve("../worker/workerMain.js"), `worker-${workerIndex}`, {
  45. ...options.extraEnv,
  46. FORCE_COLOR: "1",
  47. DEBUG_COLORS: process.env.DEBUG_COLORS === void 0 ? "1" : process.env.DEBUG_COLORS
  48. });
  49. this._didFail = false;
  50. this.workerIndex = workerIndex;
  51. this.parallelIndex = options.parallelIndex;
  52. this._hash = testGroup.workerHash;
  53. this._params = {
  54. workerIndex: this.workerIndex,
  55. parallelIndex: options.parallelIndex,
  56. repeatEachIndex: testGroup.repeatEachIndex,
  57. projectId: testGroup.projectId,
  58. config: options.config,
  59. artifactsDir: import_path.default.join(options.outputDir, (0, import_folders.artifactsFolderName)(workerIndex)),
  60. pauseOnError: options.pauseOnError,
  61. pauseAtEnd: options.pauseAtEnd
  62. };
  63. }
  64. async start() {
  65. await import_fs.default.promises.mkdir(this._params.artifactsDir, { recursive: true });
  66. return await this.startRunner(this._params, {
  67. onStdOut: (chunk) => this.emit("stdOut", (0, import_ipc.stdioChunkToParams)(chunk)),
  68. onStdErr: (chunk) => this.emit("stdErr", (0, import_ipc.stdioChunkToParams)(chunk))
  69. });
  70. }
  71. async onExit() {
  72. await (0, import_utils.removeFolders)([this._params.artifactsDir]);
  73. }
  74. async stop(didFail) {
  75. if (didFail)
  76. this._didFail = true;
  77. await super.stop();
  78. }
  79. runTestGroup(runPayload) {
  80. this.sendMessageNoReply({ method: "runTestGroup", params: runPayload });
  81. }
  82. async sendCustomMessage(payload) {
  83. return await this.sendMessage({ method: "customMessage", params: payload });
  84. }
  85. hash() {
  86. return this._hash;
  87. }
  88. projectId() {
  89. return this._params.projectId;
  90. }
  91. didFail() {
  92. return this._didFail;
  93. }
  94. }
  95. // Annotate the CommonJS export names for ESM import in node:
  96. 0 && (module.exports = {
  97. WorkerHost
  98. });