@ohos-ports/playwright 1.52.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +168 -0
- package/ThirdPartyNotices.txt +4011 -0
- package/cli.js +19 -0
- package/index.d.ts +17 -0
- package/index.js +17 -0
- package/index.mjs +18 -0
- package/jsx-runtime.js +42 -0
- package/jsx-runtime.mjs +21 -0
- package/lib/common/config.js +272 -0
- package/lib/common/configLoader.js +373 -0
- package/lib/common/esmLoaderHost.js +100 -0
- package/lib/common/expectBundle.js +49 -0
- package/lib/common/expectBundleImpl.js +389 -0
- package/lib/common/fixtures.js +302 -0
- package/lib/common/globals.js +58 -0
- package/lib/common/ipc.js +60 -0
- package/lib/common/poolBuilder.js +85 -0
- package/lib/common/process.js +109 -0
- package/lib/common/suiteUtils.js +149 -0
- package/lib/common/test.js +313 -0
- package/lib/common/testLoader.js +100 -0
- package/lib/common/testType.js +306 -0
- package/lib/errorContext.js +149 -0
- package/lib/fsWatcher.js +67 -0
- package/lib/index.js +692 -0
- package/lib/internalsForTest.js +42 -0
- package/lib/isomorphic/events.js +77 -0
- package/lib/isomorphic/folders.js +30 -0
- package/lib/isomorphic/stringInternPool.js +69 -0
- package/lib/isomorphic/teleReceiver.js +484 -0
- package/lib/isomorphic/teleSuiteUpdater.js +137 -0
- package/lib/isomorphic/testServerConnection.js +211 -0
- package/lib/isomorphic/testServerInterface.js +16 -0
- package/lib/isomorphic/testTree.js +307 -0
- package/lib/isomorphic/types.d.js +16 -0
- package/lib/isomorphic/util.js +28 -0
- package/lib/loader/loaderMain.js +59 -0
- package/lib/matchers/expect.js +322 -0
- package/lib/matchers/matcherHint.js +59 -0
- package/lib/matchers/matchers.js +362 -0
- package/lib/matchers/toBeTruthy.js +71 -0
- package/lib/matchers/toEqual.js +94 -0
- package/lib/matchers/toHaveURL.js +117 -0
- package/lib/matchers/toMatchAriaSnapshot.js +180 -0
- package/lib/matchers/toMatchSnapshot.js +365 -0
- package/lib/matchers/toMatchText.js +105 -0
- package/lib/plugins/gitCommitInfoPlugin.js +198 -0
- package/lib/plugins/index.js +28 -0
- package/lib/plugins/webServerPlugin.js +207 -0
- package/lib/program.js +407 -0
- package/lib/reporters/base.js +540 -0
- package/lib/reporters/blob.js +135 -0
- package/lib/reporters/dot.js +82 -0
- package/lib/reporters/empty.js +32 -0
- package/lib/reporters/github.js +127 -0
- package/lib/reporters/html.js +579 -0
- package/lib/reporters/internalReporter.js +129 -0
- package/lib/reporters/json.js +254 -0
- package/lib/reporters/junit.js +230 -0
- package/lib/reporters/line.js +113 -0
- package/lib/reporters/list.js +228 -0
- package/lib/reporters/merge.js +511 -0
- package/lib/reporters/multiplexer.js +104 -0
- package/lib/reporters/reporterV2.js +102 -0
- package/lib/reporters/teleEmitter.js +269 -0
- package/lib/reporters/versions/blobV1.js +16 -0
- package/lib/runner/dispatcher.js +484 -0
- package/lib/runner/failureTracker.js +62 -0
- package/lib/runner/lastRun.js +74 -0
- package/lib/runner/loadUtils.js +299 -0
- package/lib/runner/loaderHost.js +89 -0
- package/lib/runner/processHost.js +165 -0
- package/lib/runner/projectUtils.js +235 -0
- package/lib/runner/rebase.js +189 -0
- package/lib/runner/reporters.js +162 -0
- package/lib/runner/runner.js +110 -0
- package/lib/runner/sigIntWatcher.js +96 -0
- package/lib/runner/taskRunner.js +127 -0
- package/lib/runner/tasks.js +400 -0
- package/lib/runner/testGroups.js +117 -0
- package/lib/runner/testServer.js +477 -0
- package/lib/runner/uiModeReporter.js +30 -0
- package/lib/runner/vcs.js +72 -0
- package/lib/runner/watchMode.js +394 -0
- package/lib/runner/workerHost.js +93 -0
- package/lib/third_party/tsconfig-loader.js +103 -0
- package/lib/transform/babelBundle.js +43 -0
- package/lib/transform/babelBundleImpl.js +477 -0
- package/lib/transform/compilationCache.js +255 -0
- package/lib/transform/esmLoader.js +104 -0
- package/lib/transform/esmUtils.js +53 -0
- package/lib/transform/portTransport.js +66 -0
- package/lib/transform/transform.js +291 -0
- package/lib/util.js +407 -0
- package/lib/utilsBundle.js +46 -0
- package/lib/utilsBundleImpl.js +102 -0
- package/lib/worker/fixtureRunner.js +253 -0
- package/lib/worker/testInfo.js +422 -0
- package/lib/worker/testTracing.js +351 -0
- package/lib/worker/timeoutManager.js +174 -0
- package/lib/worker/util.js +31 -0
- package/lib/worker/workerMain.js +511 -0
- package/package.json +64 -0
- package/test.d.ts +18 -0
- package/test.js +24 -0
- package/test.mjs +33 -0
- package/types/test.d.ts +10061 -0
- package/types/testReporter.d.ts +799 -0
|
@@ -0,0 +1,253 @@
|
|
|
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 fixtureRunner_exports = {};
|
|
20
|
+
__export(fixtureRunner_exports, {
|
|
21
|
+
FixtureRunner: () => FixtureRunner
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(fixtureRunner_exports);
|
|
24
|
+
var import_utils = require("@ohos-ports/playwright-core/lib/utils");
|
|
25
|
+
var import_fixtures = require("../common/fixtures");
|
|
26
|
+
var import_util = require("../util");
|
|
27
|
+
class Fixture {
|
|
28
|
+
constructor(runner, registration) {
|
|
29
|
+
this.failed = false;
|
|
30
|
+
this._deps = /* @__PURE__ */ new Set();
|
|
31
|
+
this._usages = /* @__PURE__ */ new Set();
|
|
32
|
+
this.runner = runner;
|
|
33
|
+
this.registration = registration;
|
|
34
|
+
this.value = null;
|
|
35
|
+
const shouldGenerateStep = !this.registration.box && !this.registration.option;
|
|
36
|
+
const isUserFixture = this.registration.location && (0, import_util.filterStackFile)(this.registration.location.file);
|
|
37
|
+
const title = this.registration.customTitle || this.registration.name;
|
|
38
|
+
const location = isUserFixture ? this.registration.location : void 0;
|
|
39
|
+
this._stepInfo = shouldGenerateStep ? { title: `fixture: ${title}`, category: "fixture", location } : void 0;
|
|
40
|
+
this._setupDescription = {
|
|
41
|
+
title,
|
|
42
|
+
phase: "setup",
|
|
43
|
+
location,
|
|
44
|
+
slot: this.registration.timeout === void 0 ? void 0 : {
|
|
45
|
+
timeout: this.registration.timeout,
|
|
46
|
+
elapsed: 0
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
this._teardownDescription = { ...this._setupDescription, phase: "teardown" };
|
|
50
|
+
}
|
|
51
|
+
async setup(testInfo, runnable) {
|
|
52
|
+
this.runner.instanceForId.set(this.registration.id, this);
|
|
53
|
+
if (typeof this.registration.fn !== "function") {
|
|
54
|
+
this.value = this.registration.fn;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const run = () => testInfo._runWithTimeout({ ...runnable, fixture: this._setupDescription }, () => this._setupInternal(testInfo));
|
|
58
|
+
if (this._stepInfo)
|
|
59
|
+
await testInfo._runAsStep(this._stepInfo, run);
|
|
60
|
+
else
|
|
61
|
+
await run();
|
|
62
|
+
}
|
|
63
|
+
async _setupInternal(testInfo) {
|
|
64
|
+
const params = {};
|
|
65
|
+
for (const name of this.registration.deps) {
|
|
66
|
+
const registration = this.runner.pool.resolve(name, this.registration);
|
|
67
|
+
const dep = this.runner.instanceForId.get(registration.id);
|
|
68
|
+
if (!dep) {
|
|
69
|
+
this.failed = true;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
dep._usages.add(this);
|
|
73
|
+
this._deps.add(dep);
|
|
74
|
+
params[name] = dep.value;
|
|
75
|
+
if (dep.failed) {
|
|
76
|
+
this.failed = true;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
let called = false;
|
|
81
|
+
const useFuncStarted = new import_utils.ManualPromise();
|
|
82
|
+
const useFunc = async (value) => {
|
|
83
|
+
if (called)
|
|
84
|
+
throw new Error(`Cannot provide fixture value for the second time`);
|
|
85
|
+
called = true;
|
|
86
|
+
this.value = value;
|
|
87
|
+
this._useFuncFinished = new import_utils.ManualPromise();
|
|
88
|
+
useFuncStarted.resolve();
|
|
89
|
+
await this._useFuncFinished;
|
|
90
|
+
};
|
|
91
|
+
const workerInfo = { config: testInfo.config, parallelIndex: testInfo.parallelIndex, workerIndex: testInfo.workerIndex, project: testInfo.project };
|
|
92
|
+
const info = this.registration.scope === "worker" ? workerInfo : testInfo;
|
|
93
|
+
this._selfTeardownComplete = (async () => {
|
|
94
|
+
try {
|
|
95
|
+
await this.registration.fn(params, useFunc, info);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
this.failed = true;
|
|
98
|
+
if (!useFuncStarted.isDone())
|
|
99
|
+
useFuncStarted.reject(error);
|
|
100
|
+
else
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
})();
|
|
104
|
+
await useFuncStarted;
|
|
105
|
+
}
|
|
106
|
+
async teardown(testInfo, runnable) {
|
|
107
|
+
try {
|
|
108
|
+
const fixtureRunnable = { ...runnable, fixture: this._teardownDescription };
|
|
109
|
+
if (!testInfo._timeoutManager.isTimeExhaustedFor(fixtureRunnable)) {
|
|
110
|
+
const run = () => testInfo._runWithTimeout(fixtureRunnable, () => this._teardownInternal());
|
|
111
|
+
if (this._stepInfo)
|
|
112
|
+
await testInfo._runAsStep(this._stepInfo, run);
|
|
113
|
+
else
|
|
114
|
+
await run();
|
|
115
|
+
}
|
|
116
|
+
} finally {
|
|
117
|
+
for (const dep of this._deps)
|
|
118
|
+
dep._usages.delete(this);
|
|
119
|
+
this.runner.instanceForId.delete(this.registration.id);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async _teardownInternal() {
|
|
123
|
+
if (typeof this.registration.fn !== "function")
|
|
124
|
+
return;
|
|
125
|
+
if (this._usages.size !== 0) {
|
|
126
|
+
console.error("Internal error: fixture integrity at", this._teardownDescription.title);
|
|
127
|
+
this._usages.clear();
|
|
128
|
+
}
|
|
129
|
+
if (this._useFuncFinished) {
|
|
130
|
+
this._useFuncFinished.resolve();
|
|
131
|
+
this._useFuncFinished = void 0;
|
|
132
|
+
await this._selfTeardownComplete;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
_collectFixturesInTeardownOrder(scope, collector) {
|
|
136
|
+
if (this.registration.scope !== scope)
|
|
137
|
+
return;
|
|
138
|
+
for (const fixture of this._usages)
|
|
139
|
+
fixture._collectFixturesInTeardownOrder(scope, collector);
|
|
140
|
+
collector.add(this);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
class FixtureRunner {
|
|
144
|
+
constructor() {
|
|
145
|
+
this.testScopeClean = true;
|
|
146
|
+
this.instanceForId = /* @__PURE__ */ new Map();
|
|
147
|
+
}
|
|
148
|
+
setPool(pool) {
|
|
149
|
+
if (!this.testScopeClean)
|
|
150
|
+
throw new Error("Did not teardown test scope");
|
|
151
|
+
if (this.pool && pool.digest !== this.pool.digest) {
|
|
152
|
+
throw new Error([
|
|
153
|
+
`Playwright detected inconsistent test.use() options.`,
|
|
154
|
+
`Most common mistakes that lead to this issue:`,
|
|
155
|
+
` - Calling test.use() outside of the test file, for example in a common helper.`,
|
|
156
|
+
` - One test file imports from another test file.`
|
|
157
|
+
].join("\n"));
|
|
158
|
+
}
|
|
159
|
+
this.pool = pool;
|
|
160
|
+
}
|
|
161
|
+
_collectFixturesInSetupOrder(registration, collector) {
|
|
162
|
+
if (collector.has(registration))
|
|
163
|
+
return;
|
|
164
|
+
for (const name of registration.deps) {
|
|
165
|
+
const dep = this.pool.resolve(name, registration);
|
|
166
|
+
this._collectFixturesInSetupOrder(dep, collector);
|
|
167
|
+
}
|
|
168
|
+
collector.add(registration);
|
|
169
|
+
}
|
|
170
|
+
async teardownScope(scope, testInfo, runnable) {
|
|
171
|
+
const fixtures = Array.from(this.instanceForId.values()).reverse();
|
|
172
|
+
const collector = /* @__PURE__ */ new Set();
|
|
173
|
+
for (const fixture of fixtures)
|
|
174
|
+
fixture._collectFixturesInTeardownOrder(scope, collector);
|
|
175
|
+
let firstError;
|
|
176
|
+
for (const fixture of collector) {
|
|
177
|
+
try {
|
|
178
|
+
await fixture.teardown(testInfo, runnable);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
firstError = firstError ?? error;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (scope === "test")
|
|
184
|
+
this.testScopeClean = true;
|
|
185
|
+
if (firstError)
|
|
186
|
+
throw firstError;
|
|
187
|
+
}
|
|
188
|
+
async resolveParametersForFunction(fn, testInfo, autoFixtures, runnable) {
|
|
189
|
+
const collector = /* @__PURE__ */ new Set();
|
|
190
|
+
const auto = [];
|
|
191
|
+
for (const registration of this.pool.autoFixtures()) {
|
|
192
|
+
let shouldRun = true;
|
|
193
|
+
if (autoFixtures === "all-hooks-only")
|
|
194
|
+
shouldRun = registration.scope === "worker" || registration.auto === "all-hooks-included";
|
|
195
|
+
else if (autoFixtures === "worker")
|
|
196
|
+
shouldRun = registration.scope === "worker";
|
|
197
|
+
if (shouldRun)
|
|
198
|
+
auto.push(registration);
|
|
199
|
+
}
|
|
200
|
+
auto.sort((r1, r2) => (r1.scope === "worker" ? 0 : 1) - (r2.scope === "worker" ? 0 : 1));
|
|
201
|
+
for (const registration of auto)
|
|
202
|
+
this._collectFixturesInSetupOrder(registration, collector);
|
|
203
|
+
const names = getRequiredFixtureNames(fn);
|
|
204
|
+
for (const name of names)
|
|
205
|
+
this._collectFixturesInSetupOrder(this.pool.resolve(name), collector);
|
|
206
|
+
for (const registration of collector)
|
|
207
|
+
await this._setupFixtureForRegistration(registration, testInfo, runnable);
|
|
208
|
+
const params = {};
|
|
209
|
+
for (const name of names) {
|
|
210
|
+
const registration = this.pool.resolve(name);
|
|
211
|
+
const fixture = this.instanceForId.get(registration.id);
|
|
212
|
+
if (!fixture || fixture.failed)
|
|
213
|
+
return null;
|
|
214
|
+
params[name] = fixture.value;
|
|
215
|
+
}
|
|
216
|
+
return params;
|
|
217
|
+
}
|
|
218
|
+
async resolveParametersAndRunFunction(fn, testInfo, autoFixtures, runnable) {
|
|
219
|
+
const params = await this.resolveParametersForFunction(fn, testInfo, autoFixtures, runnable);
|
|
220
|
+
if (params === null) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
await testInfo._runWithTimeout(runnable, () => fn(params, testInfo));
|
|
224
|
+
}
|
|
225
|
+
async _setupFixtureForRegistration(registration, testInfo, runnable) {
|
|
226
|
+
if (registration.scope === "test")
|
|
227
|
+
this.testScopeClean = false;
|
|
228
|
+
let fixture = this.instanceForId.get(registration.id);
|
|
229
|
+
if (fixture)
|
|
230
|
+
return fixture;
|
|
231
|
+
fixture = new Fixture(this, registration);
|
|
232
|
+
await fixture.setup(testInfo, runnable);
|
|
233
|
+
return fixture;
|
|
234
|
+
}
|
|
235
|
+
dependsOnWorkerFixturesOnly(fn, location) {
|
|
236
|
+
const names = getRequiredFixtureNames(fn, location);
|
|
237
|
+
for (const name of names) {
|
|
238
|
+
const registration = this.pool.resolve(name);
|
|
239
|
+
if (registration.scope !== "worker")
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function getRequiredFixtureNames(fn, location) {
|
|
246
|
+
return (0, import_fixtures.fixtureParameterNames)(fn, location ?? { file: "<unknown>", line: 1, column: 1 }, (e) => {
|
|
247
|
+
throw new Error(`${(0, import_util.formatLocation)(e.location)}: ${e.message}`);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
251
|
+
0 && (module.exports = {
|
|
252
|
+
FixtureRunner
|
|
253
|
+
});
|
|
@@ -0,0 +1,422 @@
|
|
|
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 testInfo_exports = {};
|
|
30
|
+
__export(testInfo_exports, {
|
|
31
|
+
StepSkipError: () => StepSkipError,
|
|
32
|
+
TestInfoImpl: () => TestInfoImpl,
|
|
33
|
+
TestSkipError: () => TestSkipError,
|
|
34
|
+
TestStepInfoImpl: () => TestStepInfoImpl
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(testInfo_exports);
|
|
37
|
+
var import_fs = __toESM(require("fs"));
|
|
38
|
+
var import_path = __toESM(require("path"));
|
|
39
|
+
var import_utils = require("@ohos-ports/playwright-core/lib/utils");
|
|
40
|
+
var import_timeoutManager = require("./timeoutManager");
|
|
41
|
+
var import_util = require("../util");
|
|
42
|
+
var import_testTracing = require("./testTracing");
|
|
43
|
+
var import_util2 = require("./util");
|
|
44
|
+
class TestInfoImpl {
|
|
45
|
+
constructor(configInternal, projectInternal, workerParams, test, retry, onStepBegin, onStepEnd, onAttach) {
|
|
46
|
+
this._wasInterrupted = false;
|
|
47
|
+
this._lastStepId = 0;
|
|
48
|
+
this._steps = [];
|
|
49
|
+
this._stepMap = /* @__PURE__ */ new Map();
|
|
50
|
+
this._hasNonRetriableError = false;
|
|
51
|
+
this._hasUnhandledError = false;
|
|
52
|
+
this._allowSkips = false;
|
|
53
|
+
this.duration = 0;
|
|
54
|
+
this.annotations = [];
|
|
55
|
+
this.attachments = [];
|
|
56
|
+
this.status = "passed";
|
|
57
|
+
this.snapshotSuffix = "";
|
|
58
|
+
this.errors = [];
|
|
59
|
+
this.testId = test?.id ?? "";
|
|
60
|
+
this._onStepBegin = onStepBegin;
|
|
61
|
+
this._onStepEnd = onStepEnd;
|
|
62
|
+
this._onAttach = onAttach;
|
|
63
|
+
this._startTime = (0, import_utils.monotonicTime)();
|
|
64
|
+
this._startWallTime = Date.now();
|
|
65
|
+
this._requireFile = test?._requireFile ?? "";
|
|
66
|
+
this._uniqueSymbol = Symbol("testInfoUniqueSymbol");
|
|
67
|
+
this.repeatEachIndex = workerParams.repeatEachIndex;
|
|
68
|
+
this.retry = retry;
|
|
69
|
+
this.workerIndex = workerParams.workerIndex;
|
|
70
|
+
this.parallelIndex = workerParams.parallelIndex;
|
|
71
|
+
this._projectInternal = projectInternal;
|
|
72
|
+
this.project = projectInternal.project;
|
|
73
|
+
this._configInternal = configInternal;
|
|
74
|
+
this.config = configInternal.config;
|
|
75
|
+
this.title = test?.title ?? "";
|
|
76
|
+
this.titlePath = test?.titlePath() ?? [];
|
|
77
|
+
this.file = test?.location.file ?? "";
|
|
78
|
+
this.line = test?.location.line ?? 0;
|
|
79
|
+
this.column = test?.location.column ?? 0;
|
|
80
|
+
this.tags = test?.tags ?? [];
|
|
81
|
+
this.fn = test?.fn ?? (() => {
|
|
82
|
+
});
|
|
83
|
+
this.expectedStatus = test?.expectedStatus ?? "skipped";
|
|
84
|
+
this._timeoutManager = new import_timeoutManager.TimeoutManager(this.project.timeout);
|
|
85
|
+
if (configInternal.configCLIOverrides.debug)
|
|
86
|
+
this._setDebugMode();
|
|
87
|
+
this.outputDir = (() => {
|
|
88
|
+
const relativeTestFilePath = import_path.default.relative(this.project.testDir, this._requireFile.replace(/\.(spec|test)\.(js|ts|jsx|tsx|mjs|mts|cjs|cts)$/, ""));
|
|
89
|
+
const sanitizedRelativePath = relativeTestFilePath.replace(process.platform === "win32" ? new RegExp("\\\\", "g") : new RegExp("/", "g"), "-");
|
|
90
|
+
const fullTitleWithoutSpec = this.titlePath.slice(1).join(" ");
|
|
91
|
+
let testOutputDir = (0, import_util.trimLongString)(sanitizedRelativePath + "-" + (0, import_utils.sanitizeForFilePath)(fullTitleWithoutSpec), import_util.windowsFilesystemFriendlyLength);
|
|
92
|
+
if (projectInternal.id)
|
|
93
|
+
testOutputDir += "-" + (0, import_utils.sanitizeForFilePath)(projectInternal.id);
|
|
94
|
+
if (this.retry)
|
|
95
|
+
testOutputDir += "-retry" + this.retry;
|
|
96
|
+
if (this.repeatEachIndex)
|
|
97
|
+
testOutputDir += "-repeat" + this.repeatEachIndex;
|
|
98
|
+
return import_path.default.join(this.project.outputDir, testOutputDir);
|
|
99
|
+
})();
|
|
100
|
+
this.snapshotDir = (() => {
|
|
101
|
+
const relativeTestFilePath = import_path.default.relative(this.project.testDir, this._requireFile);
|
|
102
|
+
return import_path.default.join(this.project.snapshotDir, relativeTestFilePath + "-snapshots");
|
|
103
|
+
})();
|
|
104
|
+
this._attachmentsPush = this.attachments.push.bind(this.attachments);
|
|
105
|
+
this.attachments.push = (...attachments) => {
|
|
106
|
+
for (const a of attachments)
|
|
107
|
+
this._attach(a, this._parentStep()?.stepId);
|
|
108
|
+
return this.attachments.length;
|
|
109
|
+
};
|
|
110
|
+
this._tracing = new import_testTracing.TestTracing(this, workerParams.artifactsDir);
|
|
111
|
+
}
|
|
112
|
+
get error() {
|
|
113
|
+
return this.errors[0];
|
|
114
|
+
}
|
|
115
|
+
set error(e) {
|
|
116
|
+
if (e === void 0)
|
|
117
|
+
throw new Error("Cannot assign testInfo.error undefined value!");
|
|
118
|
+
this.errors[0] = e;
|
|
119
|
+
}
|
|
120
|
+
get timeout() {
|
|
121
|
+
return this._timeoutManager.defaultSlot().timeout;
|
|
122
|
+
}
|
|
123
|
+
set timeout(timeout) {
|
|
124
|
+
}
|
|
125
|
+
_deadlineForMatcher(timeout) {
|
|
126
|
+
const startTime = (0, import_utils.monotonicTime)();
|
|
127
|
+
const matcherDeadline = timeout ? startTime + timeout : import_timeoutManager.kMaxDeadline;
|
|
128
|
+
const testDeadline = this._timeoutManager.currentSlotDeadline() - 250;
|
|
129
|
+
const matcherMessage = `Timeout ${timeout}ms exceeded while waiting on the predicate`;
|
|
130
|
+
const testMessage = `Test timeout of ${this.timeout}ms exceeded`;
|
|
131
|
+
return { deadline: Math.min(testDeadline, matcherDeadline), timeoutMessage: testDeadline < matcherDeadline ? testMessage : matcherMessage };
|
|
132
|
+
}
|
|
133
|
+
static _defaultDeadlineForMatcher(timeout) {
|
|
134
|
+
return { deadline: timeout ? (0, import_utils.monotonicTime)() + timeout : 0, timeoutMessage: `Timeout ${timeout}ms exceeded while waiting on the predicate` };
|
|
135
|
+
}
|
|
136
|
+
_modifier(type, modifierArgs) {
|
|
137
|
+
if (typeof modifierArgs[1] === "function") {
|
|
138
|
+
throw new Error([
|
|
139
|
+
"It looks like you are calling test.skip() inside the test and pass a callback.",
|
|
140
|
+
"Pass a condition instead and optional description instead:",
|
|
141
|
+
`test('my test', async ({ page, isMobile }) => {`,
|
|
142
|
+
` test.skip(isMobile, 'This test is not applicable on mobile');`,
|
|
143
|
+
`});`
|
|
144
|
+
].join("\n"));
|
|
145
|
+
}
|
|
146
|
+
if (modifierArgs.length >= 1 && !modifierArgs[0])
|
|
147
|
+
return;
|
|
148
|
+
const description = modifierArgs[1];
|
|
149
|
+
this.annotations.push({ type, description });
|
|
150
|
+
if (type === "slow") {
|
|
151
|
+
this._timeoutManager.slow();
|
|
152
|
+
} else if (type === "skip" || type === "fixme") {
|
|
153
|
+
this.expectedStatus = "skipped";
|
|
154
|
+
throw new TestSkipError("Test is skipped: " + (description || ""));
|
|
155
|
+
} else if (type === "fail") {
|
|
156
|
+
if (this.expectedStatus !== "skipped")
|
|
157
|
+
this.expectedStatus = "failed";
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
_findLastPredefinedStep(steps) {
|
|
161
|
+
for (let i = steps.length - 1; i >= 0; i--) {
|
|
162
|
+
const child = this._findLastPredefinedStep(steps[i].steps);
|
|
163
|
+
if (child)
|
|
164
|
+
return child;
|
|
165
|
+
if ((steps[i].category === "hook" || steps[i].category === "fixture") && !steps[i].endWallTime)
|
|
166
|
+
return steps[i];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
_parentStep() {
|
|
170
|
+
return (0, import_utils.currentZone)().data("stepZone") ?? this._findLastPredefinedStep(this._steps);
|
|
171
|
+
}
|
|
172
|
+
_addStep(data, parentStep) {
|
|
173
|
+
const stepId = `${data.category}@${++this._lastStepId}`;
|
|
174
|
+
if (data.category === "hook" || data.category === "fixture") {
|
|
175
|
+
parentStep = this._findLastPredefinedStep(this._steps);
|
|
176
|
+
} else {
|
|
177
|
+
if (!parentStep)
|
|
178
|
+
parentStep = this._parentStep();
|
|
179
|
+
}
|
|
180
|
+
const filteredStack = (0, import_util.filteredStackTrace)((0, import_utils.captureRawStack)());
|
|
181
|
+
data.boxedStack = parentStep?.boxedStack;
|
|
182
|
+
if (!data.boxedStack && data.box) {
|
|
183
|
+
data.boxedStack = filteredStack.slice(1);
|
|
184
|
+
data.location = data.location || data.boxedStack[0];
|
|
185
|
+
}
|
|
186
|
+
data.location = data.location || filteredStack[0];
|
|
187
|
+
const attachmentIndices = [];
|
|
188
|
+
const step = {
|
|
189
|
+
stepId,
|
|
190
|
+
...data,
|
|
191
|
+
steps: [],
|
|
192
|
+
attachmentIndices,
|
|
193
|
+
info: new TestStepInfoImpl(this, stepId),
|
|
194
|
+
complete: (result) => {
|
|
195
|
+
if (step.endWallTime)
|
|
196
|
+
return;
|
|
197
|
+
step.endWallTime = Date.now();
|
|
198
|
+
if (result.error) {
|
|
199
|
+
if (typeof result.error === "object" && !result.error?.[stepSymbol])
|
|
200
|
+
result.error[stepSymbol] = step;
|
|
201
|
+
const error = (0, import_util2.testInfoError)(result.error);
|
|
202
|
+
if (data.boxedStack)
|
|
203
|
+
error.stack = `${error.message}
|
|
204
|
+
${(0, import_utils.stringifyStackFrames)(data.boxedStack).join("\n")}`;
|
|
205
|
+
step.error = error;
|
|
206
|
+
}
|
|
207
|
+
if (!step.error) {
|
|
208
|
+
for (const childStep of step.steps) {
|
|
209
|
+
if (childStep.error && childStep.infectParentStepsWithError) {
|
|
210
|
+
step.error = childStep.error;
|
|
211
|
+
step.infectParentStepsWithError = true;
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const payload2 = {
|
|
217
|
+
testId: this.testId,
|
|
218
|
+
stepId,
|
|
219
|
+
wallTime: step.endWallTime,
|
|
220
|
+
error: step.error,
|
|
221
|
+
suggestedRebaseline: result.suggestedRebaseline,
|
|
222
|
+
annotations: step.info.annotations
|
|
223
|
+
};
|
|
224
|
+
this._onStepEnd(payload2);
|
|
225
|
+
const errorForTrace = step.error ? { name: "", message: step.error.message || "", stack: step.error.stack } : void 0;
|
|
226
|
+
const attachments = attachmentIndices.map((i) => this.attachments[i]);
|
|
227
|
+
this._tracing.appendAfterActionForStep(stepId, errorForTrace, attachments, step.info.annotations);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
const parentStepList = parentStep ? parentStep.steps : this._steps;
|
|
231
|
+
parentStepList.push(step);
|
|
232
|
+
this._stepMap.set(stepId, step);
|
|
233
|
+
const payload = {
|
|
234
|
+
testId: this.testId,
|
|
235
|
+
stepId,
|
|
236
|
+
parentStepId: parentStep ? parentStep.stepId : void 0,
|
|
237
|
+
title: data.title,
|
|
238
|
+
category: data.category,
|
|
239
|
+
wallTime: Date.now(),
|
|
240
|
+
location: data.location
|
|
241
|
+
};
|
|
242
|
+
this._onStepBegin(payload);
|
|
243
|
+
this._tracing.appendBeforeActionForStep(stepId, parentStep?.stepId, data.category, data.apiName || data.title, data.params, data.location ? [data.location] : []);
|
|
244
|
+
return step;
|
|
245
|
+
}
|
|
246
|
+
_interrupt() {
|
|
247
|
+
this._wasInterrupted = true;
|
|
248
|
+
this._timeoutManager.interrupt();
|
|
249
|
+
if (this.status === "passed")
|
|
250
|
+
this.status = "interrupted";
|
|
251
|
+
}
|
|
252
|
+
_failWithError(error) {
|
|
253
|
+
if (this.status === "passed" || this.status === "skipped")
|
|
254
|
+
this.status = error instanceof import_timeoutManager.TimeoutManagerError ? "timedOut" : "failed";
|
|
255
|
+
const serialized = (0, import_util2.testInfoError)(error);
|
|
256
|
+
const step = typeof error === "object" ? error?.[stepSymbol] : void 0;
|
|
257
|
+
if (step && step.boxedStack)
|
|
258
|
+
serialized.stack = `${error.name}: ${error.message}
|
|
259
|
+
${(0, import_utils.stringifyStackFrames)(step.boxedStack).join("\n")}`;
|
|
260
|
+
this.errors.push(serialized);
|
|
261
|
+
this._tracing.appendForError(serialized);
|
|
262
|
+
}
|
|
263
|
+
async _runAsStep(stepInfo, cb) {
|
|
264
|
+
const step = this._addStep(stepInfo);
|
|
265
|
+
try {
|
|
266
|
+
await cb();
|
|
267
|
+
step.complete({});
|
|
268
|
+
} catch (error) {
|
|
269
|
+
step.complete({ error });
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async _runWithTimeout(runnable, cb) {
|
|
274
|
+
try {
|
|
275
|
+
await this._timeoutManager.withRunnable(runnable, async () => {
|
|
276
|
+
try {
|
|
277
|
+
await cb();
|
|
278
|
+
} catch (e) {
|
|
279
|
+
if (this._allowSkips && e instanceof TestSkipError) {
|
|
280
|
+
if (this.status === "passed")
|
|
281
|
+
this.status = "skipped";
|
|
282
|
+
} else {
|
|
283
|
+
this._failWithError(e);
|
|
284
|
+
}
|
|
285
|
+
throw e;
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
} catch (error) {
|
|
289
|
+
if (!this._wasInterrupted && error instanceof import_timeoutManager.TimeoutManagerError)
|
|
290
|
+
this._failWithError(error);
|
|
291
|
+
throw error;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
_isFailure() {
|
|
295
|
+
return this.status !== "skipped" && this.status !== this.expectedStatus;
|
|
296
|
+
}
|
|
297
|
+
_currentHookType() {
|
|
298
|
+
const type = this._timeoutManager.currentSlotType();
|
|
299
|
+
return ["beforeAll", "afterAll", "beforeEach", "afterEach"].includes(type) ? type : void 0;
|
|
300
|
+
}
|
|
301
|
+
_setDebugMode() {
|
|
302
|
+
this._timeoutManager.setIgnoreTimeouts();
|
|
303
|
+
}
|
|
304
|
+
// ------------ TestInfo methods ------------
|
|
305
|
+
async attach(name, options = {}) {
|
|
306
|
+
const step = this._addStep({
|
|
307
|
+
title: `attach "${name}"`,
|
|
308
|
+
category: "attach"
|
|
309
|
+
});
|
|
310
|
+
this._attach(await (0, import_util.normalizeAndSaveAttachment)(this.outputPath(), name, options), step.stepId);
|
|
311
|
+
step.complete({});
|
|
312
|
+
}
|
|
313
|
+
_attach(attachment, stepId) {
|
|
314
|
+
const index = this._attachmentsPush(attachment) - 1;
|
|
315
|
+
if (stepId)
|
|
316
|
+
this._stepMap.get(stepId).attachmentIndices.push(index);
|
|
317
|
+
else
|
|
318
|
+
this._tracing.appendTopLevelAttachment(attachment);
|
|
319
|
+
this._onAttach({
|
|
320
|
+
testId: this.testId,
|
|
321
|
+
name: attachment.name,
|
|
322
|
+
contentType: attachment.contentType,
|
|
323
|
+
path: attachment.path,
|
|
324
|
+
body: attachment.body?.toString("base64"),
|
|
325
|
+
stepId
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
outputPath(...pathSegments) {
|
|
329
|
+
const outputPath = this._getOutputPath(...pathSegments);
|
|
330
|
+
import_fs.default.mkdirSync(this.outputDir, { recursive: true });
|
|
331
|
+
return outputPath;
|
|
332
|
+
}
|
|
333
|
+
_getOutputPath(...pathSegments) {
|
|
334
|
+
const joinedPath = import_path.default.join(...pathSegments);
|
|
335
|
+
const outputPath = (0, import_util.getContainedPath)(this.outputDir, joinedPath);
|
|
336
|
+
if (outputPath)
|
|
337
|
+
return outputPath;
|
|
338
|
+
throw new Error(`The outputPath is not allowed outside of the parent directory. Please fix the defined path.
|
|
339
|
+
|
|
340
|
+
outputPath: ${joinedPath}`);
|
|
341
|
+
}
|
|
342
|
+
_fsSanitizedTestName() {
|
|
343
|
+
const fullTitleWithoutSpec = this.titlePath.slice(1).join(" ");
|
|
344
|
+
return (0, import_utils.sanitizeForFilePath)((0, import_util.trimLongString)(fullTitleWithoutSpec));
|
|
345
|
+
}
|
|
346
|
+
_resolveSnapshotPath(template, defaultTemplate, pathSegments, extension) {
|
|
347
|
+
const subPath = import_path.default.join(...pathSegments);
|
|
348
|
+
const dir = import_path.default.dirname(subPath);
|
|
349
|
+
const ext = extension ?? import_path.default.extname(subPath);
|
|
350
|
+
const name = import_path.default.basename(subPath, ext);
|
|
351
|
+
const relativeTestFilePath = import_path.default.relative(this.project.testDir, this._requireFile);
|
|
352
|
+
const parsedRelativeTestFilePath = import_path.default.parse(relativeTestFilePath);
|
|
353
|
+
const projectNamePathSegment = (0, import_utils.sanitizeForFilePath)(this.project.name);
|
|
354
|
+
const actualTemplate = template || this._projectInternal.snapshotPathTemplate || defaultTemplate;
|
|
355
|
+
const snapshotPath = actualTemplate.replace(/\{(.)?testDir\}/g, "$1" + this.project.testDir).replace(/\{(.)?snapshotDir\}/g, "$1" + this.project.snapshotDir).replace(/\{(.)?snapshotSuffix\}/g, this.snapshotSuffix ? "$1" + this.snapshotSuffix : "").replace(/\{(.)?testFileDir\}/g, "$1" + parsedRelativeTestFilePath.dir).replace(/\{(.)?platform\}/g, "$1" + process.platform).replace(/\{(.)?projectName\}/g, projectNamePathSegment ? "$1" + projectNamePathSegment : "").replace(/\{(.)?testName\}/g, "$1" + this._fsSanitizedTestName()).replace(/\{(.)?testFileName\}/g, "$1" + parsedRelativeTestFilePath.base).replace(/\{(.)?testFilePath\}/g, "$1" + relativeTestFilePath).replace(/\{(.)?arg\}/g, "$1" + import_path.default.join(dir, name)).replace(/\{(.)?ext\}/g, ext ? "$1" + ext : "");
|
|
356
|
+
return import_path.default.normalize(import_path.default.resolve(this._configInternal.configDir, snapshotPath));
|
|
357
|
+
}
|
|
358
|
+
snapshotPath(...pathSegments) {
|
|
359
|
+
const legacyTemplate = "{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}{-snapshotSuffix}{ext}";
|
|
360
|
+
return this._resolveSnapshotPath(void 0, legacyTemplate, pathSegments);
|
|
361
|
+
}
|
|
362
|
+
skip(...args) {
|
|
363
|
+
this._modifier("skip", args);
|
|
364
|
+
}
|
|
365
|
+
fixme(...args) {
|
|
366
|
+
this._modifier("fixme", args);
|
|
367
|
+
}
|
|
368
|
+
fail(...args) {
|
|
369
|
+
this._modifier("fail", args);
|
|
370
|
+
}
|
|
371
|
+
slow(...args) {
|
|
372
|
+
this._modifier("slow", args);
|
|
373
|
+
}
|
|
374
|
+
setTimeout(timeout) {
|
|
375
|
+
this._timeoutManager.setTimeout(timeout);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
class TestStepInfoImpl {
|
|
379
|
+
constructor(testInfo, stepId) {
|
|
380
|
+
this.annotations = [];
|
|
381
|
+
this._testInfo = testInfo;
|
|
382
|
+
this._stepId = stepId;
|
|
383
|
+
}
|
|
384
|
+
async _runStepBody(skip, body) {
|
|
385
|
+
if (skip) {
|
|
386
|
+
this.annotations.push({ type: "skip" });
|
|
387
|
+
return void 0;
|
|
388
|
+
}
|
|
389
|
+
try {
|
|
390
|
+
return await body(this);
|
|
391
|
+
} catch (e) {
|
|
392
|
+
if (e instanceof StepSkipError)
|
|
393
|
+
return void 0;
|
|
394
|
+
throw e;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
_attachToStep(attachment) {
|
|
398
|
+
this._testInfo._attach(attachment, this._stepId);
|
|
399
|
+
}
|
|
400
|
+
async attach(name, options) {
|
|
401
|
+
this._attachToStep(await (0, import_util.normalizeAndSaveAttachment)(this._testInfo.outputPath(), name, options));
|
|
402
|
+
}
|
|
403
|
+
skip(...args) {
|
|
404
|
+
if (args.length > 0 && !args[0])
|
|
405
|
+
return;
|
|
406
|
+
const description = args[1];
|
|
407
|
+
this.annotations.push({ type: "skip", description });
|
|
408
|
+
throw new StepSkipError(description);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
class TestSkipError extends Error {
|
|
412
|
+
}
|
|
413
|
+
class StepSkipError extends Error {
|
|
414
|
+
}
|
|
415
|
+
const stepSymbol = Symbol("step");
|
|
416
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
417
|
+
0 && (module.exports = {
|
|
418
|
+
StepSkipError,
|
|
419
|
+
TestInfoImpl,
|
|
420
|
+
TestSkipError,
|
|
421
|
+
TestStepInfoImpl
|
|
422
|
+
});
|