|
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 taskRunner_exports = {}; |
|
f7eb47b…
|
lmata
|
20 |
__export(taskRunner_exports, { |
|
f7eb47b…
|
lmata
|
21 |
TaskRunner: () => TaskRunner |
|
f7eb47b…
|
lmata
|
22 |
}); |
|
f7eb47b…
|
lmata
|
23 |
module.exports = __toCommonJS(taskRunner_exports); |
|
f7eb47b…
|
lmata
|
24 |
var import_utils = require("playwright-core/lib/utils"); |
|
f7eb47b…
|
lmata
|
25 |
var import_utils2 = require("playwright-core/lib/utils"); |
|
f7eb47b…
|
lmata
|
26 |
var import_utilsBundle = require("playwright-core/lib/utilsBundle"); |
|
f7eb47b…
|
lmata
|
27 |
var import_sigIntWatcher = require("./sigIntWatcher"); |
|
f7eb47b…
|
lmata
|
28 |
var import_util = require("../util"); |
|
f7eb47b…
|
lmata
|
29 |
class TaskRunner { |
|
f7eb47b…
|
lmata
|
30 |
constructor(reporter, globalTimeoutForError) { |
|
f7eb47b…
|
lmata
|
31 |
this._tasks = []; |
|
f7eb47b…
|
lmata
|
32 |
this._hasErrors = false; |
|
f7eb47b…
|
lmata
|
33 |
this._interrupted = false; |
|
f7eb47b…
|
lmata
|
34 |
this._isTearDown = false; |
|
f7eb47b…
|
lmata
|
35 |
this._reporter = reporter; |
|
f7eb47b…
|
lmata
|
36 |
this._globalTimeoutForError = globalTimeoutForError; |
|
f7eb47b…
|
lmata
|
37 |
} |
|
f7eb47b…
|
lmata
|
38 |
addTask(task) { |
|
f7eb47b…
|
lmata
|
39 |
this._tasks.push(task); |
|
f7eb47b…
|
lmata
|
40 |
} |
|
f7eb47b…
|
lmata
|
41 |
async run(context, deadline, cancelPromise) { |
|
f7eb47b…
|
lmata
|
42 |
const { status, cleanup } = await this.runDeferCleanup(context, deadline, cancelPromise); |
|
f7eb47b…
|
lmata
|
43 |
const teardownStatus = await cleanup(); |
|
f7eb47b…
|
lmata
|
44 |
return status === "passed" ? teardownStatus : status; |
|
f7eb47b…
|
lmata
|
45 |
} |
|
f7eb47b…
|
lmata
|
46 |
async runDeferCleanup(context, deadline, cancelPromise = new import_utils.ManualPromise()) { |
|
f7eb47b…
|
lmata
|
47 |
const sigintWatcher = new import_sigIntWatcher.SigIntWatcher(); |
|
f7eb47b…
|
lmata
|
48 |
const timeoutWatcher = new TimeoutWatcher(deadline); |
|
f7eb47b…
|
lmata
|
49 |
const teardownRunner = new TaskRunner(this._reporter, this._globalTimeoutForError); |
|
f7eb47b…
|
lmata
|
50 |
teardownRunner._isTearDown = true; |
|
f7eb47b…
|
lmata
|
51 |
let currentTaskName; |
|
f7eb47b…
|
lmata
|
52 |
const taskLoop = async () => { |
|
f7eb47b…
|
lmata
|
53 |
for (const task of this._tasks) { |
|
f7eb47b…
|
lmata
|
54 |
currentTaskName = task.title; |
|
f7eb47b…
|
lmata
|
55 |
if (this._interrupted) |
|
f7eb47b…
|
lmata
|
56 |
break; |
|
f7eb47b…
|
lmata
|
57 |
(0, import_utilsBundle.debug)("pw:test:task")(`"${task.title}" started`); |
|
f7eb47b…
|
lmata
|
58 |
const errors = []; |
|
f7eb47b…
|
lmata
|
59 |
const softErrors = []; |
|
f7eb47b…
|
lmata
|
60 |
try { |
|
f7eb47b…
|
lmata
|
61 |
teardownRunner._tasks.unshift({ title: `teardown for ${task.title}`, setup: task.teardown }); |
|
f7eb47b…
|
lmata
|
62 |
await task.setup?.(context, errors, softErrors); |
|
f7eb47b…
|
lmata
|
63 |
} catch (e) { |
|
f7eb47b…
|
lmata
|
64 |
(0, import_utilsBundle.debug)("pw:test:task")(`error in "${task.title}": `, e); |
|
f7eb47b…
|
lmata
|
65 |
errors.push((0, import_util.serializeError)(e)); |
|
f7eb47b…
|
lmata
|
66 |
} finally { |
|
f7eb47b…
|
lmata
|
67 |
for (const error of [...softErrors, ...errors]) |
|
f7eb47b…
|
lmata
|
68 |
this._reporter.onError?.(error); |
|
f7eb47b…
|
lmata
|
69 |
if (errors.length) { |
|
f7eb47b…
|
lmata
|
70 |
if (!this._isTearDown) |
|
f7eb47b…
|
lmata
|
71 |
this._interrupted = true; |
|
f7eb47b…
|
lmata
|
72 |
this._hasErrors = true; |
|
f7eb47b…
|
lmata
|
73 |
} |
|
f7eb47b…
|
lmata
|
74 |
} |
|
f7eb47b…
|
lmata
|
75 |
(0, import_utilsBundle.debug)("pw:test:task")(`"${task.title}" finished`); |
|
f7eb47b…
|
lmata
|
76 |
} |
|
f7eb47b…
|
lmata
|
77 |
}; |
|
f7eb47b…
|
lmata
|
78 |
await Promise.race([ |
|
f7eb47b…
|
lmata
|
79 |
taskLoop(), |
|
f7eb47b…
|
lmata
|
80 |
cancelPromise, |
|
f7eb47b…
|
lmata
|
81 |
sigintWatcher.promise(), |
|
f7eb47b…
|
lmata
|
82 |
timeoutWatcher.promise |
|
f7eb47b…
|
lmata
|
83 |
]); |
|
f7eb47b…
|
lmata
|
84 |
sigintWatcher.disarm(); |
|
f7eb47b…
|
lmata
|
85 |
timeoutWatcher.disarm(); |
|
f7eb47b…
|
lmata
|
86 |
this._interrupted = true; |
|
f7eb47b…
|
lmata
|
87 |
let status = "passed"; |
|
f7eb47b…
|
lmata
|
88 |
if (sigintWatcher.hadSignal() || cancelPromise?.isDone()) { |
|
f7eb47b…
|
lmata
|
89 |
status = "interrupted"; |
|
f7eb47b…
|
lmata
|
90 |
} else if (timeoutWatcher.timedOut()) { |
|
f7eb47b…
|
lmata
|
91 |
this._reporter.onError?.({ message: import_utils2.colors.red(`Timed out waiting ${this._globalTimeoutForError / 1e3}s for the ${currentTaskName} to run`) }); |
|
f7eb47b…
|
lmata
|
92 |
status = "timedout"; |
|
f7eb47b…
|
lmata
|
93 |
} else if (this._hasErrors) { |
|
f7eb47b…
|
lmata
|
94 |
status = "failed"; |
|
f7eb47b…
|
lmata
|
95 |
} |
|
f7eb47b…
|
lmata
|
96 |
cancelPromise?.resolve(); |
|
f7eb47b…
|
lmata
|
97 |
const cleanup = () => teardownRunner.runDeferCleanup(context, deadline).then((r) => r.status); |
|
f7eb47b…
|
lmata
|
98 |
return { status, cleanup }; |
|
f7eb47b…
|
lmata
|
99 |
} |
|
f7eb47b…
|
lmata
|
100 |
} |
|
f7eb47b…
|
lmata
|
101 |
class TimeoutWatcher { |
|
f7eb47b…
|
lmata
|
102 |
constructor(deadline) { |
|
f7eb47b…
|
lmata
|
103 |
this._timedOut = false; |
|
f7eb47b…
|
lmata
|
104 |
this.promise = new import_utils.ManualPromise(); |
|
f7eb47b…
|
lmata
|
105 |
if (!deadline) |
|
f7eb47b…
|
lmata
|
106 |
return; |
|
f7eb47b…
|
lmata
|
107 |
if (deadline - (0, import_utils.monotonicTime)() <= 0) { |
|
f7eb47b…
|
lmata
|
108 |
this._timedOut = true; |
|
f7eb47b…
|
lmata
|
109 |
this.promise.resolve(); |
|
f7eb47b…
|
lmata
|
110 |
return; |
|
f7eb47b…
|
lmata
|
111 |
} |
|
f7eb47b…
|
lmata
|
112 |
this._timer = setTimeout(() => { |
|
f7eb47b…
|
lmata
|
113 |
this._timedOut = true; |
|
f7eb47b…
|
lmata
|
114 |
this.promise.resolve(); |
|
f7eb47b…
|
lmata
|
115 |
}, deadline - (0, import_utils.monotonicTime)()); |
|
f7eb47b…
|
lmata
|
116 |
} |
|
f7eb47b…
|
lmata
|
117 |
timedOut() { |
|
f7eb47b…
|
lmata
|
118 |
return this._timedOut; |
|
f7eb47b…
|
lmata
|
119 |
} |
|
f7eb47b…
|
lmata
|
120 |
disarm() { |
|
f7eb47b…
|
lmata
|
121 |
clearTimeout(this._timer); |
|
f7eb47b…
|
lmata
|
122 |
} |
|
f7eb47b…
|
lmata
|
123 |
} |
|
f7eb47b…
|
lmata
|
124 |
// Annotate the CommonJS export names for ESM import in node: |
|
f7eb47b…
|
lmata
|
125 |
0 && (module.exports = { |
|
f7eb47b…
|
lmata
|
126 |
TaskRunner |
|
f7eb47b…
|
lmata
|
127 |
}); |