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