|
f7eb47b…
|
lmata
|
1 |
"use strict"; |
|
f7eb47b…
|
lmata
|
2 |
var __defProp = Object.defineProperty; |
|
f7eb47b…
|
lmata
|
3 |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
|
f7eb47b…
|
lmata
|
4 |
var __getOwnPropNames = Object.getOwnPropertyNames; |
|
f7eb47b…
|
lmata
|
5 |
var __hasOwnProp = Object.prototype.hasOwnProperty; |
|
f7eb47b…
|
lmata
|
6 |
var __export = (target, all) => { |
|
f7eb47b…
|
lmata
|
7 |
for (var name in all) |
|
f7eb47b…
|
lmata
|
8 |
__defProp(target, name, { get: all[name], enumerable: true }); |
|
f7eb47b…
|
lmata
|
9 |
}; |
|
f7eb47b…
|
lmata
|
10 |
var __copyProps = (to, from, except, desc) => { |
|
f7eb47b…
|
lmata
|
11 |
if (from && typeof from === "object" || typeof from === "function") { |
|
f7eb47b…
|
lmata
|
12 |
for (let key of __getOwnPropNames(from)) |
|
f7eb47b…
|
lmata
|
13 |
if (!__hasOwnProp.call(to, key) && key !== except) |
|
f7eb47b…
|
lmata
|
14 |
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
|
f7eb47b…
|
lmata
|
15 |
} |
|
f7eb47b…
|
lmata
|
16 |
return to; |
|
f7eb47b…
|
lmata
|
17 |
}; |
|
f7eb47b…
|
lmata
|
18 |
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); |
|
f7eb47b…
|
lmata
|
19 |
var testGroups_exports = {}; |
|
f7eb47b…
|
lmata
|
20 |
__export(testGroups_exports, { |
|
f7eb47b…
|
lmata
|
21 |
createTestGroups: () => createTestGroups, |
|
f7eb47b…
|
lmata
|
22 |
filterForShard: () => filterForShard |
|
f7eb47b…
|
lmata
|
23 |
}); |
|
f7eb47b…
|
lmata
|
24 |
module.exports = __toCommonJS(testGroups_exports); |
|
f7eb47b…
|
lmata
|
25 |
function createTestGroups(projectSuite, expectedParallelism) { |
|
f7eb47b…
|
lmata
|
26 |
const groups = /* @__PURE__ */ new Map(); |
|
f7eb47b…
|
lmata
|
27 |
const createGroup = (test) => { |
|
f7eb47b…
|
lmata
|
28 |
return { |
|
f7eb47b…
|
lmata
|
29 |
workerHash: test._workerHash, |
|
f7eb47b…
|
lmata
|
30 |
requireFile: test._requireFile, |
|
f7eb47b…
|
lmata
|
31 |
repeatEachIndex: test.repeatEachIndex, |
|
f7eb47b…
|
lmata
|
32 |
projectId: test._projectId, |
|
f7eb47b…
|
lmata
|
33 |
tests: [] |
|
f7eb47b…
|
lmata
|
34 |
}; |
|
f7eb47b…
|
lmata
|
35 |
}; |
|
f7eb47b…
|
lmata
|
36 |
for (const test of projectSuite.allTests()) { |
|
f7eb47b…
|
lmata
|
37 |
let withWorkerHash = groups.get(test._workerHash); |
|
f7eb47b…
|
lmata
|
38 |
if (!withWorkerHash) { |
|
f7eb47b…
|
lmata
|
39 |
withWorkerHash = /* @__PURE__ */ new Map(); |
|
f7eb47b…
|
lmata
|
40 |
groups.set(test._workerHash, withWorkerHash); |
|
f7eb47b…
|
lmata
|
41 |
} |
|
f7eb47b…
|
lmata
|
42 |
let withRequireFile = withWorkerHash.get(test._requireFile); |
|
f7eb47b…
|
lmata
|
43 |
if (!withRequireFile) { |
|
f7eb47b…
|
lmata
|
44 |
withRequireFile = { |
|
f7eb47b…
|
lmata
|
45 |
general: createGroup(test), |
|
f7eb47b…
|
lmata
|
46 |
parallel: /* @__PURE__ */ new Map(), |
|
f7eb47b…
|
lmata
|
47 |
parallelWithHooks: createGroup(test) |
|
f7eb47b…
|
lmata
|
48 |
}; |
|
f7eb47b…
|
lmata
|
49 |
withWorkerHash.set(test._requireFile, withRequireFile); |
|
f7eb47b…
|
lmata
|
50 |
} |
|
f7eb47b…
|
lmata
|
51 |
let insideParallel = false; |
|
f7eb47b…
|
lmata
|
52 |
let outerMostSequentialSuite; |
|
f7eb47b…
|
lmata
|
53 |
let hasAllHooks = false; |
|
f7eb47b…
|
lmata
|
54 |
for (let parent = test.parent; parent; parent = parent.parent) { |
|
f7eb47b…
|
lmata
|
55 |
if (parent._parallelMode === "serial" || parent._parallelMode === "default") |
|
f7eb47b…
|
lmata
|
56 |
outerMostSequentialSuite = parent; |
|
f7eb47b…
|
lmata
|
57 |
insideParallel = insideParallel || parent._parallelMode === "parallel"; |
|
f7eb47b…
|
lmata
|
58 |
hasAllHooks = hasAllHooks || parent._hooks.some((hook) => hook.type === "beforeAll" || hook.type === "afterAll"); |
|
f7eb47b…
|
lmata
|
59 |
} |
|
f7eb47b…
|
lmata
|
60 |
if (insideParallel) { |
|
f7eb47b…
|
lmata
|
61 |
if (hasAllHooks && !outerMostSequentialSuite) { |
|
f7eb47b…
|
lmata
|
62 |
withRequireFile.parallelWithHooks.tests.push(test); |
|
f7eb47b…
|
lmata
|
63 |
} else { |
|
f7eb47b…
|
lmata
|
64 |
const key = outerMostSequentialSuite || test; |
|
f7eb47b…
|
lmata
|
65 |
let group = withRequireFile.parallel.get(key); |
|
f7eb47b…
|
lmata
|
66 |
if (!group) { |
|
f7eb47b…
|
lmata
|
67 |
group = createGroup(test); |
|
f7eb47b…
|
lmata
|
68 |
withRequireFile.parallel.set(key, group); |
|
f7eb47b…
|
lmata
|
69 |
} |
|
f7eb47b…
|
lmata
|
70 |
group.tests.push(test); |
|
f7eb47b…
|
lmata
|
71 |
} |
|
f7eb47b…
|
lmata
|
72 |
} else { |
|
f7eb47b…
|
lmata
|
73 |
withRequireFile.general.tests.push(test); |
|
f7eb47b…
|
lmata
|
74 |
} |
|
f7eb47b…
|
lmata
|
75 |
} |
|
f7eb47b…
|
lmata
|
76 |
const result = []; |
|
f7eb47b…
|
lmata
|
77 |
for (const withWorkerHash of groups.values()) { |
|
f7eb47b…
|
lmata
|
78 |
for (const withRequireFile of withWorkerHash.values()) { |
|
f7eb47b…
|
lmata
|
79 |
if (withRequireFile.general.tests.length) |
|
f7eb47b…
|
lmata
|
80 |
result.push(withRequireFile.general); |
|
f7eb47b…
|
lmata
|
81 |
result.push(...withRequireFile.parallel.values()); |
|
f7eb47b…
|
lmata
|
82 |
const parallelWithHooksGroupSize = Math.ceil(withRequireFile.parallelWithHooks.tests.length / expectedParallelism); |
|
f7eb47b…
|
lmata
|
83 |
let lastGroup; |
|
f7eb47b…
|
lmata
|
84 |
for (const test of withRequireFile.parallelWithHooks.tests) { |
|
f7eb47b…
|
lmata
|
85 |
if (!lastGroup || lastGroup.tests.length >= parallelWithHooksGroupSize) { |
|
f7eb47b…
|
lmata
|
86 |
lastGroup = createGroup(test); |
|
f7eb47b…
|
lmata
|
87 |
result.push(lastGroup); |
|
f7eb47b…
|
lmata
|
88 |
} |
|
f7eb47b…
|
lmata
|
89 |
lastGroup.tests.push(test); |
|
f7eb47b…
|
lmata
|
90 |
} |
|
f7eb47b…
|
lmata
|
91 |
} |
|
f7eb47b…
|
lmata
|
92 |
} |
|
f7eb47b…
|
lmata
|
93 |
return result; |
|
f7eb47b…
|
lmata
|
94 |
} |
|
f7eb47b…
|
lmata
|
95 |
function filterForShard(shard, weights, testGroups) { |
|
f7eb47b…
|
lmata
|
96 |
weights ??= Array.from({ length: shard.total }, () => 1); |
|
f7eb47b…
|
lmata
|
97 |
if (weights.length !== shard.total) |
|
f7eb47b…
|
lmata
|
98 |
throw new Error(`PWTEST_SHARD_WEIGHTS number of weights must match the shard total of ${shard.total}`); |
|
f7eb47b…
|
lmata
|
99 |
const totalWeight = weights.reduce((a, b) => a + b, 0); |
|
f7eb47b…
|
lmata
|
100 |
let shardableTotal = 0; |
|
f7eb47b…
|
lmata
|
101 |
for (const group of testGroups) |
|
f7eb47b…
|
lmata
|
102 |
shardableTotal += group.tests.length; |
|
f7eb47b…
|
lmata
|
103 |
const shardSizes = weights.map((w) => Math.floor(w * shardableTotal / totalWeight)); |
|
f7eb47b…
|
lmata
|
104 |
const remainder = shardableTotal - shardSizes.reduce((a, b) => a + b, 0); |
|
f7eb47b…
|
lmata
|
105 |
for (let i = 0; i < remainder; i++) { |
|
f7eb47b…
|
lmata
|
106 |
shardSizes[i % shardSizes.length]++; |
|
f7eb47b…
|
lmata
|
107 |
} |
|
f7eb47b…
|
lmata
|
108 |
let from = 0; |
|
f7eb47b…
|
lmata
|
109 |
for (let i = 0; i < shard.current - 1; i++) |
|
f7eb47b…
|
lmata
|
110 |
from += shardSizes[i]; |
|
f7eb47b…
|
lmata
|
111 |
const to = from + shardSizes[shard.current - 1]; |
|
f7eb47b…
|
lmata
|
112 |
let current = 0; |
|
f7eb47b…
|
lmata
|
113 |
const result = /* @__PURE__ */ new Set(); |
|
f7eb47b…
|
lmata
|
114 |
for (const group of testGroups) { |
|
f7eb47b…
|
lmata
|
115 |
if (current >= from && current < to) |
|
f7eb47b…
|
lmata
|
116 |
result.add(group); |
|
f7eb47b…
|
lmata
|
117 |
current += group.tests.length; |
|
f7eb47b…
|
lmata
|
118 |
} |
|
f7eb47b…
|
lmata
|
119 |
return result; |
|
f7eb47b…
|
lmata
|
120 |
} |
|
f7eb47b…
|
lmata
|
121 |
// Annotate the CommonJS export names for ESM import in node: |
|
f7eb47b…
|
lmata
|
122 |
0 && (module.exports = { |
|
f7eb47b…
|
lmata
|
123 |
createTestGroups, |
|
f7eb47b…
|
lmata
|
124 |
filterForShard |
|
f7eb47b…
|
lmata
|
125 |
}); |