@testpulse.run/playwright-events 0.2.3
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/README.md +56 -0
- package/dist/index.cjs +180 -0
- package/dist/index.d.cts +86 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.js +152 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://testpulse.run">
|
|
3
|
+
<img src="https://testpulse.run/images/logo-testpulse.svg" alt="TestPulse.run" height="48">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://testpulse.run">testpulse.run</a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
# @testpulse.run/playwright-events
|
|
12
|
+
|
|
13
|
+
Derived Playwright test events for TestPulse reporters.
|
|
14
|
+
|
|
15
|
+
This package consumes normalized core events from `@testpulse.run/playwright-core` and emits higher-level events such as test attempts and final test outcomes. It is useful when you are building a custom reporter and do not want to derive retries, flaky outcomes, skipped results, and attempt lifecycle yourself.
|
|
16
|
+
|
|
17
|
+
Most users should install `@testpulse.run/reporter` instead.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm install -D @testpulse.run/playwright-events @testpulse.run/playwright-core @playwright/test
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Basic Usage
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { TestPulseReporterCore } from "@testpulse.run/playwright-core";
|
|
29
|
+
import { PlaywrightEvents, type TestPulseDerivedEventsPlugin } from "@testpulse.run/playwright-events";
|
|
30
|
+
|
|
31
|
+
const derivedPlugin: TestPulseDerivedEventsPlugin = {
|
|
32
|
+
name: "my-derived-events",
|
|
33
|
+
TestAttemptFinished: (event) => {
|
|
34
|
+
recordAttempt(event.test.title, event.status, event.retry);
|
|
35
|
+
},
|
|
36
|
+
TestOutcomeResolved: (event) => {
|
|
37
|
+
recordOutcome(event.test.title, event.outcome);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const events = new PlaywrightEvents({ plugins: [derivedPlugin] });
|
|
42
|
+
const core = new TestPulseReporterCore({ plugins: [events.asCorePlugin()] });
|
|
43
|
+
events.setErrorSink(core);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Derived Events
|
|
47
|
+
|
|
48
|
+
- `TestAttemptStarted`
|
|
49
|
+
- `TestAttemptFinished`
|
|
50
|
+
- `TestOutcomeResolved`
|
|
51
|
+
|
|
52
|
+
## Related Packages
|
|
53
|
+
|
|
54
|
+
- `@testpulse.run/reporter`: preconfigured HTTP reporter for TestPulse.
|
|
55
|
+
- `@testpulse.run/playwright-jsonl-reporter`: writes core and derived events to JSONL or HTTP sinks.
|
|
56
|
+
- `@testpulse.run/playwright-core`: normalized Playwright reporter lifecycle events.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
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
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
PlaywrightEvents: () => PlaywrightEvents,
|
|
24
|
+
TestPulseDerivedEventName: () => TestPulseDerivedEventName
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/events.ts
|
|
29
|
+
var TestPulseDerivedEventName = {
|
|
30
|
+
TestAttemptStarted: "TestAttemptStarted",
|
|
31
|
+
TestAttemptFinished: "TestAttemptFinished",
|
|
32
|
+
TestOutcomeResolved: "TestOutcomeResolved"
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/playwright-events.ts
|
|
36
|
+
var PlaywrightEvents = class {
|
|
37
|
+
handlerErrors = [];
|
|
38
|
+
plugins;
|
|
39
|
+
errorSink;
|
|
40
|
+
attemptsByTestId = /* @__PURE__ */ new Map();
|
|
41
|
+
resolvedTestIds = /* @__PURE__ */ new Set();
|
|
42
|
+
constructor(options = {}) {
|
|
43
|
+
this.plugins = options.plugins ?? [];
|
|
44
|
+
this.errorSink = options.errorSink;
|
|
45
|
+
}
|
|
46
|
+
setErrorSink(errorSink) {
|
|
47
|
+
this.errorSink = errorSink;
|
|
48
|
+
}
|
|
49
|
+
asCorePlugin() {
|
|
50
|
+
return {
|
|
51
|
+
name: "@testpulse.run/playwright-events",
|
|
52
|
+
RunStarted: () => this.reset(),
|
|
53
|
+
TestStarted: (event, context) => this.onTestStarted(event, context),
|
|
54
|
+
TestFinished: (event, context) => this.onTestFinished(event, context)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
onTestStarted(event, context = {}) {
|
|
58
|
+
const metadata = createMetadata(event);
|
|
59
|
+
this.emit({
|
|
60
|
+
eventName: TestPulseDerivedEventName.TestAttemptStarted,
|
|
61
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
62
|
+
source: "synthetic",
|
|
63
|
+
...metadata,
|
|
64
|
+
attemptIndex: event.retry,
|
|
65
|
+
retry: event.retry,
|
|
66
|
+
coreEvent: {
|
|
67
|
+
eventName: event.eventName,
|
|
68
|
+
timestamp: event.timestamp
|
|
69
|
+
}
|
|
70
|
+
}, { coreContext: context });
|
|
71
|
+
}
|
|
72
|
+
onTestFinished(event, context = {}) {
|
|
73
|
+
const metadata = createMetadata(event);
|
|
74
|
+
if (this.resolvedTestIds.has(metadata.testId)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const attempt = createAttempt(event);
|
|
78
|
+
const attempts = [...this.attemptsByTestId.get(metadata.testId) ?? [], attempt];
|
|
79
|
+
this.attemptsByTestId.set(metadata.testId, attempts);
|
|
80
|
+
this.emit({
|
|
81
|
+
eventName: TestPulseDerivedEventName.TestAttemptFinished,
|
|
82
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
83
|
+
source: "synthetic",
|
|
84
|
+
...metadata,
|
|
85
|
+
attempt,
|
|
86
|
+
attemptIndex: attempt.attemptIndex,
|
|
87
|
+
retry: attempt.retry,
|
|
88
|
+
status: attempt.status,
|
|
89
|
+
coreEvent: {
|
|
90
|
+
eventName: event.eventName,
|
|
91
|
+
timestamp: event.timestamp
|
|
92
|
+
}
|
|
93
|
+
}, { coreContext: context });
|
|
94
|
+
if (!isFinalAttempt(event)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.resolvedTestIds.add(metadata.testId);
|
|
98
|
+
this.attemptsByTestId.delete(metadata.testId);
|
|
99
|
+
this.emit({
|
|
100
|
+
eventName: TestPulseDerivedEventName.TestOutcomeResolved,
|
|
101
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
102
|
+
source: "synthetic",
|
|
103
|
+
...metadata,
|
|
104
|
+
outcome: resolveOutcome(event, attempts),
|
|
105
|
+
attempts,
|
|
106
|
+
finalAttempt: attempt,
|
|
107
|
+
coreEvent: {
|
|
108
|
+
eventName: event.eventName,
|
|
109
|
+
timestamp: event.timestamp
|
|
110
|
+
}
|
|
111
|
+
}, { coreContext: context });
|
|
112
|
+
}
|
|
113
|
+
emit(event, context) {
|
|
114
|
+
for (const plugin of this.plugins) {
|
|
115
|
+
const handler = plugin[event.eventName];
|
|
116
|
+
if (!handler) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
handler.call(plugin, event, context);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
const handlerError = {
|
|
123
|
+
source: "@testpulse.run/playwright-events",
|
|
124
|
+
eventName: event.eventName,
|
|
125
|
+
pluginName: plugin.name,
|
|
126
|
+
error
|
|
127
|
+
};
|
|
128
|
+
this.handlerErrors.push(handlerError);
|
|
129
|
+
this.errorSink?.recordHandlerError(handlerError);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
reset() {
|
|
134
|
+
this.handlerErrors.length = 0;
|
|
135
|
+
this.attemptsByTestId.clear();
|
|
136
|
+
this.resolvedTestIds.clear();
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
function createMetadata(event) {
|
|
140
|
+
return {
|
|
141
|
+
...event.test,
|
|
142
|
+
testId: event.test.testId ?? event.titlePath.join(" \u203A "),
|
|
143
|
+
test: event.test,
|
|
144
|
+
titlePath: event.titlePath,
|
|
145
|
+
worker: event.worker
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function createAttempt(event) {
|
|
149
|
+
return {
|
|
150
|
+
attemptIndex: event.retry,
|
|
151
|
+
retry: event.retry,
|
|
152
|
+
status: event.status,
|
|
153
|
+
durationMs: event.durationMs,
|
|
154
|
+
errors: event.errors,
|
|
155
|
+
attachments: event.attachments
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function isFinalAttempt(event) {
|
|
159
|
+
return event.status === event.expectedStatus || event.retry >= (event.test.retryCount ?? 0) || event.status === "skipped" || event.status === "interrupted";
|
|
160
|
+
}
|
|
161
|
+
function resolveOutcome(event, attempts) {
|
|
162
|
+
if (event.status === "skipped") {
|
|
163
|
+
return "skipped";
|
|
164
|
+
}
|
|
165
|
+
if (event.status === "interrupted") {
|
|
166
|
+
return "interrupted";
|
|
167
|
+
}
|
|
168
|
+
if (event.status === "timedOut") {
|
|
169
|
+
return "timedOut";
|
|
170
|
+
}
|
|
171
|
+
if (event.status === "passed") {
|
|
172
|
+
return attempts.some((attempt) => attempt.status === "failed" || attempt.status === "timedOut" || attempt.status === "interrupted") ? "flaky" : "passed";
|
|
173
|
+
}
|
|
174
|
+
return "failed";
|
|
175
|
+
}
|
|
176
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
177
|
+
0 && (module.exports = {
|
|
178
|
+
PlaywrightEvents,
|
|
179
|
+
TestPulseDerivedEventName
|
|
180
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { TestPulseHandlerError, TestPulseTestInfo, WorkerIdentity, TestStartedEvent, NormalizedTestStatus, TestPulseErrorInfo, AttachmentInfo, TestFinishedEvent, PlaywrightCoreEventContext, TestPulseEventSource, TestPulseHandlerErrorSink, TestPulseReporterPlugin } from '@testpulse.run/playwright-core';
|
|
2
|
+
|
|
3
|
+
declare const TestPulseDerivedEventName: {
|
|
4
|
+
readonly TestAttemptStarted: "TestAttemptStarted";
|
|
5
|
+
readonly TestAttemptFinished: "TestAttemptFinished";
|
|
6
|
+
readonly TestOutcomeResolved: "TestOutcomeResolved";
|
|
7
|
+
};
|
|
8
|
+
type TestPulseDerivedEventName = (typeof TestPulseDerivedEventName)[keyof typeof TestPulseDerivedEventName];
|
|
9
|
+
type TestOutcome = "passed" | "failed" | "flaky" | "skipped" | "interrupted" | "timedOut";
|
|
10
|
+
interface TestAttempt {
|
|
11
|
+
attemptIndex: number;
|
|
12
|
+
retry: number;
|
|
13
|
+
status: NormalizedTestStatus;
|
|
14
|
+
durationMs: number;
|
|
15
|
+
errors: TestPulseErrorInfo[];
|
|
16
|
+
attachments: AttachmentInfo[];
|
|
17
|
+
}
|
|
18
|
+
interface TestMetadata extends TestPulseTestInfo {
|
|
19
|
+
testId: string;
|
|
20
|
+
test: TestPulseTestInfo;
|
|
21
|
+
worker: WorkerIdentity;
|
|
22
|
+
}
|
|
23
|
+
interface TestAttemptStartedEvent extends TestMetadata {
|
|
24
|
+
eventName: "TestAttemptStarted";
|
|
25
|
+
timestamp: string;
|
|
26
|
+
source: "synthetic";
|
|
27
|
+
attemptIndex: number;
|
|
28
|
+
retry: number;
|
|
29
|
+
coreEvent: Pick<TestStartedEvent, "eventName" | "timestamp">;
|
|
30
|
+
}
|
|
31
|
+
interface TestAttemptFinishedEvent extends TestMetadata {
|
|
32
|
+
eventName: "TestAttemptFinished";
|
|
33
|
+
timestamp: string;
|
|
34
|
+
source: "synthetic";
|
|
35
|
+
attempt: TestAttempt;
|
|
36
|
+
attemptIndex: number;
|
|
37
|
+
retry: number;
|
|
38
|
+
status: NormalizedTestStatus;
|
|
39
|
+
coreEvent: Pick<TestFinishedEvent, "eventName" | "timestamp">;
|
|
40
|
+
}
|
|
41
|
+
interface TestOutcomeResolvedEvent extends TestMetadata {
|
|
42
|
+
eventName: "TestOutcomeResolved";
|
|
43
|
+
timestamp: string;
|
|
44
|
+
source: "synthetic";
|
|
45
|
+
outcome: TestOutcome;
|
|
46
|
+
attempts: TestAttempt[];
|
|
47
|
+
finalAttempt: TestAttempt;
|
|
48
|
+
coreEvent: Pick<TestFinishedEvent, "eventName" | "timestamp">;
|
|
49
|
+
}
|
|
50
|
+
type TestPulseDerivedEvent = TestAttemptStartedEvent | TestAttemptFinishedEvent | TestOutcomeResolvedEvent;
|
|
51
|
+
type TestPulseDerivedEventMap = {
|
|
52
|
+
[Event in TestPulseDerivedEvent as Event["eventName"]]: Event;
|
|
53
|
+
};
|
|
54
|
+
interface PlaywrightDerivedEventContext {
|
|
55
|
+
coreContext?: PlaywrightCoreEventContext;
|
|
56
|
+
}
|
|
57
|
+
type TestPulseDerivedHandler<Name extends TestPulseDerivedEventName> = (event: TestPulseDerivedEventMap[Name], context: PlaywrightDerivedEventContext) => void;
|
|
58
|
+
type TestPulseDerivedHandlerMap = Partial<{
|
|
59
|
+
[Name in TestPulseDerivedEventName]: TestPulseDerivedHandler<Name>;
|
|
60
|
+
}>;
|
|
61
|
+
interface TestPulseDerivedEventsPlugin extends TestPulseDerivedHandlerMap {
|
|
62
|
+
name?: string;
|
|
63
|
+
}
|
|
64
|
+
type TestPulseDerivedHandlerError = TestPulseHandlerError;
|
|
65
|
+
type TestPulseDerivedEventSource = TestPulseEventSource;
|
|
66
|
+
|
|
67
|
+
interface PlaywrightEventsOptions {
|
|
68
|
+
plugins?: TestPulseDerivedEventsPlugin[];
|
|
69
|
+
errorSink?: TestPulseHandlerErrorSink;
|
|
70
|
+
}
|
|
71
|
+
declare class PlaywrightEvents {
|
|
72
|
+
readonly handlerErrors: TestPulseDerivedHandlerError[];
|
|
73
|
+
private readonly plugins;
|
|
74
|
+
private errorSink?;
|
|
75
|
+
private readonly attemptsByTestId;
|
|
76
|
+
private readonly resolvedTestIds;
|
|
77
|
+
constructor(options?: PlaywrightEventsOptions);
|
|
78
|
+
setErrorSink(errorSink: TestPulseHandlerErrorSink | undefined): void;
|
|
79
|
+
asCorePlugin(): TestPulseReporterPlugin;
|
|
80
|
+
onTestStarted(event: TestStartedEvent, context?: PlaywrightCoreEventContext): void;
|
|
81
|
+
onTestFinished(event: TestFinishedEvent, context?: PlaywrightCoreEventContext): void;
|
|
82
|
+
private emit;
|
|
83
|
+
private reset;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { PlaywrightEvents, type PlaywrightEventsOptions, type TestAttempt, type TestAttemptFinishedEvent, type TestAttemptStartedEvent, type TestMetadata, type TestOutcome, type TestOutcomeResolvedEvent, type TestPulseDerivedEvent, type TestPulseDerivedEventMap, TestPulseDerivedEventName, type TestPulseDerivedEventSource, type TestPulseDerivedEventsPlugin, type TestPulseDerivedHandler, type TestPulseDerivedHandlerError, type TestPulseDerivedHandlerMap };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { TestPulseHandlerError, TestPulseTestInfo, WorkerIdentity, TestStartedEvent, NormalizedTestStatus, TestPulseErrorInfo, AttachmentInfo, TestFinishedEvent, PlaywrightCoreEventContext, TestPulseEventSource, TestPulseHandlerErrorSink, TestPulseReporterPlugin } from '@testpulse.run/playwright-core';
|
|
2
|
+
|
|
3
|
+
declare const TestPulseDerivedEventName: {
|
|
4
|
+
readonly TestAttemptStarted: "TestAttemptStarted";
|
|
5
|
+
readonly TestAttemptFinished: "TestAttemptFinished";
|
|
6
|
+
readonly TestOutcomeResolved: "TestOutcomeResolved";
|
|
7
|
+
};
|
|
8
|
+
type TestPulseDerivedEventName = (typeof TestPulseDerivedEventName)[keyof typeof TestPulseDerivedEventName];
|
|
9
|
+
type TestOutcome = "passed" | "failed" | "flaky" | "skipped" | "interrupted" | "timedOut";
|
|
10
|
+
interface TestAttempt {
|
|
11
|
+
attemptIndex: number;
|
|
12
|
+
retry: number;
|
|
13
|
+
status: NormalizedTestStatus;
|
|
14
|
+
durationMs: number;
|
|
15
|
+
errors: TestPulseErrorInfo[];
|
|
16
|
+
attachments: AttachmentInfo[];
|
|
17
|
+
}
|
|
18
|
+
interface TestMetadata extends TestPulseTestInfo {
|
|
19
|
+
testId: string;
|
|
20
|
+
test: TestPulseTestInfo;
|
|
21
|
+
worker: WorkerIdentity;
|
|
22
|
+
}
|
|
23
|
+
interface TestAttemptStartedEvent extends TestMetadata {
|
|
24
|
+
eventName: "TestAttemptStarted";
|
|
25
|
+
timestamp: string;
|
|
26
|
+
source: "synthetic";
|
|
27
|
+
attemptIndex: number;
|
|
28
|
+
retry: number;
|
|
29
|
+
coreEvent: Pick<TestStartedEvent, "eventName" | "timestamp">;
|
|
30
|
+
}
|
|
31
|
+
interface TestAttemptFinishedEvent extends TestMetadata {
|
|
32
|
+
eventName: "TestAttemptFinished";
|
|
33
|
+
timestamp: string;
|
|
34
|
+
source: "synthetic";
|
|
35
|
+
attempt: TestAttempt;
|
|
36
|
+
attemptIndex: number;
|
|
37
|
+
retry: number;
|
|
38
|
+
status: NormalizedTestStatus;
|
|
39
|
+
coreEvent: Pick<TestFinishedEvent, "eventName" | "timestamp">;
|
|
40
|
+
}
|
|
41
|
+
interface TestOutcomeResolvedEvent extends TestMetadata {
|
|
42
|
+
eventName: "TestOutcomeResolved";
|
|
43
|
+
timestamp: string;
|
|
44
|
+
source: "synthetic";
|
|
45
|
+
outcome: TestOutcome;
|
|
46
|
+
attempts: TestAttempt[];
|
|
47
|
+
finalAttempt: TestAttempt;
|
|
48
|
+
coreEvent: Pick<TestFinishedEvent, "eventName" | "timestamp">;
|
|
49
|
+
}
|
|
50
|
+
type TestPulseDerivedEvent = TestAttemptStartedEvent | TestAttemptFinishedEvent | TestOutcomeResolvedEvent;
|
|
51
|
+
type TestPulseDerivedEventMap = {
|
|
52
|
+
[Event in TestPulseDerivedEvent as Event["eventName"]]: Event;
|
|
53
|
+
};
|
|
54
|
+
interface PlaywrightDerivedEventContext {
|
|
55
|
+
coreContext?: PlaywrightCoreEventContext;
|
|
56
|
+
}
|
|
57
|
+
type TestPulseDerivedHandler<Name extends TestPulseDerivedEventName> = (event: TestPulseDerivedEventMap[Name], context: PlaywrightDerivedEventContext) => void;
|
|
58
|
+
type TestPulseDerivedHandlerMap = Partial<{
|
|
59
|
+
[Name in TestPulseDerivedEventName]: TestPulseDerivedHandler<Name>;
|
|
60
|
+
}>;
|
|
61
|
+
interface TestPulseDerivedEventsPlugin extends TestPulseDerivedHandlerMap {
|
|
62
|
+
name?: string;
|
|
63
|
+
}
|
|
64
|
+
type TestPulseDerivedHandlerError = TestPulseHandlerError;
|
|
65
|
+
type TestPulseDerivedEventSource = TestPulseEventSource;
|
|
66
|
+
|
|
67
|
+
interface PlaywrightEventsOptions {
|
|
68
|
+
plugins?: TestPulseDerivedEventsPlugin[];
|
|
69
|
+
errorSink?: TestPulseHandlerErrorSink;
|
|
70
|
+
}
|
|
71
|
+
declare class PlaywrightEvents {
|
|
72
|
+
readonly handlerErrors: TestPulseDerivedHandlerError[];
|
|
73
|
+
private readonly plugins;
|
|
74
|
+
private errorSink?;
|
|
75
|
+
private readonly attemptsByTestId;
|
|
76
|
+
private readonly resolvedTestIds;
|
|
77
|
+
constructor(options?: PlaywrightEventsOptions);
|
|
78
|
+
setErrorSink(errorSink: TestPulseHandlerErrorSink | undefined): void;
|
|
79
|
+
asCorePlugin(): TestPulseReporterPlugin;
|
|
80
|
+
onTestStarted(event: TestStartedEvent, context?: PlaywrightCoreEventContext): void;
|
|
81
|
+
onTestFinished(event: TestFinishedEvent, context?: PlaywrightCoreEventContext): void;
|
|
82
|
+
private emit;
|
|
83
|
+
private reset;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { PlaywrightEvents, type PlaywrightEventsOptions, type TestAttempt, type TestAttemptFinishedEvent, type TestAttemptStartedEvent, type TestMetadata, type TestOutcome, type TestOutcomeResolvedEvent, type TestPulseDerivedEvent, type TestPulseDerivedEventMap, TestPulseDerivedEventName, type TestPulseDerivedEventSource, type TestPulseDerivedEventsPlugin, type TestPulseDerivedHandler, type TestPulseDerivedHandlerError, type TestPulseDerivedHandlerMap };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// src/events.ts
|
|
2
|
+
var TestPulseDerivedEventName = {
|
|
3
|
+
TestAttemptStarted: "TestAttemptStarted",
|
|
4
|
+
TestAttemptFinished: "TestAttemptFinished",
|
|
5
|
+
TestOutcomeResolved: "TestOutcomeResolved"
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// src/playwright-events.ts
|
|
9
|
+
var PlaywrightEvents = class {
|
|
10
|
+
handlerErrors = [];
|
|
11
|
+
plugins;
|
|
12
|
+
errorSink;
|
|
13
|
+
attemptsByTestId = /* @__PURE__ */ new Map();
|
|
14
|
+
resolvedTestIds = /* @__PURE__ */ new Set();
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
this.plugins = options.plugins ?? [];
|
|
17
|
+
this.errorSink = options.errorSink;
|
|
18
|
+
}
|
|
19
|
+
setErrorSink(errorSink) {
|
|
20
|
+
this.errorSink = errorSink;
|
|
21
|
+
}
|
|
22
|
+
asCorePlugin() {
|
|
23
|
+
return {
|
|
24
|
+
name: "@testpulse.run/playwright-events",
|
|
25
|
+
RunStarted: () => this.reset(),
|
|
26
|
+
TestStarted: (event, context) => this.onTestStarted(event, context),
|
|
27
|
+
TestFinished: (event, context) => this.onTestFinished(event, context)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
onTestStarted(event, context = {}) {
|
|
31
|
+
const metadata = createMetadata(event);
|
|
32
|
+
this.emit({
|
|
33
|
+
eventName: TestPulseDerivedEventName.TestAttemptStarted,
|
|
34
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
35
|
+
source: "synthetic",
|
|
36
|
+
...metadata,
|
|
37
|
+
attemptIndex: event.retry,
|
|
38
|
+
retry: event.retry,
|
|
39
|
+
coreEvent: {
|
|
40
|
+
eventName: event.eventName,
|
|
41
|
+
timestamp: event.timestamp
|
|
42
|
+
}
|
|
43
|
+
}, { coreContext: context });
|
|
44
|
+
}
|
|
45
|
+
onTestFinished(event, context = {}) {
|
|
46
|
+
const metadata = createMetadata(event);
|
|
47
|
+
if (this.resolvedTestIds.has(metadata.testId)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const attempt = createAttempt(event);
|
|
51
|
+
const attempts = [...this.attemptsByTestId.get(metadata.testId) ?? [], attempt];
|
|
52
|
+
this.attemptsByTestId.set(metadata.testId, attempts);
|
|
53
|
+
this.emit({
|
|
54
|
+
eventName: TestPulseDerivedEventName.TestAttemptFinished,
|
|
55
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
56
|
+
source: "synthetic",
|
|
57
|
+
...metadata,
|
|
58
|
+
attempt,
|
|
59
|
+
attemptIndex: attempt.attemptIndex,
|
|
60
|
+
retry: attempt.retry,
|
|
61
|
+
status: attempt.status,
|
|
62
|
+
coreEvent: {
|
|
63
|
+
eventName: event.eventName,
|
|
64
|
+
timestamp: event.timestamp
|
|
65
|
+
}
|
|
66
|
+
}, { coreContext: context });
|
|
67
|
+
if (!isFinalAttempt(event)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.resolvedTestIds.add(metadata.testId);
|
|
71
|
+
this.attemptsByTestId.delete(metadata.testId);
|
|
72
|
+
this.emit({
|
|
73
|
+
eventName: TestPulseDerivedEventName.TestOutcomeResolved,
|
|
74
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
75
|
+
source: "synthetic",
|
|
76
|
+
...metadata,
|
|
77
|
+
outcome: resolveOutcome(event, attempts),
|
|
78
|
+
attempts,
|
|
79
|
+
finalAttempt: attempt,
|
|
80
|
+
coreEvent: {
|
|
81
|
+
eventName: event.eventName,
|
|
82
|
+
timestamp: event.timestamp
|
|
83
|
+
}
|
|
84
|
+
}, { coreContext: context });
|
|
85
|
+
}
|
|
86
|
+
emit(event, context) {
|
|
87
|
+
for (const plugin of this.plugins) {
|
|
88
|
+
const handler = plugin[event.eventName];
|
|
89
|
+
if (!handler) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
handler.call(plugin, event, context);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
const handlerError = {
|
|
96
|
+
source: "@testpulse.run/playwright-events",
|
|
97
|
+
eventName: event.eventName,
|
|
98
|
+
pluginName: plugin.name,
|
|
99
|
+
error
|
|
100
|
+
};
|
|
101
|
+
this.handlerErrors.push(handlerError);
|
|
102
|
+
this.errorSink?.recordHandlerError(handlerError);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
reset() {
|
|
107
|
+
this.handlerErrors.length = 0;
|
|
108
|
+
this.attemptsByTestId.clear();
|
|
109
|
+
this.resolvedTestIds.clear();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
function createMetadata(event) {
|
|
113
|
+
return {
|
|
114
|
+
...event.test,
|
|
115
|
+
testId: event.test.testId ?? event.titlePath.join(" \u203A "),
|
|
116
|
+
test: event.test,
|
|
117
|
+
titlePath: event.titlePath,
|
|
118
|
+
worker: event.worker
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function createAttempt(event) {
|
|
122
|
+
return {
|
|
123
|
+
attemptIndex: event.retry,
|
|
124
|
+
retry: event.retry,
|
|
125
|
+
status: event.status,
|
|
126
|
+
durationMs: event.durationMs,
|
|
127
|
+
errors: event.errors,
|
|
128
|
+
attachments: event.attachments
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function isFinalAttempt(event) {
|
|
132
|
+
return event.status === event.expectedStatus || event.retry >= (event.test.retryCount ?? 0) || event.status === "skipped" || event.status === "interrupted";
|
|
133
|
+
}
|
|
134
|
+
function resolveOutcome(event, attempts) {
|
|
135
|
+
if (event.status === "skipped") {
|
|
136
|
+
return "skipped";
|
|
137
|
+
}
|
|
138
|
+
if (event.status === "interrupted") {
|
|
139
|
+
return "interrupted";
|
|
140
|
+
}
|
|
141
|
+
if (event.status === "timedOut") {
|
|
142
|
+
return "timedOut";
|
|
143
|
+
}
|
|
144
|
+
if (event.status === "passed") {
|
|
145
|
+
return attempts.some((attempt) => attempt.status === "failed" || attempt.status === "timedOut" || attempt.status === "interrupted") ? "flaky" : "passed";
|
|
146
|
+
}
|
|
147
|
+
return "failed";
|
|
148
|
+
}
|
|
149
|
+
export {
|
|
150
|
+
PlaywrightEvents,
|
|
151
|
+
TestPulseDerivedEventName
|
|
152
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@testpulse.run/playwright-events",
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"description": "Derived Playwright test events for TestPulse reporters.",
|
|
5
|
+
"homepage": "https://testpulse.run",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"testpulse",
|
|
8
|
+
"playwright",
|
|
9
|
+
"playwright-reporter",
|
|
10
|
+
"test-events",
|
|
11
|
+
"test-automation",
|
|
12
|
+
"testing",
|
|
13
|
+
"typescript"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.cjs",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"require": "./dist/index.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
34
|
+
"test": "vitest run"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@testpulse.run/playwright-core": "0.2.3"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@playwright/test": ">=1.40.0"
|
|
41
|
+
}
|
|
42
|
+
}
|