workerHost.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.WorkerHost = void 0;
  6. var _fs = _interopRequireDefault(require("fs"));
  7. var _path = _interopRequireDefault(require("path"));
  8. var _ipc = require("../common/ipc");
  9. var _processHost = require("./processHost");
  10. var _folders = require("../isomorphic/folders");
  11. var _utils = require("playwright-core/lib/utils");
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. /**
  14. * Copyright Microsoft Corporation. All rights reserved.
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the "License");
  17. * you may not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * http://www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an "AS IS" BASIS,
  24. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. let lastWorkerIndex = 0;
  29. class WorkerHost extends _processHost.ProcessHost {
  30. constructor(testGroup, parallelIndex, config, extraEnv, outputDir) {
  31. const workerIndex = lastWorkerIndex++;
  32. super(require.resolve('../worker/workerMain.js'), `worker-${workerIndex}`, {
  33. ...extraEnv,
  34. FORCE_COLOR: '1',
  35. DEBUG_COLORS: '1'
  36. });
  37. this.parallelIndex = void 0;
  38. this.workerIndex = void 0;
  39. this._hash = void 0;
  40. this._params = void 0;
  41. this._didFail = false;
  42. this.workerIndex = workerIndex;
  43. this.parallelIndex = parallelIndex;
  44. this._hash = testGroup.workerHash;
  45. this._params = {
  46. workerIndex: this.workerIndex,
  47. parallelIndex,
  48. repeatEachIndex: testGroup.repeatEachIndex,
  49. projectId: testGroup.projectId,
  50. config,
  51. artifactsDir: _path.default.join(outputDir, (0, _folders.artifactsFolderName)(workerIndex))
  52. };
  53. }
  54. async start() {
  55. await _fs.default.promises.mkdir(this._params.artifactsDir, {
  56. recursive: true
  57. });
  58. return await this.startRunner(this._params, {
  59. onStdOut: chunk => this.emit('stdOut', (0, _ipc.stdioChunkToParams)(chunk)),
  60. onStdErr: chunk => this.emit('stdErr', (0, _ipc.stdioChunkToParams)(chunk))
  61. });
  62. }
  63. async onExit() {
  64. await (0, _utils.removeFolders)([this._params.artifactsDir]);
  65. }
  66. async stop(didFail) {
  67. if (didFail) this._didFail = true;
  68. await super.stop();
  69. }
  70. runTestGroup(runPayload) {
  71. this.sendMessageNoReply({
  72. method: 'runTestGroup',
  73. params: runPayload
  74. });
  75. }
  76. hash() {
  77. return this._hash;
  78. }
  79. didFail() {
  80. return this._didFail;
  81. }
  82. }
  83. exports.WorkerHost = WorkerHost;