workerHost.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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, parallelIndex, config, recoverFromStepErrors, extraEnv, outputDir) {
  43. const workerIndex = lastWorkerIndex++;
  44. super(require.resolve("../worker/workerMain.js"), `worker-${workerIndex}`, {
  45. ...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 = parallelIndex;
  52. this._hash = testGroup.workerHash;
  53. this._params = {
  54. workerIndex: this.workerIndex,
  55. parallelIndex,
  56. repeatEachIndex: testGroup.repeatEachIndex,
  57. projectId: testGroup.projectId,
  58. config,
  59. artifactsDir: import_path.default.join(outputDir, (0, import_folders.artifactsFolderName)(workerIndex)),
  60. recoverFromStepErrors
  61. };
  62. }
  63. async start() {
  64. await import_fs.default.promises.mkdir(this._params.artifactsDir, { recursive: true });
  65. return await this.startRunner(this._params, {
  66. onStdOut: (chunk) => this.emit("stdOut", (0, import_ipc.stdioChunkToParams)(chunk)),
  67. onStdErr: (chunk) => this.emit("stdErr", (0, import_ipc.stdioChunkToParams)(chunk))
  68. });
  69. }
  70. async onExit() {
  71. await (0, import_utils.removeFolders)([this._params.artifactsDir]);
  72. }
  73. async stop(didFail) {
  74. if (didFail)
  75. this._didFail = true;
  76. await super.stop();
  77. }
  78. runTestGroup(runPayload) {
  79. this.sendMessageNoReply({ method: "runTestGroup", params: runPayload });
  80. }
  81. resumeAfterStepError(result) {
  82. this.sendMessageNoReply({ method: "resumeAfterStepError", params: result });
  83. }
  84. hash() {
  85. return this._hash;
  86. }
  87. projectId() {
  88. return this._params.projectId;
  89. }
  90. didFail() {
  91. return this._didFail;
  92. }
  93. }
  94. // Annotate the CommonJS export names for ESM import in node:
  95. 0 && (module.exports = {
  96. WorkerHost
  97. });