@dionlarson/playwright-orchestrator-core 1.3.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.md +190 -0
- package/README.md +279 -0
- package/dist/adapter.d.ts +20 -0
- package/dist/adapter.js +65 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +2 -0
- package/dist/commands/create-report.d.ts +2 -0
- package/dist/commands/create-report.js +18 -0
- package/dist/commands/create.d.ts +2 -0
- package/dist/commands/create.js +26 -0
- package/dist/commands/error-handler.d.ts +1 -0
- package/dist/commands/error-handler.js +28 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +14 -0
- package/dist/commands/program.d.ts +2 -0
- package/dist/commands/program.js +17 -0
- package/dist/commands/run.d.ts +2 -0
- package/dist/commands/run.js +18 -0
- package/dist/helpers/plugin.d.ts +13 -0
- package/dist/helpers/plugin.js +23 -0
- package/dist/helpers/reporter-tools.d.ts +2 -0
- package/dist/helpers/reporter-tools.js +21 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/playwright-tools/annotations.cjs +8 -0
- package/dist/playwright-tools/annotations.d.cts +3 -0
- package/dist/playwright-tools/run-builder.d.ts +15 -0
- package/dist/playwright-tools/run-builder.js +81 -0
- package/dist/playwright-tools/run-info-reporter.d.ts +4 -0
- package/dist/playwright-tools/run-info-reporter.js +7 -0
- package/dist/playwright-tools/test-ats-analyzer.d.ts +21 -0
- package/dist/playwright-tools/test-ats-analyzer.js +173 -0
- package/dist/playwright-tools/test-result-reporter.d.ts +11 -0
- package/dist/playwright-tools/test-result-reporter.js +63 -0
- package/dist/plugins-list.d.ts +1 -0
- package/dist/plugins-list.js +2 -0
- package/dist/reporters/gha-reporter.d.ts +2 -0
- package/dist/reporters/gha-reporter.js +42 -0
- package/dist/reporters/helpers.d.ts +7 -0
- package/dist/reporters/helpers.js +21 -0
- package/dist/reporters/reporter-factory.d.ts +4 -0
- package/dist/reporters/reporter-factory.js +14 -0
- package/dist/reporters/test-execution-reporter.d.ts +17 -0
- package/dist/reporters/test-execution-reporter.js +85 -0
- package/dist/test-runner.d.ts +18 -0
- package/dist/test-runner.js +111 -0
- package/dist/types/adapters.d.ts +39 -0
- package/dist/types/adapters.js +1 -0
- package/dist/types/reporter.d.ts +32 -0
- package/dist/types/reporter.js +1 -0
- package/dist/types/test-info.d.ts +42 -0
- package/dist/types/test-info.js +14 -0
- package/package.json +81 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
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
|
+
Copyright 2025 Rostyslav Kudrevatykh
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# Playwright Orchestrator
|
|
2
|
+
|
|
3
|
+
A CLI tool for orchestrating and managing Playwright test execution.
|
|
4
|
+
|
|
5
|
+
Helps to orchestrate Playwright test execution through smart sharding using existing database.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## 🎯 Overview
|
|
10
|
+
|
|
11
|
+
The project provides tooling to analyze and orchestrate Playwright tests using available storage plugin options. Currently available plugin options:
|
|
12
|
+
|
|
13
|
+
- file: Basic storage that uses a local file as storage.
|
|
14
|
+
- dynamo-db: Amazon's DynamoDB adapter.
|
|
15
|
+
- pg: PostgreSQL adapter.
|
|
16
|
+
- mysql: MySQL adapter.
|
|
17
|
+
- mongo: MongoDB adapter.
|
|
18
|
+
|
|
19
|
+
**Tests are ordered as follows:**
|
|
20
|
+
|
|
21
|
+
1. If there are no previous test runs, use the default timeout.
|
|
22
|
+
2. Take the [EMA (Exponential Moving Average)](https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average) of the test duration. The window size can be changed in [`create`](#create) command, default value is 10.
|
|
23
|
+
3. If there was a failed test in the chosen window, it is more likely to fail again. Therefore, the formula is adjusted as follows:
|
|
24
|
+
|
|
25
|
+
- Calculate the EMA of the test duration.
|
|
26
|
+
- Adjust the EMA by adding a factor based on the percentage of failed tests in the window.
|
|
27
|
+
- The final formula is: `EMA + EMA * (% of failed tests in window)`
|
|
28
|
+
|
|
29
|
+
**Example:**
|
|
30
|
+
|
|
31
|
+
- If the EMA of the test duration is 2 minutes and 4 of 10 tests in the window failed, the adjusted duration would be:
|
|
32
|
+
`2 + 2 * 0.4 = 2.8 minutes`
|
|
33
|
+
|
|
34
|
+
**Serial tests duration is a sum of all included tests.**
|
|
35
|
+
|
|
36
|
+
### Test identifiers
|
|
37
|
+
|
|
38
|
+
In order to keep history of tests, they need to be identified. There are multiple possible cases:
|
|
39
|
+
|
|
40
|
+
1. Default id: `[{project}] {file} > {title of the test}`.
|
|
41
|
+
2. Serial test id: `[{project}] {file} > {title of the parent group}`.
|
|
42
|
+
3. Serial test defined at the file level: `[{project}] {file}`.
|
|
43
|
+
4. Custom Id: `[{project}] {custom id}`.
|
|
44
|
+
|
|
45
|
+
In case some of these attributes changed, test history would be recreated. To preserve test history between changes, you can add a **static** attribute. Adding an id to an existing test would recreate the history as well.
|
|
46
|
+
|
|
47
|
+
**✅ Examples**
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
import { id } from '@playwright-orchestrator/core/annotations';
|
|
51
|
+
test('test', { annotation: id('#custom_id') }, () => {
|
|
52
|
+
// test code
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
import { id } from '@playwright-orchestrator/core/annotations';
|
|
58
|
+
test.describe('serial tests', { annotation: id('#custom_id') }, () => {
|
|
59
|
+
// test code
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**❌ This won't work**
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
import { id } from '@playwright-orchestrator/core/annotations';
|
|
67
|
+
test.describe('test', () => {
|
|
68
|
+
test.info().annotations.push(id('#custom_id'));
|
|
69
|
+
// test code
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 📦 Installation
|
|
74
|
+
|
|
75
|
+
Make sure Playwright is installed by following [Playwright's installation guide](https://playwright.dev/docs/intro#installation).
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm install @playwright-orchestrator/core --save-dev
|
|
79
|
+
|
|
80
|
+
npm install @playwright-orchestrator/<storage_plugin_name> --save-dev
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 🚀 Usage
|
|
84
|
+
|
|
85
|
+
Run the CLI tool:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npx playwright-orchestrator <command> <storage_type> [options]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 📝 Example
|
|
92
|
+
|
|
93
|
+
- [Mongo](/.github/workflows/mongo.yml)
|
|
94
|
+
|
|
95
|
+
- [DynamoDB](/.github/workflows/dynamo-db.yml)
|
|
96
|
+
|
|
97
|
+
- [PostgreSQL](/.github/workflows/pg.yml)
|
|
98
|
+
|
|
99
|
+
1. Run the `init` command. Required to run once to set up storage. Make sure that executing credentials have all permissions.
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npx playwright-orchestrator init pg --connection-string "postgres://username:password@localhost:5432/postgres"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
2. Run the `create` command. Required to run once per run.
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npx playwright-orchestrator create pg --connection-string "postgres://username:password@localhost:5432/postgres" --workers 2
|
|
109
|
+
> 019464f7-1488-75d1-b5c0-5e7d3dde9195
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
3. Start the desired count of shards using the `run` command. Run ID is generated in the previous step. All Playwright options are already saved in the previous step.
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
npx playwright-orchestrator run pg --connection-string "postgres://username:password@localhost:5432/postgres" --run-id 019464f7-1488-75d1-b5c0-5e7d3dde9195
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
4. Failed tests can be started again using step 3.
|
|
119
|
+
|
|
120
|
+
5. Merge report using [Playwright's Merge-reports CLI](https://playwright.dev/docs/test-sharding#merge-reports-cli)
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npx playwright merge-reports ./blob-reports --reporter html
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## ⚙️ Commands and Options
|
|
127
|
+
|
|
128
|
+
### `init`
|
|
129
|
+
|
|
130
|
+
Seeds data storage with necessary tables and initial configuration.
|
|
131
|
+
No additional options.
|
|
132
|
+
|
|
133
|
+
### `create`
|
|
134
|
+
|
|
135
|
+
Creates and configures a new test run. Outputs created run ID. Supports most of [playwright's options](https://playwright.dev/docs/test-cli#reference).
|
|
136
|
+
|
|
137
|
+
| Option | Description | Type | Default | Required? |
|
|
138
|
+
| ------------------ | ----------------------------------------------------------------------------------- | -------- | ------- | --------- |
|
|
139
|
+
| `--history-window` | Count of runs history kept and window for average duration. More [here](#-overview) | `number` | 10 | no |
|
|
140
|
+
|
|
141
|
+
### `run`
|
|
142
|
+
|
|
143
|
+
Starts a test shard for the provided test run. If used with a finished run, it will only start failed tests.
|
|
144
|
+
|
|
145
|
+
Command generate blob reports into `--output` directory. To merge it use [Playwright's Merge-reports CLI](https://playwright.dev/docs/test-sharding#merge-reports-cli)
|
|
146
|
+
|
|
147
|
+
**`webServer` property is not supported and is ignored; make sure the app run beforehand.**
|
|
148
|
+
|
|
149
|
+
| Option | Description | Type | Default | Required? |
|
|
150
|
+
| -------------- | ----------------------------------------- | -------- | -------------- | --------- |
|
|
151
|
+
| `--run-id` | Run ID generated by `create` command | `string` | - | yes |
|
|
152
|
+
| `-o, --output` | Directory for artifacts produced by tests | `string` | `blob_reports` | no |
|
|
153
|
+
|
|
154
|
+
### `create-report`
|
|
155
|
+
|
|
156
|
+
Generates report for provided test run id.
|
|
157
|
+
|
|
158
|
+
| Option | Description | Type | Default | Required? |
|
|
159
|
+
| ------------ | ------------------------------------ | ----------------- | ------- | --------- |
|
|
160
|
+
| `--run-id` | Run ID generated by `create` command | `string` | - | yes |
|
|
161
|
+
| `--reporter` | Type of reporter | `'json' \| 'gha'` | `json` | no |
|
|
162
|
+
|
|
163
|
+
<details>
|
|
164
|
+
<summary>GHA Report Example</summary>
|
|
165
|
+
|
|
166
|
+

|
|
167
|
+
|
|
168
|
+
</details>
|
|
169
|
+
|
|
170
|
+
## ⚙️ Subcommands and Options
|
|
171
|
+
|
|
172
|
+
Each command has corresponding subcommands for installed storages.
|
|
173
|
+
|
|
174
|
+
**Each storage option can be parsed from env variable**. For example, `table-name-prefix` -> TABLE_NAME_PREFIX.
|
|
175
|
+
|
|
176
|
+
### `file`
|
|
177
|
+
|
|
178
|
+
Use as a storage locally created file
|
|
179
|
+
|
|
180
|
+
| Option | Description | Type | Default | Required? |
|
|
181
|
+
| ------------- | -------------------------------- | -------- | --------- | --------- |
|
|
182
|
+
| `--directory` | Directory to store test run data | `string` | test-runs | no |
|
|
183
|
+
|
|
184
|
+
### `dynamo-db`
|
|
185
|
+
|
|
186
|
+
Use Amazon's DynamoDB as storage. Credentials are taken from AWS profile
|
|
187
|
+
|
|
188
|
+
| Option | Description | Type | Default | Required? |
|
|
189
|
+
| --------------------- | --------------------- | -------- | ------------------------- | --------- |
|
|
190
|
+
| `--table-name-prefix` | Table(s) name prefix | `string` | 'playwright-orchestrator' | no |
|
|
191
|
+
| `--ttl` | TTL in days | `number` | 30 | no |
|
|
192
|
+
| `--endpoint-url` | DynamoDB endpoint URL | `string` | - | no |
|
|
193
|
+
|
|
194
|
+
### `pg`
|
|
195
|
+
|
|
196
|
+
Use PostgreSQL as storage.
|
|
197
|
+
|
|
198
|
+
| Option | Description | Type | Default | Required? |
|
|
199
|
+
| --------------------- | -------------------- | -------- | ------------------------- | --------- |
|
|
200
|
+
| `--connection-string` | Connection string | `string` | - | yes |
|
|
201
|
+
| `--table-name-prefix` | Table(s) name prefix | `string` | 'playwright-orchestrator' | no |
|
|
202
|
+
| `--ssl-ca ` | SSL CA | `string` | - | no |
|
|
203
|
+
| `--ssl-cert ` | SSL certificate | `string` | - | no |
|
|
204
|
+
| `--ssl-key ` | SSL key | `string` | - | no |
|
|
205
|
+
|
|
206
|
+
### `mysql`
|
|
207
|
+
|
|
208
|
+
Use MySQL as storage.
|
|
209
|
+
|
|
210
|
+
| Option | Description | Type | Default | Required? |
|
|
211
|
+
| --------------------------------- | -------------------------------------------- | -------- | ------------------------- | --------- |
|
|
212
|
+
| `--connection-string` | Connection string | `string` | - | yes |
|
|
213
|
+
| `--table-name-prefix` | Table(s) name prefix | `string` | 'playwright-orchestrator' | no |
|
|
214
|
+
| `--ssl-profile ` | The SSL profile overrides other SSL options. | `string` | - | no |
|
|
215
|
+
| `--ssl-ca` | SSL CA | `string` | - | no |
|
|
216
|
+
| `--ssl-cert` | SSL certificate | `string` | - | no |
|
|
217
|
+
| `--ssl-key` | SSL key | `string` | - | no |
|
|
218
|
+
| `--ssl-passphrase` | SSL passphrase | `string` | - | no |
|
|
219
|
+
| `--ssl-reject-unauthorized` | SSL reject unauthorized | - | - | no |
|
|
220
|
+
| `--ssl-verify-server-certificate` | SSL verify server certificate | - | - | no |
|
|
221
|
+
|
|
222
|
+
### `mongo`
|
|
223
|
+
|
|
224
|
+
Use MongoDB as storage.
|
|
225
|
+
|
|
226
|
+
| Option | Description | Type | Default | Required? |
|
|
227
|
+
| ---------------------------------- | ------------------------------------- | -------- | ------------------------- | --------- |
|
|
228
|
+
| `--connection-string` | Connection string | `string` | - | yes |
|
|
229
|
+
| `--db` | Database name | `string` | - | yes |
|
|
230
|
+
| `--collection-name-prefix` | Table(s) name prefix | `string` | 'playwright-orchestrator' | no |
|
|
231
|
+
| `--tls` | Enable TLS | - | - | no |
|
|
232
|
+
| `--tls-ca` | SSL CA | `string` | - | no |
|
|
233
|
+
| `--tls-key` | SSL key | `string` | - | no |
|
|
234
|
+
| `--tls-key-password` | SSL key password | `string` | - | no |
|
|
235
|
+
| `--tls-passphrase` | SSL passphrase | `string` | - | no |
|
|
236
|
+
| `--tls-allow-invalid-certificates` | Allow invalid certificates | - | - | no |
|
|
237
|
+
| `--tls-allow-invalid-hostnames` | Allow invalid hostnames | - | - | no |
|
|
238
|
+
| `--tls-allow-invalid-certificates` | Allow invalid certificates | - | - | no |
|
|
239
|
+
| `--tls-insecure` | Allow insecure | - | - | no |
|
|
240
|
+
| `--debug` | Add extra fields for some collections | `string` | - | no |
|
|
241
|
+
|
|
242
|
+
## 💻 Development
|
|
243
|
+
|
|
244
|
+
Make sure podman and compose is installed. They used for tests and local development.
|
|
245
|
+
|
|
246
|
+
Build or use `npm run watch`.
|
|
247
|
+
|
|
248
|
+
Make sure you run `npm run cli-permissions` and `npm run link-packages`
|
|
249
|
+
|
|
250
|
+
See packages.json .scripts section for more commands.
|
|
251
|
+
|
|
252
|
+
## ⚖️ License
|
|
253
|
+
|
|
254
|
+
Licensed under the Apache License 2.0. See LICENSE.md for details.
|
|
255
|
+
|
|
256
|
+
## 🔮 Future plans/ideas
|
|
257
|
+
|
|
258
|
+
- ✅ ~~Tests~~
|
|
259
|
+
- ✅ ~~Better Error Handling~~
|
|
260
|
+
- ✅ ~~MySQL adapter~~
|
|
261
|
+
- ✅ ~~MongoDB adapter~~
|
|
262
|
+
- ✅ ~~Tests improvements~~
|
|
263
|
+
- ✅ ~~Better Logging~~
|
|
264
|
+
- ✅ ~~Test History statistics (test duration trends, count of test failures for past n days, etc.)~~
|
|
265
|
+
- ✅ ~~Smarter test ordering based on previous execution duration~~
|
|
266
|
+
- ✅ ~~GHA reporter~~
|
|
267
|
+
- ⬜ Redis adapter
|
|
268
|
+
- ⬜ Even more adapters (by request)
|
|
269
|
+
- ⬜ More examples
|
|
270
|
+
- ⬜ Create Documentation site.
|
|
271
|
+
- ? Restore unfinished tests in case shard terminated (Can be simply fixed by creating new run)
|
|
272
|
+
|
|
273
|
+
## ⚠️ Disclaimer
|
|
274
|
+
|
|
275
|
+
This library was created in a couple weeks of free time, so issues may occur, but I try to address them as quickly as I can. Don't hesitate to create an issue report or contribute.
|
|
276
|
+
|
|
277
|
+
## 🤝 Support
|
|
278
|
+
|
|
279
|
+
For now, the best way to support this project is to star it on GitHub and share it with your colleagues or the community.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TestItem, ResultTestParams, SaveTestRunParams, ReporterTestItem, TestSortItem, SortTestsOptions, GetTestIdParams } from './types/adapters.js';
|
|
2
|
+
import { TestRunReport } from './types/reporter.js';
|
|
3
|
+
import { TestRunConfig, TestRun } from './types/test-info.js';
|
|
4
|
+
export declare abstract class Adapter {
|
|
5
|
+
abstract getNextTest(runId: string, config: TestRunConfig): Promise<TestItem | undefined>;
|
|
6
|
+
abstract finishTest(params: ResultTestParams): Promise<void>;
|
|
7
|
+
abstract failTest(params: ResultTestParams): Promise<void>;
|
|
8
|
+
abstract saveTestRun(params: SaveTestRunParams): Promise<void>;
|
|
9
|
+
abstract initialize(): Promise<void>;
|
|
10
|
+
abstract startShard(runId: string): Promise<TestRunConfig>;
|
|
11
|
+
abstract finishShard(runId: string): Promise<void>;
|
|
12
|
+
abstract getReportData(runId: string): Promise<TestRunReport>;
|
|
13
|
+
abstract dispose(): Promise<void>;
|
|
14
|
+
protected transformTestRunToItems(run: TestRun): ReporterTestItem[];
|
|
15
|
+
protected sortTests(tests: ReporterTestItem[], testInfoMap: Map<string, TestSortItem>, { historyWindow, reverse }: SortTestsOptions): ReporterTestItem[];
|
|
16
|
+
private extractCompareValue;
|
|
17
|
+
protected validateTests(tests: ReporterTestItem[]): void;
|
|
18
|
+
protected getTestId({ project, file, title, annotations }: GetTestIdParams): string;
|
|
19
|
+
protected calculateEMA(current: number, ema: number, window: number): number;
|
|
20
|
+
}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ID_TYPE } from './playwright-tools/annotations.cjs';
|
|
2
|
+
export class Adapter {
|
|
3
|
+
transformTestRunToItems(run) {
|
|
4
|
+
const tests = Object.entries(run)
|
|
5
|
+
.flatMap(([file, tests]) => {
|
|
6
|
+
return Object.entries(tests).flatMap(([position, { timeout, projects, title, annotations }]) => {
|
|
7
|
+
return projects.flatMap((project) => {
|
|
8
|
+
const testId = this.getTestId({ project, file, title, annotations });
|
|
9
|
+
return { testId, file, position, project, timeout };
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
})
|
|
13
|
+
.map((test, i) => ({ ...test, order: i + 1 }));
|
|
14
|
+
this.validateTests(tests);
|
|
15
|
+
return tests;
|
|
16
|
+
}
|
|
17
|
+
sortTests(tests, testInfoMap, { historyWindow, reverse }) {
|
|
18
|
+
const extractValue = this.extractCompareValue.bind(this, testInfoMap, historyWindow);
|
|
19
|
+
return tests
|
|
20
|
+
.sort((a, b) => (extractValue(b) - extractValue(a)) * (reverse ? -1 : 1))
|
|
21
|
+
.map((test, i) => ({ ...test, order: i + 1 }));
|
|
22
|
+
}
|
|
23
|
+
extractCompareValue(testInfoMap, historyWindow, test) {
|
|
24
|
+
const testInfo = testInfoMap.get(test.testId);
|
|
25
|
+
let value = test.timeout;
|
|
26
|
+
if (testInfo && testInfo.ema) {
|
|
27
|
+
value = testInfo.ema;
|
|
28
|
+
}
|
|
29
|
+
const fails = testInfo?.fails ?? 0;
|
|
30
|
+
if (fails > 0) {
|
|
31
|
+
value *= fails / historyWindow + 1;
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
validateTests(tests) {
|
|
36
|
+
const existingIds = new Map();
|
|
37
|
+
for (const test of tests) {
|
|
38
|
+
if (existingIds.has(test.testId)) {
|
|
39
|
+
const existing = existingIds.get(test.testId);
|
|
40
|
+
throw new Error([
|
|
41
|
+
`Test ${existing.file}:${existing.position} has the same ID as ${test.file}:${test.position}.`,
|
|
42
|
+
'Please make sure that each test has a unique ID annotation.',
|
|
43
|
+
'If no ID annotation is provided, the `{file} > {title}` will be taken as ID.',
|
|
44
|
+
'Or file name in case test is serial at the top level.',
|
|
45
|
+
].join('\n'));
|
|
46
|
+
}
|
|
47
|
+
existingIds.set(test.testId, test);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
getTestId({ project, file, title, annotations }) {
|
|
51
|
+
const idAnnotation = annotations.find((a) => a.type === ID_TYPE);
|
|
52
|
+
if (idAnnotation)
|
|
53
|
+
return `[${project}] ${idAnnotation.description}`;
|
|
54
|
+
if (file === title)
|
|
55
|
+
return `[${project}] ${file}`;
|
|
56
|
+
return `[${project}] ${file} > ${title}`;
|
|
57
|
+
}
|
|
58
|
+
// Exponential Moving Average
|
|
59
|
+
calculateEMA(current, ema, window) {
|
|
60
|
+
if (ema === 0)
|
|
61
|
+
return current;
|
|
62
|
+
const k = 2 / (window + 1);
|
|
63
|
+
return current * k + ema * (1 - k);
|
|
64
|
+
}
|
|
65
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Option } from '@commander-js/extra-typings';
|
|
2
|
+
import { loadPlugins } from '../helpers/plugin.js';
|
|
3
|
+
import { generateReport, REPORTERS } from '../reporters/reporter-factory.js';
|
|
4
|
+
import { withErrorHandling } from './error-handler.js';
|
|
5
|
+
import { program } from './program.js';
|
|
6
|
+
export default async () => {
|
|
7
|
+
const command = program.command('create-report').description('Create for selected storage type.');
|
|
8
|
+
for await (const { factory, subCommand } of loadPlugins(command)) {
|
|
9
|
+
subCommand
|
|
10
|
+
.requiredOption('--run-id <string>', 'Run id generated by create command')
|
|
11
|
+
.addOption(new Option('--reporter <string>', 'Reporter type').choices(REPORTERS).default('json'))
|
|
12
|
+
.action(withErrorHandling(async (options) => {
|
|
13
|
+
const adapter = await factory(options);
|
|
14
|
+
await generateReport(await adapter.getReportData(options.runId), options.reporter);
|
|
15
|
+
await adapter.dispose();
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as uuid from 'uuid';
|
|
2
|
+
import { program } from './program.js';
|
|
3
|
+
import { loadRunInfo } from '../helpers/reporter-tools.js';
|
|
4
|
+
import { loadPlugins } from '../helpers/plugin.js';
|
|
5
|
+
import { withErrorHandling } from './error-handler.js';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
export default async () => {
|
|
8
|
+
const command = program
|
|
9
|
+
.command('create')
|
|
10
|
+
.description("Prepare new run configuration and fill storage. Supports all playwright's CLI options");
|
|
11
|
+
for await (const { factory, subCommand } of loadPlugins(command)) {
|
|
12
|
+
subCommand
|
|
13
|
+
.option('--history-window <number>', 'History window size', '10')
|
|
14
|
+
.allowUnknownOption()
|
|
15
|
+
.allowExcessArguments()
|
|
16
|
+
.action(withErrorHandling(async (options) => {
|
|
17
|
+
const runId = uuid.v7();
|
|
18
|
+
const args = subCommand.args.slice(subCommand.registeredArguments.length);
|
|
19
|
+
const runInfo = await loadRunInfo(args);
|
|
20
|
+
const adapter = await factory(options);
|
|
21
|
+
await adapter.saveTestRun({ runId, testRun: runInfo, args, historyWindow: +options.historyWindow });
|
|
22
|
+
await adapter.dispose();
|
|
23
|
+
console.log(chalk.green(runId));
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function withErrorHandling<T extends (...args: any[]) => Promise<any> | any>(target: T): (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>>>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { tmpdir } from 'os';
|
|
2
|
+
import { writeFile } from 'node:fs/promises';
|
|
3
|
+
import * as uuid from 'uuid';
|
|
4
|
+
import { program } from './program.js';
|
|
5
|
+
export function withErrorHandling(target) {
|
|
6
|
+
return async (...args) => {
|
|
7
|
+
try {
|
|
8
|
+
return await target(...args);
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
const logFile = `${tmpdir()}/${uuid.v4()}.log`;
|
|
12
|
+
const errorDetails = {
|
|
13
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
14
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
15
|
+
timestamp: new Date().toISOString(),
|
|
16
|
+
details: error,
|
|
17
|
+
};
|
|
18
|
+
try {
|
|
19
|
+
await writeFile(logFile, JSON.stringify(errorDetails, null, 2));
|
|
20
|
+
program.error(`Error occurred. Log file: ${logFile}\nError: ${errorDetails.message}`);
|
|
21
|
+
}
|
|
22
|
+
catch (writeError) {
|
|
23
|
+
program.error(`Failed to write error log. Original error: ${errorDetails.message}`);
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|