poolBuilder.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var poolBuilder_exports = {};
  20. __export(poolBuilder_exports, {
  21. PoolBuilder: () => PoolBuilder
  22. });
  23. module.exports = __toCommonJS(poolBuilder_exports);
  24. var import_fixtures = require("./fixtures");
  25. var import_util = require("../util");
  26. class PoolBuilder {
  27. constructor(type, project) {
  28. this._testTypePools = /* @__PURE__ */ new Map();
  29. this._type = type;
  30. this._project = project;
  31. }
  32. static createForLoader() {
  33. return new PoolBuilder("loader");
  34. }
  35. static createForWorker(project) {
  36. return new PoolBuilder("worker", project);
  37. }
  38. buildPools(suite, testErrors) {
  39. suite.forEachTest((test) => {
  40. const pool = this._buildPoolForTest(test, testErrors);
  41. if (this._type === "loader")
  42. test._poolDigest = pool.digest;
  43. if (this._type === "worker")
  44. test._pool = pool;
  45. });
  46. }
  47. _buildPoolForTest(test, testErrors) {
  48. let pool = this._buildTestTypePool(test._testType, testErrors);
  49. const parents = [];
  50. for (let parent = test.parent; parent; parent = parent.parent)
  51. parents.push(parent);
  52. parents.reverse();
  53. for (const parent of parents) {
  54. if (parent._use.length)
  55. pool = new import_fixtures.FixturePool(parent._use, (e) => this._handleLoadError(e, testErrors), pool, parent._type === "describe");
  56. for (const hook of parent._hooks)
  57. pool.validateFunction(hook.fn, hook.type + " hook", hook.location);
  58. for (const modifier of parent._modifiers)
  59. pool.validateFunction(modifier.fn, modifier.type + " modifier", modifier.location);
  60. }
  61. pool.validateFunction(test.fn, "Test", test.location);
  62. return pool;
  63. }
  64. _buildTestTypePool(testType, testErrors) {
  65. if (!this._testTypePools.has(testType)) {
  66. const optionOverrides = {
  67. overrides: this._project?.project?.use ?? {},
  68. location: { file: `project#${this._project?.id}`, line: 1, column: 1 }
  69. };
  70. const pool = new import_fixtures.FixturePool(testType.fixtures, (e) => this._handleLoadError(e, testErrors), void 0, void 0, optionOverrides);
  71. this._testTypePools.set(testType, pool);
  72. }
  73. return this._testTypePools.get(testType);
  74. }
  75. _handleLoadError(e, testErrors) {
  76. if (testErrors)
  77. testErrors.push(e);
  78. else
  79. throw new Error(`${(0, import_util.formatLocation)(e.location)}: ${e.message}`);
  80. }
  81. }
  82. // Annotate the CommonJS export names for ESM import in node:
  83. 0 && (module.exports = {
  84. PoolBuilder
  85. });