@danwo/playwright 0.0.0-stage → 0.1.1
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 +201 -0
- package/NOTICE +12 -0
- package/README.md +13 -2
- package/bin/danwo-playwright.mjs +8 -0
- package/dist/types/bin.d.ts +1 -0
- package/dist/types/environment.d.ts +24 -0
- package/dist/types/fixture.d.ts +57 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/matrix.d.ts +19 -0
- package/dist/types/protocol.d.ts +96 -0
- package/dist/types/record.d.ts +20 -0
- package/dist/types/spawn.d.ts +13 -0
- package/package.json +47 -4
- package/src/bin.ts +51 -0
- package/src/environment.ts +41 -0
- package/src/fixture.ts +306 -0
- package/src/index.ts +19 -0
- package/src/matrix.ts +181 -0
- package/src/protocol.ts +80 -0
- package/src/record.ts +74 -0
- package/src/spawn.ts +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Carbonme Inc
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
dánwò (danwo)
|
|
2
|
+
Copyright 2026 Carbonme Inc
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
The dánwò name, wordmark and logos in brand/ are trademarks of Carbonme Inc
|
|
7
|
+
and are not licensed under the Apache License; see TRADEMARKS.md. The wordmark
|
|
8
|
+
is drawn from Young Serif, licensed under the SIL Open Font License 1.1
|
|
9
|
+
(brand/YoungSerif-OFL.txt).
|
|
10
|
+
|
|
11
|
+
All code in this repository is danwo's own. Third-party packages it depends on
|
|
12
|
+
are listed in each package.json and keep their own licences.
|
package/README.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @danwo/playwright
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
danwo's environments, emulators, faults, invariants and fault matrix for Playwright Test suites.
|
|
4
|
+
|
|
5
|
+
Part of [dánwò](https://danwo.dev), an open-source testing framework that drives your app
|
|
6
|
+
through its UI like a user, then checks everything that happened behind it. Most projects
|
|
7
|
+
get it through `@danwo/cli` and import `@danwo/sdk` in their tests:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npx @danwo/cli init
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Documentation: https://danwo.dev. Source: https://github.com/carbonmeai/danwo/tree/main/packages/playwright.
|
|
14
|
+
Licensed under the Apache License 2.0.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One Playwright worker's danwo environment: the same `environment()` a danwo project declares in
|
|
3
|
+
* `danwo.config.ts` (or one passed inline), started once per worker, with the vault that redacts
|
|
4
|
+
* the project's secrets from flight records.
|
|
5
|
+
*/
|
|
6
|
+
import { SecretVault } from "@danwo/runner";
|
|
7
|
+
import { type EnvironmentContext, type WorkerEnvironment } from "@danwo/runner/runner";
|
|
8
|
+
/** Starts what a worker's tests run against: app, emulators, proxy. */
|
|
9
|
+
export type EnvironmentFactory = (context: EnvironmentContext) => Promise<WorkerEnvironment>;
|
|
10
|
+
export interface WorkerSetup {
|
|
11
|
+
readonly env: WorkerEnvironment;
|
|
12
|
+
/** Knows the project's secret values, so records never show them. */
|
|
13
|
+
readonly vault: SecretVault;
|
|
14
|
+
}
|
|
15
|
+
export interface WorkerSetupOptions {
|
|
16
|
+
/** A danwo config file, relative to `cwd`; default the nearest `danwo.config.*`. */
|
|
17
|
+
readonly config?: string | undefined;
|
|
18
|
+
/** An environment to start instead of the config's. */
|
|
19
|
+
readonly environment?: EnvironmentFactory | undefined;
|
|
20
|
+
readonly cwd: string;
|
|
21
|
+
readonly workerIndex: number;
|
|
22
|
+
}
|
|
23
|
+
/** Loads the project's config and starts its environment for one worker. */
|
|
24
|
+
export declare function startWorkerSetup(options: WorkerSetupOptions): Promise<WorkerSetup>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ServiceDelivery } from "@danwo/matrix";
|
|
2
|
+
import type { Exchange, Proxy } from "@danwo/proxy";
|
|
3
|
+
import { type NamedFault } from "@danwo/runner/runner";
|
|
4
|
+
import { type PlaywrightTestArgs, type PlaywrightTestOptions, type PlaywrightWorkerArgs, type PlaywrightWorkerOptions, type TestType } from "@playwright/test";
|
|
5
|
+
import { type EnvironmentFactory, type WorkerSetup } from "./environment.ts";
|
|
6
|
+
/** What a test reaches danwo through. */
|
|
7
|
+
export interface DanwoHandle {
|
|
8
|
+
/** The environment's fixtures by name: emulators (`stripe`, `slack`, …) and helpers. */
|
|
9
|
+
readonly fixtures: Readonly<Record<string, unknown>>;
|
|
10
|
+
/** The proxy the browser and the app go through, when the environment has one. */
|
|
11
|
+
readonly proxy: Proxy | undefined;
|
|
12
|
+
/** Lets pending background work finish, e.g. webhooks waiting on the emulator's clock. */
|
|
13
|
+
settle(): Promise<void>;
|
|
14
|
+
/** Every call the app made through the proxy since this test began, bodies included. */
|
|
15
|
+
exchanges(): readonly Exchange[];
|
|
16
|
+
/** Every webhook delivery attempt since this test began. */
|
|
17
|
+
deliveries(): readonly ServiceDelivery[];
|
|
18
|
+
/**
|
|
19
|
+
* Arms one fault by its matrix label, e.g. `duplicate on webhook checkout.session.completed` or
|
|
20
|
+
* `status 500 on POST api.stripe.com/v1/checkout/sessions`; it fires on the next matching call.
|
|
21
|
+
*/
|
|
22
|
+
inject(fault: string): NamedFault;
|
|
23
|
+
/** Disarms every fault this test armed; returns how many had not fired. */
|
|
24
|
+
clearFaults(): number;
|
|
25
|
+
}
|
|
26
|
+
/** The `danwo` fixture: the handle plus the environment's fixtures under their own names. */
|
|
27
|
+
export type Danwo<F = Readonly<Record<string, unknown>>> = DanwoHandle & F;
|
|
28
|
+
export interface InvariantArgs<F> {
|
|
29
|
+
readonly danwo: Danwo<F>;
|
|
30
|
+
readonly baseURL: string | undefined;
|
|
31
|
+
}
|
|
32
|
+
/** What must hold after the test, however its body went: read from the app and the emulators. */
|
|
33
|
+
export type Invariant<F = Readonly<Record<string, unknown>>> = (args: InvariantArgs<F>) => Promise<void> | void;
|
|
34
|
+
export interface DanwoTestFixtures<F> {
|
|
35
|
+
danwo: Danwo<F>;
|
|
36
|
+
/** The test's invariant; set with `test.invariant(fn)` or `test.use({ invariant })`. */
|
|
37
|
+
invariant: Invariant<F> | undefined;
|
|
38
|
+
}
|
|
39
|
+
export interface DanwoWorkerFixtures {
|
|
40
|
+
/** A danwo config file whose `environment()` the worker starts; default the nearest one. */
|
|
41
|
+
danwoConfig: string | undefined;
|
|
42
|
+
/** An environment to start instead of the config's. */
|
|
43
|
+
danwoEnvironment: EnvironmentFactory | undefined;
|
|
44
|
+
danwoWorker: WorkerSetup;
|
|
45
|
+
}
|
|
46
|
+
export type DanwoTest<F = Readonly<Record<string, unknown>>> = TestType<PlaywrightTestArgs & PlaywrightTestOptions & DanwoTestFixtures<F>, PlaywrightWorkerArgs & PlaywrightWorkerOptions & DanwoWorkerFixtures> & {
|
|
47
|
+
/** Declares the invariant of every test in this file or describe block. */
|
|
48
|
+
invariant(fn: Invariant<F>): void;
|
|
49
|
+
};
|
|
50
|
+
/** `test` from `@playwright/test`, with danwo's environment, `danwo` fixture and invariants. */
|
|
51
|
+
export declare const test: DanwoTest;
|
|
52
|
+
/**
|
|
53
|
+
* `test` with the environment's fixtures typed, e.g. `testWith<StripeFixtures>()` gives
|
|
54
|
+
* `danwo.stripe`. The fixtures are whatever the environment returns; the type only names them.
|
|
55
|
+
*/
|
|
56
|
+
export declare function testWith<F>(): DanwoTest<F>;
|
|
57
|
+
export { expect } from "@playwright/test";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { EnvironmentFactory, WorkerSetup } from "./environment.ts";
|
|
2
|
+
export { type Danwo, type DanwoHandle, type DanwoTest, type DanwoTestFixtures, type DanwoWorkerFixtures, expect, type Invariant, type InvariantArgs, test, testWith, } from "./fixture.ts";
|
|
3
|
+
export { judgeTrial, type PlaywrightMatrixOptions, runPlaywrightMatrix } from "./matrix.ts";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type PlannedFault, type RunOutcome } from "@danwo/matrix";
|
|
2
|
+
import { type TestOutcome } from "./protocol.ts";
|
|
3
|
+
export interface PlaywrightMatrixOptions {
|
|
4
|
+
/** The spec file; with `grep`, it must select exactly one test. */
|
|
5
|
+
readonly spec: string;
|
|
6
|
+
readonly grep?: string | undefined;
|
|
7
|
+
/** A regular expression over planned fault labels: only the faults it matches run. */
|
|
8
|
+
readonly faults?: string | undefined;
|
|
9
|
+
/** The Playwright config file, when it is not the default one. */
|
|
10
|
+
readonly config?: string | undefined;
|
|
11
|
+
/** The danwo config whose `matrix` settings to use; default the nearest one. */
|
|
12
|
+
readonly danwoConfig?: string | undefined;
|
|
13
|
+
readonly cwd?: string | undefined;
|
|
14
|
+
readonly write?: ((line: string) => void) | undefined;
|
|
15
|
+
}
|
|
16
|
+
/** Turns one trial's outcome into a matrix run: the clean run needs body and invariant to hold. */
|
|
17
|
+
export declare function judgeTrial(fault: PlannedFault | null, outcome: TestOutcome): RunOutcome;
|
|
18
|
+
/** Runs the matrix and prints its report; resolves with the exit code. */
|
|
19
|
+
export declare function runPlaywrightMatrix(options: PlaywrightMatrixOptions): Promise<number>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How `danwo-playwright matrix` and the fixture talk across the Playwright process they share
|
|
3
|
+
* nothing else with: the matrix sets two environment variables, the fixture appends one JSON line
|
|
4
|
+
* per test to the outcome file.
|
|
5
|
+
*/
|
|
6
|
+
import type { ServiceDelivery } from "@danwo/matrix";
|
|
7
|
+
import type { Exchange } from "@danwo/proxy";
|
|
8
|
+
import { z } from "@danwo/runner/runner";
|
|
9
|
+
/** Where the fixture appends each test's outcome; set by the matrix for every trial. */
|
|
10
|
+
export declare const OUTCOME_FILE = "DANWO_PLAYWRIGHT_OUTCOME";
|
|
11
|
+
/** The fault a trial arms, by its matrix label; absent for the clean trial. */
|
|
12
|
+
export declare const TRIAL_FAULT = "DANWO_PLAYWRIGHT_FAULT";
|
|
13
|
+
declare const ExchangeLine: z.ZodObject<{
|
|
14
|
+
disposition: z.ZodEnum<{
|
|
15
|
+
blocked: "blocked";
|
|
16
|
+
passthrough: "passthrough";
|
|
17
|
+
routed: "routed";
|
|
18
|
+
}>;
|
|
19
|
+
method: z.ZodString;
|
|
20
|
+
host: z.ZodString;
|
|
21
|
+
path: z.ZodString;
|
|
22
|
+
startedAt: z.ZodString;
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
fault: z.ZodNullable<z.ZodString>;
|
|
25
|
+
status: z.ZodNullable<z.ZodNumber>;
|
|
26
|
+
durationMs: z.ZodNullable<z.ZodNumber>;
|
|
27
|
+
aborted: z.ZodBoolean;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
declare const DeliveryLine: z.ZodObject<{
|
|
30
|
+
messageId: z.ZodNumber;
|
|
31
|
+
topic: z.ZodString;
|
|
32
|
+
endpointId: z.ZodString;
|
|
33
|
+
attempt: z.ZodNumber;
|
|
34
|
+
at: z.ZodString;
|
|
35
|
+
status: z.ZodNullable<z.ZodNumber>;
|
|
36
|
+
error: z.ZodNullable<z.ZodString>;
|
|
37
|
+
durationMs: z.ZodNumber;
|
|
38
|
+
delivered: z.ZodBoolean;
|
|
39
|
+
fault: z.ZodNullable<z.ZodString>;
|
|
40
|
+
service: z.ZodExactOptional<z.ZodString>;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
/** One test's outcome as the fixture saw it. */
|
|
43
|
+
declare const OutcomeLine: z.ZodObject<{
|
|
44
|
+
title: z.ZodString;
|
|
45
|
+
file: z.ZodString;
|
|
46
|
+
body: z.ZodEnum<{
|
|
47
|
+
failed: "failed";
|
|
48
|
+
interrupted: "interrupted";
|
|
49
|
+
passed: "passed";
|
|
50
|
+
skipped: "skipped";
|
|
51
|
+
timedOut: "timedOut";
|
|
52
|
+
}>;
|
|
53
|
+
bodyError: z.ZodNullable<z.ZodString>;
|
|
54
|
+
invariant: z.ZodNullable<z.ZodObject<{
|
|
55
|
+
error: z.ZodNullable<z.ZodString>;
|
|
56
|
+
}, z.core.$strip>>;
|
|
57
|
+
line: z.ZodNullable<z.ZodNumber>;
|
|
58
|
+
exchanges: z.ZodArray<z.ZodObject<{
|
|
59
|
+
disposition: z.ZodEnum<{
|
|
60
|
+
blocked: "blocked";
|
|
61
|
+
passthrough: "passthrough";
|
|
62
|
+
routed: "routed";
|
|
63
|
+
}>;
|
|
64
|
+
method: z.ZodString;
|
|
65
|
+
host: z.ZodString;
|
|
66
|
+
path: z.ZodString;
|
|
67
|
+
startedAt: z.ZodString;
|
|
68
|
+
id: z.ZodString;
|
|
69
|
+
fault: z.ZodNullable<z.ZodString>;
|
|
70
|
+
status: z.ZodNullable<z.ZodNumber>;
|
|
71
|
+
durationMs: z.ZodNullable<z.ZodNumber>;
|
|
72
|
+
aborted: z.ZodBoolean;
|
|
73
|
+
}, z.core.$strip>>;
|
|
74
|
+
deliveries: z.ZodArray<z.ZodObject<{
|
|
75
|
+
messageId: z.ZodNumber;
|
|
76
|
+
topic: z.ZodString;
|
|
77
|
+
endpointId: z.ZodString;
|
|
78
|
+
attempt: z.ZodNumber;
|
|
79
|
+
at: z.ZodString;
|
|
80
|
+
status: z.ZodNullable<z.ZodNumber>;
|
|
81
|
+
error: z.ZodNullable<z.ZodString>;
|
|
82
|
+
durationMs: z.ZodNumber;
|
|
83
|
+
delivered: z.ZodBoolean;
|
|
84
|
+
fault: z.ZodNullable<z.ZodString>;
|
|
85
|
+
service: z.ZodExactOptional<z.ZodString>;
|
|
86
|
+
}, z.core.$strip>>;
|
|
87
|
+
record: z.ZodNullable<z.ZodString>;
|
|
88
|
+
}, z.core.$strip>;
|
|
89
|
+
export type TestOutcome = z.infer<typeof OutcomeLine>;
|
|
90
|
+
/** An exchange as the outcome file carries it: everything but its bodies. */
|
|
91
|
+
export declare function exchangeLine(exchange: Exchange): z.infer<typeof ExchangeLine>;
|
|
92
|
+
/** A delivery as the outcome file carries it. */
|
|
93
|
+
export declare function deliveryLine(delivery: ServiceDelivery): z.infer<typeof DeliveryLine>;
|
|
94
|
+
/** Every outcome line in `text`, in the order the tests finished. */
|
|
95
|
+
export declare function readOutcomes(text: string): TestOutcome[];
|
|
96
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type WorkerEnvironment } from "@danwo/runner/runner";
|
|
2
|
+
import type { TestInfo } from "@playwright/test";
|
|
3
|
+
import type { WorkerSetup } from "./environment.ts";
|
|
4
|
+
/** Where a test's evidence starts: counts of what the environment had seen before it. */
|
|
5
|
+
export interface EvidenceMark {
|
|
6
|
+
readonly exchanges: number;
|
|
7
|
+
readonly deliveries: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function markOf(env: WorkerEnvironment): EvidenceMark;
|
|
10
|
+
/** The exchanges since `mark`, unredacted (bodies included) for the test's own use. */
|
|
11
|
+
export declare function exchangesSince(env: WorkerEnvironment, mark: EvidenceMark): import("@danwo/proxy").Exchange[];
|
|
12
|
+
/** The webhook delivery attempts since `mark`. */
|
|
13
|
+
export declare function deliveriesSince(env: WorkerEnvironment, mark: EvidenceMark): import("@danwo/matrix").ServiceDelivery[];
|
|
14
|
+
export interface Verdict {
|
|
15
|
+
readonly bodyError: string | null;
|
|
16
|
+
readonly invariantError: string | null;
|
|
17
|
+
readonly fault: string | null;
|
|
18
|
+
}
|
|
19
|
+
/** Writes the test's flight record next to its output and attaches it; returns its path. */
|
|
20
|
+
export declare function attachRecord(setup: WorkerSetup, mark: EvidenceMark, verdict: Verdict, testInfo: TestInfo): Promise<string>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface PlaywrightRun {
|
|
2
|
+
readonly spec: string;
|
|
3
|
+
readonly grep?: string | undefined;
|
|
4
|
+
readonly config?: string | undefined;
|
|
5
|
+
readonly cwd?: string | undefined;
|
|
6
|
+
readonly outcomeFile: string;
|
|
7
|
+
/** Playwright's output folder for this trial, so one trial's results outlive the next. */
|
|
8
|
+
readonly outputDir: string;
|
|
9
|
+
/** The fault the trial arms, by label; none for the clean trial. */
|
|
10
|
+
readonly fault?: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
/** Runs the trial; resolves with Playwright's output once it exits, whatever its exit code. */
|
|
13
|
+
export declare function runPlaywright(run: PlaywrightRun): Promise<string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danwo/playwright",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "danwo's environments, emulators, faults, invariants and fault matrix for Playwright Test suites.",
|
|
5
|
+
"homepage": "https://danwo.dev",
|
|
6
|
+
"bugs": "https://github.com/carbonmeai/danwo/issues",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/carbonmeai/danwo.git",
|
|
11
|
+
"directory": "packages/playwright"
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"danwo-playwright": "./bin/danwo-playwright.mjs"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"bin",
|
|
18
|
+
"src",
|
|
19
|
+
"dist/types",
|
|
20
|
+
"NOTICE"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"danwo-source": "./src/index.ts",
|
|
26
|
+
"types": "./dist/types/index.d.ts",
|
|
27
|
+
"default": "./src/index.ts"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"prepack": "node ../../scripts/declarations.ts && node ../../scripts/pack-files.ts add",
|
|
32
|
+
"postpack": "node ../../scripts/pack-files.ts remove"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@danwo/emulators": "0.1.1",
|
|
36
|
+
"@danwo/matrix": "0.1.1",
|
|
37
|
+
"@danwo/proxy": "0.1.1",
|
|
38
|
+
"@danwo/runner": "0.1.1"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@playwright/test": "1.64.1"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@playwright/test": ">=1.60.0 <2"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": "^22.22.3 || >=24.11.1"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/bin.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `danwo-playwright matrix <spec> [--grep <re>] [--faults <re>] [--config <file>]
|
|
3
|
+
* [--danwo-config <file>]`: the fault matrix over one Playwright test.
|
|
4
|
+
*/
|
|
5
|
+
import { parseArgs } from "node:util"
|
|
6
|
+
|
|
7
|
+
import { runPlaywrightMatrix } from "./matrix.ts"
|
|
8
|
+
|
|
9
|
+
const USAGE =
|
|
10
|
+
"usage: danwo-playwright matrix <spec> [--grep <re>] [--faults <re>] [--config <file>] [--danwo-config <file>]"
|
|
11
|
+
|
|
12
|
+
/** The command line, or undefined when it has an option the command does not take. */
|
|
13
|
+
function parsed() {
|
|
14
|
+
try {
|
|
15
|
+
return parseArgs({
|
|
16
|
+
allowPositionals: true,
|
|
17
|
+
options: {
|
|
18
|
+
grep: { type: "string" },
|
|
19
|
+
faults: { type: "string" },
|
|
20
|
+
config: { type: "string" },
|
|
21
|
+
"danwo-config": { type: "string" },
|
|
22
|
+
help: { type: "boolean", short: "h" },
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
} catch (error) {
|
|
26
|
+
process.stderr.write(
|
|
27
|
+
`danwo-playwright: ${error instanceof Error ? error.message : String(error)}\n`,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
return undefined
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const args = parsed()
|
|
35
|
+
const { values = {}, positionals = [] } = args ?? {}
|
|
36
|
+
const [command, spec] = positionals
|
|
37
|
+
|
|
38
|
+
if (values.help === true) {
|
|
39
|
+
process.stdout.write(`${USAGE}\n`)
|
|
40
|
+
} else if (args === undefined || command !== "matrix" || spec === undefined) {
|
|
41
|
+
process.stderr.write(`${USAGE}\n`)
|
|
42
|
+
process.exitCode = 2
|
|
43
|
+
} else {
|
|
44
|
+
process.exitCode = await runPlaywrightMatrix({
|
|
45
|
+
spec,
|
|
46
|
+
grep: values.grep,
|
|
47
|
+
faults: values.faults,
|
|
48
|
+
config: values.config,
|
|
49
|
+
danwoConfig: values["danwo-config"],
|
|
50
|
+
})
|
|
51
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One Playwright worker's danwo environment: the same `environment()` a danwo project declares in
|
|
3
|
+
* `danwo.config.ts` (or one passed inline), started once per worker, with the vault that redacts
|
|
4
|
+
* the project's secrets from flight records.
|
|
5
|
+
*/
|
|
6
|
+
import { SecretVault } from "@danwo/runner"
|
|
7
|
+
import { type EnvironmentContext, loadConfig, type WorkerEnvironment } from "@danwo/runner/runner"
|
|
8
|
+
|
|
9
|
+
/** Starts what a worker's tests run against: app, emulators, proxy. */
|
|
10
|
+
export type EnvironmentFactory = (context: EnvironmentContext) => Promise<WorkerEnvironment>
|
|
11
|
+
|
|
12
|
+
export interface WorkerSetup {
|
|
13
|
+
readonly env: WorkerEnvironment
|
|
14
|
+
/** Knows the project's secret values, so records never show them. */
|
|
15
|
+
readonly vault: SecretVault
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface WorkerSetupOptions {
|
|
19
|
+
/** A danwo config file, relative to `cwd`; default the nearest `danwo.config.*`. */
|
|
20
|
+
readonly config?: string | undefined
|
|
21
|
+
/** An environment to start instead of the config's. */
|
|
22
|
+
readonly environment?: EnvironmentFactory | undefined
|
|
23
|
+
readonly cwd: string
|
|
24
|
+
readonly workerIndex: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Loads the project's config and starts its environment for one worker. */
|
|
28
|
+
export async function startWorkerSetup(options: WorkerSetupOptions): Promise<WorkerSetup> {
|
|
29
|
+
const loaded = await loadConfig(options.cwd, options.config)
|
|
30
|
+
const factory = options.environment ?? loaded.config.environment
|
|
31
|
+
|
|
32
|
+
if (factory === undefined) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`no danwo environment: give the danwoEnvironment option, or an environment() in ${loaded.path ?? "a danwo.config.ts"}`,
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const env = await factory({ workerIndex: options.workerIndex })
|
|
39
|
+
|
|
40
|
+
return { env, vault: new SecretVault(loaded.config.secrets) }
|
|
41
|
+
}
|