-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep.ts
More file actions
100 lines (85 loc) · 2.34 KB
/
Copy pathstep.ts
File metadata and controls
100 lines (85 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import {LogEventType} from './constants/internal';
import {getTestRunPromise} from './context/testRunPromise';
import {setCustomInspectOnFunction} from './utils/fn';
import {generalLog} from './utils/generalLog';
import {logAndGetLogEvent} from './utils/log';
import {setReadonlyProperty} from './utils/object';
import {processStepError, runStepBody} from './utils/step';
import type {
LogEvent,
LogPayload,
StepBody,
StepErrorProperties,
StepOptions,
UtcTimeInMs,
Void,
} from './types/internal';
/**
* Declares a test step (could calls Playwright's `test.step` function inside).
*/
// eslint-disable-next-line max-statements
export const step = async (
name: string,
body?: StepBody,
options: StepOptions = {},
): Promise<void> => {
if (body !== undefined) {
setCustomInspectOnFunction(body);
}
let logEvent: LogEvent | undefined;
const errorProperties: StepErrorProperties = {
stepBody: body,
stepName: name,
stepOptions: {...options, payload: {...options.payload}},
};
let isTestRunCompleted = false;
let payload = undefined as LogPayload | Void;
let stepError: unknown;
try {
const testRunPromise = getTestRunPromise();
void testRunPromise.then(() => {
isTestRunCompleted = true;
});
if (options?.skipLogs !== true) {
logEvent = logAndGetLogEvent(
name,
options?.payload,
options?.type ?? LogEventType.InternalCore,
);
}
const {
bodyError,
hasError,
payload: additionalPayload,
} = await runStepBody({
body,
errorProperties,
logEvent,
name,
stepOptions: options,
});
payload = additionalPayload;
if (hasError) {
throw bodyError;
}
} catch (error) {
stepError = processStepError({error, errorProperties, logEvent});
if (isTestRunCompleted) {
await new Promise(() => {});
}
throw stepError;
} finally {
if (logEvent !== undefined) {
const endTime = Date.now() as UtcTimeInMs;
setReadonlyProperty(logEvent, 'endTime', endTime);
if (payload !== undefined) {
setReadonlyProperty(logEvent, 'payload', {...logEvent.payload, ...payload});
}
generalLog(`Step "${name}" completed`, {
body,
step: {...logEvent, children: logEvent.children?.map(({message}) => message)},
stepError,
});
}
}
};