@planitro/playwright-reporter 0.0.0-stage → 0.1.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 +21 -0
- package/README.md +176 -2
- package/dist/core/src/automationId.d.ts +39 -0
- package/dist/core/src/automationId.js +102 -0
- package/dist/core/src/ci.d.ts +21 -0
- package/dist/core/src/ci.js +143 -0
- package/dist/core/src/http.d.ts +116 -0
- package/dist/core/src/http.js +270 -0
- package/dist/core/src/playwrightJson.d.ts +74 -0
- package/dist/core/src/playwrightJson.js +92 -0
- package/dist/core/src/results.d.ts +69 -0
- package/dist/core/src/results.js +159 -0
- package/dist/core/src/sender.d.ts +45 -0
- package/dist/core/src/sender.js +145 -0
- package/dist/core/src/steps.d.ts +48 -0
- package/dist/core/src/steps.js +482 -0
- package/dist/playwright-reporter/src/index.d.ts +95 -0
- package/dist/playwright-reporter/src/index.js +269 -0
- package/package.json +41 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Snowy Fox Studios
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,177 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @planitro/playwright-reporter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A [Playwright](https://playwright.dev) reporter that sends your test results to **Planitro Tests**
|
|
4
|
+
(the test-management plugin of [Planitro](https://planitro.app)). Every automated test becomes a test
|
|
5
|
+
case in Planitro (created the first time it is seen), and every CI run becomes a test run with pass /
|
|
6
|
+
fail / skip / flaky results, errors, and screenshots, traces and videos of failures.
|
|
7
|
+
|
|
8
|
+
- Zero runtime dependencies (Node 18+ `fetch`).
|
|
9
|
+
- **Never fails your test run**: if Planitro is down or misconfigured you get a one-line warning and
|
|
10
|
+
your exit code is unchanged.
|
|
11
|
+
- Safe to always list in your config: with no URL or API key it is disabled (one info line).
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install --save-dev @planitro/playwright-reporter
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Create an API key in Planitro: the project's **Tests → API keys** settings (scope `tests:write`). The Tests
|
|
20
|
+
plugin must be enabled and the project owner on the Team plan.
|
|
21
|
+
|
|
22
|
+
## Configure
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
// playwright.config.ts
|
|
26
|
+
import { defineConfig } from "@playwright/test";
|
|
27
|
+
|
|
28
|
+
export default defineConfig({
|
|
29
|
+
reporter: [
|
|
30
|
+
["list"],
|
|
31
|
+
["@planitro/playwright-reporter", { release: "v1.8.0" }],
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Then provide the URL and key through the environment (keep the key in a CI secret):
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
PLANITRO_URL=https://planitro.app PLANITRO_API_KEY=pltr_… npx playwright test
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
If your CI passes `--reporter` on the command line (which replaces the config's list), add it there:
|
|
43
|
+
`npx playwright test --reporter=list,html,@planitro/playwright-reporter`.
|
|
44
|
+
|
|
45
|
+
### Options
|
|
46
|
+
|
|
47
|
+
Options in the config win over environment variables.
|
|
48
|
+
|
|
49
|
+
| Option | Env | Default | |
|
|
50
|
+
|---|---|---|---|
|
|
51
|
+
| `url` | `PLANITRO_URL` | — | Planitro base URL, e.g. `https://planitro.app` (self-hosted/local: `http://localhost:8081`) |
|
|
52
|
+
| `apiKey` | `PLANITRO_API_KEY` | — | Project API key `pltr_…` |
|
|
53
|
+
| `runName` | `PLANITRO_RUN_NAME` | `<branch> · <short sha>`, else `Local run <date>` | Run name |
|
|
54
|
+
| `release` | `PLANITRO_RELEASE` | — | Release name (`v1.8.0`) or id; unknown releases are ignored |
|
|
55
|
+
| `autoCreate` | `PLANITRO_AUTO_CREATE` | `true` | Create cases for tests Planitro does not know yet |
|
|
56
|
+
| `runId` | `PLANITRO_RUN_ID` | — | Report into an existing run and leave it open (sharding, below) |
|
|
57
|
+
| `uploadAttachments` | `PLANITRO_UPLOAD_ATTACHMENTS` | `"failures"` | `"failures"`, `"all"` or `"none"`: screenshots / traces / videos (image/*, video/*, zip) |
|
|
58
|
+
| `batchSize` | | `50` | Results per request (max 500) |
|
|
59
|
+
| `flushIntervalMs` | | `2000` | Send queued results at least this often |
|
|
60
|
+
| `endTimeoutMs` | | `60000` | How long the end of the run waits for uploads |
|
|
61
|
+
| `retries` | | `3` | HTTP retries on network errors, 429 and 5xx (exponential backoff) |
|
|
62
|
+
|
|
63
|
+
Set `PLANITRO_DEBUG=1` for verbose logs. The API key is never printed.
|
|
64
|
+
|
|
65
|
+
## What gets reported
|
|
66
|
+
|
|
67
|
+
- **Run**: created when the first test starts (so `--list` or an empty run creates nothing), with build,
|
|
68
|
+
commit, branch and CI URL detected from GitHub Actions, GitLab CI, CircleCI, Jenkins, Azure Pipelines or
|
|
69
|
+
generic `CI_COMMIT_SHA` / `BRANCH_NAME` / `BUILD_NUMBER` / `BUILD_URL`, falling back to `git rev-parse`.
|
|
70
|
+
At the end it is completed and one line is printed: `Planitro: run <url> — X passed, Y failed`.
|
|
71
|
+
- **One result per test, final attempt only.** With retries, earlier failed attempts are not sent; the
|
|
72
|
+
result carries `retries` = the attempt number, so "failed then passed" shows as **flaky**.
|
|
73
|
+
- **Status** follows Playwright's outcome: expected and flaky → passed, unexpected → failed, skipped →
|
|
74
|
+
skipped. A `test.fail()` test that fails is therefore *passed*.
|
|
75
|
+
- **Case identity (`automation_id`)**: `<file relative to testDir> › <describe…> › <title>`, e.g.
|
|
76
|
+
`issues/modal.spec.ts › Issue modal › opens`. The Playwright project name is **not** part of it.
|
|
77
|
+
- **Linking to an existing case**: put its key in the title, e.g. `test("opens @PTR-T12", …)` or
|
|
78
|
+
`{ tag: "@PTR-T12" }`. The tag is stripped from the automation_id and sent in `tags`, and Planitro
|
|
79
|
+
links the test to that case.
|
|
80
|
+
- **Tags** (`test.tags`: `{ tag: "@smoke" }` on a test or a describe, and `@smoke` written in a title) are
|
|
81
|
+
sent with every result. Planitro adds them to the case as `smoke` (no `@`, lowercase), with a robot icon,
|
|
82
|
+
and keeps them in sync: remove the tag in code and it leaves the case on the next run. Tags added by hand
|
|
83
|
+
in Planitro are never touched. Case keys like `@PTR-T12` only link and never become tags.
|
|
84
|
+
- **Prefer `{ tag: "@smoke" }` over a tag in the title.** Playwright keeps title text as is, and so does
|
|
85
|
+
the automation_id (only `@PTR-T12` keys are stripped), so adding `@smoke` to a title gives the test a new
|
|
86
|
+
automation_id: Planitro creates a new case and the old one goes stale (merge them from the case panel,
|
|
87
|
+
or link with `@PTR-T12`). The `tag` option leaves the automation_id alone.
|
|
88
|
+
- **Steps**: for passed tests the reporter also sends readable `steps` and `expected` lines, and Planitro
|
|
89
|
+
fills them into the case's Steps / Expected result (unless someone wrote the steps by hand in Planitro).
|
|
90
|
+
Use `test.step("Log in", …)` for the best result: the step titles become the steps (nested steps get
|
|
91
|
+
a "– " prefix). Otherwise the action log is used: `Navigate to`/`Click`/`Fill`/`Check`/… become steps like
|
|
92
|
+
`Click the "Save" button`, and assertions become expected results like `"Saved" is visible`. Hooks,
|
|
93
|
+
fixtures and API calls are left out (API setup becomes one "Set up test data (N API calls)" line);
|
|
94
|
+
at most 30 steps and 15 expected results.
|
|
95
|
+
- **Several Playwright projects** (chromium + firefox) produce the same automation_id, so they share
|
|
96
|
+
one case: the run keeps the **worst** status (failed > passed > skipped). If chromium passes and
|
|
97
|
+
firefox fails, the case is failed in that run.
|
|
98
|
+
- **Attachments** of failed tests (default) are uploaded one file per request; files over 50 MB and
|
|
99
|
+
missing files are skipped.
|
|
100
|
+
|
|
101
|
+
## Smoke runs (only some tests)
|
|
102
|
+
|
|
103
|
+
Filter with Playwright as usual; only the tests that ran are reported, so the run holds just them.
|
|
104
|
+
Give it a name that says what it is:
|
|
105
|
+
|
|
106
|
+
```yaml
|
|
107
|
+
- run: npx playwright test --grep @smoke
|
|
108
|
+
env:
|
|
109
|
+
PLANITRO_URL: https://planitro.app
|
|
110
|
+
PLANITRO_API_KEY: ${{ secrets.PLANITRO_API_KEY }}
|
|
111
|
+
PLANITRO_RUN_NAME: smoke · ${{ github.sha }}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Tests that did not run are left out of the run (they don't count as untested or failed) and they don't
|
|
115
|
+
lose their tags. In Planitro, filter the case list by the `smoke` tag (or the **Smoke** quick filter), or
|
|
116
|
+
start a manual run with the `smoke` tag.
|
|
117
|
+
|
|
118
|
+
## Sharded CI
|
|
119
|
+
|
|
120
|
+
Create the run once, let every shard report into it, then complete it:
|
|
121
|
+
|
|
122
|
+
```yaml
|
|
123
|
+
jobs:
|
|
124
|
+
create-run:
|
|
125
|
+
runs-on: ubuntu-latest
|
|
126
|
+
outputs:
|
|
127
|
+
run_id: ${{ steps.run.outputs.id }}
|
|
128
|
+
steps:
|
|
129
|
+
- id: run
|
|
130
|
+
run: echo "id=$(npx -y @planitro/cli run create)" >> "$GITHUB_OUTPUT"
|
|
131
|
+
env:
|
|
132
|
+
PLANITRO_URL: https://planitro.app
|
|
133
|
+
PLANITRO_API_KEY: ${{ secrets.PLANITRO_API_KEY }}
|
|
134
|
+
|
|
135
|
+
test:
|
|
136
|
+
needs: create-run
|
|
137
|
+
strategy:
|
|
138
|
+
matrix:
|
|
139
|
+
shard: [1, 2, 3, 4]
|
|
140
|
+
steps:
|
|
141
|
+
# … checkout, npm ci, playwright install …
|
|
142
|
+
- run: npx playwright test --shard=${{ matrix.shard }}/4
|
|
143
|
+
env:
|
|
144
|
+
PLANITRO_URL: https://planitro.app
|
|
145
|
+
PLANITRO_API_KEY: ${{ secrets.PLANITRO_API_KEY }}
|
|
146
|
+
PLANITRO_RUN_ID: ${{ needs.create-run.outputs.run_id }}
|
|
147
|
+
|
|
148
|
+
complete-run:
|
|
149
|
+
needs: [create-run, test]
|
|
150
|
+
if: always()
|
|
151
|
+
steps:
|
|
152
|
+
- run: npx -y @planitro/cli run complete ${{ needs.create-run.outputs.run_id }}
|
|
153
|
+
env:
|
|
154
|
+
PLANITRO_URL: https://planitro.app
|
|
155
|
+
PLANITRO_API_KEY: ${{ secrets.PLANITRO_API_KEY }}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
With `PLANITRO_RUN_ID` set, the reporter does not create or complete a run. If the same test ends up
|
|
159
|
+
in two shards (it should not), the server keeps the last result posted. If `run create` fails it prints
|
|
160
|
+
nothing, `PLANITRO_RUN_ID` is empty, and each shard creates its own run instead.
|
|
161
|
+
|
|
162
|
+
## Replaying a JSON report
|
|
163
|
+
|
|
164
|
+
Already have `results.json` from `--reporter=json`? Upload it with the CLI, same rules:
|
|
165
|
+
`npx @planitro/cli upload results.json`.
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
MIT
|
|
170
|
+
|
|
171
|
+
## Security
|
|
172
|
+
|
|
173
|
+
- The API key is sent only in the `Authorization` header, only to `PLANITRO_URL`, and never logged. Keep it in your CI's secret store.
|
|
174
|
+
- Redirects are never followed, so the key can't be forwarded to another host. If your URL redirects, the run stops with a message naming the final address to use.
|
|
175
|
+
- A plain `http://` URL that isn't localhost triggers a warning: the key would travel unencrypted.
|
|
176
|
+
- Use a key with only the scopes you need (`tests:write` for reporting). Revoke it in Project Settings → API keys if it leaks.
|
|
177
|
+
- No install scripts and no runtime dependencies.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* automation_id rules (see docs/technical/test-management.md, "automation_id conventions").
|
|
3
|
+
*
|
|
4
|
+
* Playwright: `<file relative to testDir, forward slashes> › <describe titles…> › <test title>`, with any
|
|
5
|
+
* `@<CODE>-T<n>` case tags stripped from the titles. The Playwright project name is never included.
|
|
6
|
+
* JUnit: `<classname> › <name>`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const SEPARATOR = " \u203A ";
|
|
9
|
+
/** Every `@CODE-T<n>` token found in a title, in order, without duplicates. */
|
|
10
|
+
export declare function extractCaseTags(title: string): string[];
|
|
11
|
+
/** Removes `@CODE-T<n>` tokens from a title and tidies the whitespace left behind. */
|
|
12
|
+
export declare function stripCaseTags(title: string): string;
|
|
13
|
+
/** Backslashes to forward slashes, no leading `./`. */
|
|
14
|
+
export declare function toPosixPath(p: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* `file` relative to `baseDir`, with forward slashes. Pure string logic so a report produced on Windows can be
|
|
17
|
+
* replayed on Linux and vice versa. Comparison is case-insensitive when either side looks like a Windows path.
|
|
18
|
+
* When `file` is not under `baseDir`, it is returned unchanged (normalised).
|
|
19
|
+
*/
|
|
20
|
+
export declare function relativePosix(file: string, baseDir: string | undefined): string;
|
|
21
|
+
/** Joins already-relative path parts with `/`. */
|
|
22
|
+
export declare function joinPosix(...parts: string[]): string;
|
|
23
|
+
export interface PlaywrightIdParts {
|
|
24
|
+
/** automation_id sent to the server. */
|
|
25
|
+
automationId: string;
|
|
26
|
+
/** Test title with case tags stripped. */
|
|
27
|
+
title: string;
|
|
28
|
+
/** `[file, ...describes]` (describe titles stripped of case tags; empty ones dropped). */
|
|
29
|
+
suitePath: string[];
|
|
30
|
+
}
|
|
31
|
+
/** Builds the automation_id, title and suite_path for a Playwright test. */
|
|
32
|
+
export declare function buildPlaywrightId(relativeFile: string, describes: string[], testTitle: string): PlaywrightIdParts;
|
|
33
|
+
/** automation_id for a JUnit testcase. */
|
|
34
|
+
export declare function buildJunitId(classname: string, name: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Tags to send for a test: Playwright's own tags (`@smoke`, normalised to start with `@`) plus any `@CODE-T<n>`
|
|
37
|
+
* tokens found in the title chain. Duplicates removed, order kept.
|
|
38
|
+
*/
|
|
39
|
+
export declare function buildTags(tags: readonly string[] | undefined, titles: readonly string[]): string[];
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* automation_id rules (see docs/technical/test-management.md, "automation_id conventions").
|
|
4
|
+
*
|
|
5
|
+
* Playwright: `<file relative to testDir, forward slashes> › <describe titles…> › <test title>`, with any
|
|
6
|
+
* `@<CODE>-T<n>` case tags stripped from the titles. The Playwright project name is never included.
|
|
7
|
+
* JUnit: `<classname> › <name>`.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SEPARATOR = void 0;
|
|
11
|
+
exports.extractCaseTags = extractCaseTags;
|
|
12
|
+
exports.stripCaseTags = stripCaseTags;
|
|
13
|
+
exports.toPosixPath = toPosixPath;
|
|
14
|
+
exports.relativePosix = relativePosix;
|
|
15
|
+
exports.joinPosix = joinPosix;
|
|
16
|
+
exports.buildPlaywrightId = buildPlaywrightId;
|
|
17
|
+
exports.buildJunitId = buildJunitId;
|
|
18
|
+
exports.buildTags = buildTags;
|
|
19
|
+
exports.SEPARATOR = " › ";
|
|
20
|
+
/** Matches a case key tag such as `@PTR-T01` (same key shape the server parses: `^([A-Z0-9]+)-T(\d+)$`). */
|
|
21
|
+
const CASE_TAG_SOURCE = "@([A-Z0-9]+)-T(\\d+)(?![A-Za-z0-9_])";
|
|
22
|
+
/** Every `@CODE-T<n>` token found in a title, in order, without duplicates. */
|
|
23
|
+
function extractCaseTags(title) {
|
|
24
|
+
const out = [];
|
|
25
|
+
const re = new RegExp(CASE_TAG_SOURCE, "g");
|
|
26
|
+
let m;
|
|
27
|
+
while ((m = re.exec(title)) !== null) {
|
|
28
|
+
if (!out.includes(m[0]))
|
|
29
|
+
out.push(m[0]);
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
/** Removes `@CODE-T<n>` tokens from a title and tidies the whitespace left behind. */
|
|
34
|
+
function stripCaseTags(title) {
|
|
35
|
+
return title
|
|
36
|
+
.replace(new RegExp(CASE_TAG_SOURCE, "g"), "")
|
|
37
|
+
.replace(/\s{2,}/g, " ")
|
|
38
|
+
.trim();
|
|
39
|
+
}
|
|
40
|
+
/** Backslashes to forward slashes, no leading `./`. */
|
|
41
|
+
function toPosixPath(p) {
|
|
42
|
+
return p.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* `file` relative to `baseDir`, with forward slashes. Pure string logic so a report produced on Windows can be
|
|
46
|
+
* replayed on Linux and vice versa. Comparison is case-insensitive when either side looks like a Windows path.
|
|
47
|
+
* When `file` is not under `baseDir`, it is returned unchanged (normalised).
|
|
48
|
+
*/
|
|
49
|
+
function relativePosix(file, baseDir) {
|
|
50
|
+
const f = toPosixPath(file);
|
|
51
|
+
if (!baseDir)
|
|
52
|
+
return f;
|
|
53
|
+
let base = toPosixPath(baseDir).replace(/\/+$/, "");
|
|
54
|
+
if (!base)
|
|
55
|
+
return f;
|
|
56
|
+
const windowsish = /^[A-Za-z]:\//.test(f) || /^[A-Za-z]:\//.test(base);
|
|
57
|
+
const fc = windowsish ? f.toLowerCase() : f;
|
|
58
|
+
const bc = windowsish ? base.toLowerCase() : base;
|
|
59
|
+
if (fc.startsWith(bc + "/"))
|
|
60
|
+
return f.slice(base.length + 1);
|
|
61
|
+
return f;
|
|
62
|
+
}
|
|
63
|
+
/** Joins already-relative path parts with `/`. */
|
|
64
|
+
function joinPosix(...parts) {
|
|
65
|
+
return parts
|
|
66
|
+
.map((p) => toPosixPath(p).replace(/^\/+|\/+$/g, ""))
|
|
67
|
+
.filter(Boolean)
|
|
68
|
+
.join("/");
|
|
69
|
+
}
|
|
70
|
+
/** Builds the automation_id, title and suite_path for a Playwright test. */
|
|
71
|
+
function buildPlaywrightId(relativeFile, describes, testTitle) {
|
|
72
|
+
const file = toPosixPath(relativeFile);
|
|
73
|
+
const cleanDescribes = describes.map(stripCaseTags).filter((d) => d.length > 0);
|
|
74
|
+
const title = stripCaseTags(testTitle);
|
|
75
|
+
return {
|
|
76
|
+
automationId: [file, ...cleanDescribes, title].join(exports.SEPARATOR),
|
|
77
|
+
title,
|
|
78
|
+
suitePath: [file, ...cleanDescribes],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** automation_id for a JUnit testcase. */
|
|
82
|
+
function buildJunitId(classname, name) {
|
|
83
|
+
return classname ? `${classname}${exports.SEPARATOR}${name}` : name;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Tags to send for a test: Playwright's own tags (`@smoke`, normalised to start with `@`) plus any `@CODE-T<n>`
|
|
87
|
+
* tokens found in the title chain. Duplicates removed, order kept.
|
|
88
|
+
*/
|
|
89
|
+
function buildTags(tags, titles) {
|
|
90
|
+
const out = [];
|
|
91
|
+
const add = (t) => {
|
|
92
|
+
const v = t.startsWith("@") ? t : `@${t}`;
|
|
93
|
+
if (v.length > 1 && !out.includes(v))
|
|
94
|
+
out.push(v);
|
|
95
|
+
};
|
|
96
|
+
for (const t of tags ?? [])
|
|
97
|
+
add(t);
|
|
98
|
+
for (const title of titles)
|
|
99
|
+
for (const t of extractCaseTags(title))
|
|
100
|
+
add(t);
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Build metadata sent with `POST /api/v1/tests/runs`. Empty fields are omitted. */
|
|
2
|
+
export interface CiInfo {
|
|
3
|
+
provider: string;
|
|
4
|
+
build?: string;
|
|
5
|
+
commit?: string;
|
|
6
|
+
branch?: string;
|
|
7
|
+
ci_url?: string;
|
|
8
|
+
}
|
|
9
|
+
export type Env = Record<string, string | undefined>;
|
|
10
|
+
export type GitRunner = (args: string[]) => string | undefined;
|
|
11
|
+
/** `refs/heads/main` → `main`, `refs/pull/12/merge` → `pull/12/merge`. */
|
|
12
|
+
export declare function cleanBranch(ref: string | undefined): string | undefined;
|
|
13
|
+
/** Runs `git <args>` in the cwd; returns trimmed stdout or undefined on any error. */
|
|
14
|
+
export declare const defaultGit: GitRunner;
|
|
15
|
+
/**
|
|
16
|
+
* Detects build/commit/branch/CI URL from the environment of the common CI providers, then falls back to the
|
|
17
|
+
* local git checkout (`git rev-parse`) for whatever is still missing. Never throws.
|
|
18
|
+
*/
|
|
19
|
+
export declare function detectCi(env?: Env, git?: GitRunner): CiInfo;
|
|
20
|
+
/** `<branch> · <short sha>`, or whichever of the two is known, or `Local run YYYY-MM-DD HH:MM`. */
|
|
21
|
+
export declare function defaultRunName(info: Pick<CiInfo, "branch" | "commit">, now?: Date): string;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultGit = void 0;
|
|
4
|
+
exports.cleanBranch = cleanBranch;
|
|
5
|
+
exports.detectCi = detectCi;
|
|
6
|
+
exports.defaultRunName = defaultRunName;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
function v(env, ...names) {
|
|
9
|
+
for (const n of names) {
|
|
10
|
+
const val = env[n];
|
|
11
|
+
if (val && val.trim())
|
|
12
|
+
return val.trim();
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
/** `refs/heads/main` → `main`, `refs/pull/12/merge` → `pull/12/merge`. */
|
|
17
|
+
function cleanBranch(ref) {
|
|
18
|
+
if (!ref)
|
|
19
|
+
return undefined;
|
|
20
|
+
const b = ref.replace(/^refs\/heads\//, "").replace(/^refs\//, "").replace(/^origin\//, "");
|
|
21
|
+
return b || undefined;
|
|
22
|
+
}
|
|
23
|
+
/** Runs `git <args>` in the cwd; returns trimmed stdout or undefined on any error. */
|
|
24
|
+
const defaultGit = (args) => {
|
|
25
|
+
try {
|
|
26
|
+
const out = (0, child_process_1.execFileSync)("git", args, {
|
|
27
|
+
encoding: "utf8",
|
|
28
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
29
|
+
timeout: 3000,
|
|
30
|
+
windowsHide: true,
|
|
31
|
+
});
|
|
32
|
+
const t = out.trim();
|
|
33
|
+
return t || undefined;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.defaultGit = defaultGit;
|
|
40
|
+
function compact(info) {
|
|
41
|
+
const out = { provider: info.provider };
|
|
42
|
+
if (info.build)
|
|
43
|
+
out.build = info.build;
|
|
44
|
+
if (info.commit)
|
|
45
|
+
out.commit = info.commit;
|
|
46
|
+
const branch = cleanBranch(info.branch);
|
|
47
|
+
if (branch)
|
|
48
|
+
out.branch = branch;
|
|
49
|
+
if (info.ci_url)
|
|
50
|
+
out.ci_url = info.ci_url;
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Detects build/commit/branch/CI URL from the environment of the common CI providers, then falls back to the
|
|
55
|
+
* local git checkout (`git rev-parse`) for whatever is still missing. Never throws.
|
|
56
|
+
*/
|
|
57
|
+
function detectCi(env = process.env, git = exports.defaultGit) {
|
|
58
|
+
let info;
|
|
59
|
+
if (env.GITHUB_ACTIONS === "true" || env.GITHUB_RUN_ID) {
|
|
60
|
+
const server = v(env, "GITHUB_SERVER_URL") ?? "https://github.com";
|
|
61
|
+
const repo = v(env, "GITHUB_REPOSITORY");
|
|
62
|
+
const runId = v(env, "GITHUB_RUN_ID");
|
|
63
|
+
info = {
|
|
64
|
+
provider: "github",
|
|
65
|
+
build: runId,
|
|
66
|
+
commit: v(env, "GITHUB_SHA"),
|
|
67
|
+
branch: v(env, "GITHUB_HEAD_REF", "GITHUB_REF_NAME", "GITHUB_REF"),
|
|
68
|
+
ci_url: repo && runId ? `${server.replace(/\/+$/, "")}/${repo}/actions/runs/${runId}` : undefined,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
else if (env.GITLAB_CI) {
|
|
72
|
+
info = {
|
|
73
|
+
provider: "gitlab",
|
|
74
|
+
build: v(env, "CI_PIPELINE_ID", "CI_JOB_ID"),
|
|
75
|
+
commit: v(env, "CI_COMMIT_SHA"),
|
|
76
|
+
branch: v(env, "CI_MERGE_REQUEST_SOURCE_BRANCH_NAME", "CI_COMMIT_REF_NAME", "CI_COMMIT_BRANCH"),
|
|
77
|
+
ci_url: v(env, "CI_PIPELINE_URL", "CI_JOB_URL"),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
else if (env.CIRCLECI) {
|
|
81
|
+
info = {
|
|
82
|
+
provider: "circleci",
|
|
83
|
+
build: v(env, "CIRCLE_BUILD_NUM", "CIRCLE_WORKFLOW_ID"),
|
|
84
|
+
commit: v(env, "CIRCLE_SHA1"),
|
|
85
|
+
branch: v(env, "CIRCLE_BRANCH"),
|
|
86
|
+
ci_url: v(env, "CIRCLE_BUILD_URL"),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
else if (env.JENKINS_URL || env.JENKINS_HOME) {
|
|
90
|
+
info = {
|
|
91
|
+
provider: "jenkins",
|
|
92
|
+
build: v(env, "BUILD_NUMBER", "BUILD_ID"),
|
|
93
|
+
commit: v(env, "GIT_COMMIT"),
|
|
94
|
+
branch: v(env, "CHANGE_BRANCH", "BRANCH_NAME", "GIT_BRANCH"),
|
|
95
|
+
ci_url: v(env, "BUILD_URL"),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
else if (env.TF_BUILD) {
|
|
99
|
+
const collection = v(env, "SYSTEM_COLLECTIONURI");
|
|
100
|
+
const project = v(env, "SYSTEM_TEAMPROJECT");
|
|
101
|
+
const buildId = v(env, "BUILD_BUILDID");
|
|
102
|
+
info = {
|
|
103
|
+
provider: "azure",
|
|
104
|
+
build: v(env, "BUILD_BUILDNUMBER", "BUILD_BUILDID"),
|
|
105
|
+
commit: v(env, "BUILD_SOURCEVERSION"),
|
|
106
|
+
branch: v(env, "SYSTEM_PULLREQUEST_SOURCEBRANCH", "BUILD_SOURCEBRANCH", "BUILD_SOURCEBRANCHNAME"),
|
|
107
|
+
ci_url: collection && project && buildId
|
|
108
|
+
? `${collection.replace(/\/?$/, "/")}${encodeURIComponent(project)}/_build/results?buildId=${buildId}`
|
|
109
|
+
: undefined,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
info = {
|
|
114
|
+
provider: env.CI ? "ci" : "local",
|
|
115
|
+
build: v(env, "BUILD_NUMBER", "BUILD_ID", "CI_BUILD_NUMBER"),
|
|
116
|
+
commit: v(env, "CI_COMMIT_SHA", "COMMIT_SHA", "GIT_COMMIT"),
|
|
117
|
+
branch: v(env, "BRANCH_NAME", "CI_BRANCH", "GIT_BRANCH"),
|
|
118
|
+
ci_url: v(env, "BUILD_URL", "CI_BUILD_URL"),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (!info.commit)
|
|
122
|
+
info.commit = git(["rev-parse", "HEAD"]);
|
|
123
|
+
if (!info.branch) {
|
|
124
|
+
const b = git(["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
125
|
+
if (b && b !== "HEAD")
|
|
126
|
+
info.branch = b;
|
|
127
|
+
}
|
|
128
|
+
return compact(info);
|
|
129
|
+
}
|
|
130
|
+
function pad(n) {
|
|
131
|
+
return String(n).padStart(2, "0");
|
|
132
|
+
}
|
|
133
|
+
/** `<branch> · <short sha>`, or whichever of the two is known, or `Local run YYYY-MM-DD HH:MM`. */
|
|
134
|
+
function defaultRunName(info, now = new Date()) {
|
|
135
|
+
const short = info.commit ? info.commit.slice(0, 7) : undefined;
|
|
136
|
+
if (info.branch && short)
|
|
137
|
+
return `${info.branch} · ${short}`;
|
|
138
|
+
if (info.branch)
|
|
139
|
+
return info.branch;
|
|
140
|
+
if (short)
|
|
141
|
+
return short;
|
|
142
|
+
return `Local run ${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}`;
|
|
143
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { LocalAttachment, ResultPayload } from "./results";
|
|
2
|
+
/** Minimal logger; every line is prefixed with `Planitro: ` by the caller's implementation. */
|
|
3
|
+
export interface Logger {
|
|
4
|
+
info(msg: string): void;
|
|
5
|
+
warn(msg: string): void;
|
|
6
|
+
debug?(msg: string): void;
|
|
7
|
+
}
|
|
8
|
+
export declare const consoleLogger: Logger;
|
|
9
|
+
export declare class PlanitroError extends Error {
|
|
10
|
+
readonly status?: number | undefined;
|
|
11
|
+
readonly code?: string | undefined;
|
|
12
|
+
constructor(message: string, status?: number | undefined, code?: string | undefined);
|
|
13
|
+
/** Auth / plan / permission problems: retrying or sending more will not help. */
|
|
14
|
+
get fatal(): boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface ClientOptions {
|
|
17
|
+
url: string;
|
|
18
|
+
apiKey: string;
|
|
19
|
+
/** Retries on network errors, 429 and 5xx. Default 3 (i.e. up to 4 attempts). */
|
|
20
|
+
retries?: number;
|
|
21
|
+
/** First backoff delay; doubles on each retry. Default 500 ms. */
|
|
22
|
+
backoffMs?: number;
|
|
23
|
+
/** Per-request timeout. Default 30 s (uploads 120 s). */
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
userAgent?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface CreateRunBody {
|
|
28
|
+
name: string;
|
|
29
|
+
release?: string;
|
|
30
|
+
build?: string;
|
|
31
|
+
commit?: string;
|
|
32
|
+
branch?: string;
|
|
33
|
+
ci_url?: string;
|
|
34
|
+
/** Original start (ISO 8601) when uploading a run that already happened. */
|
|
35
|
+
started_at?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface CreateRunResponse {
|
|
38
|
+
run_id: number;
|
|
39
|
+
url?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ResultsResponse {
|
|
42
|
+
results: Array<{
|
|
43
|
+
automation_id: string;
|
|
44
|
+
case_key?: string;
|
|
45
|
+
case_id?: number;
|
|
46
|
+
result_id: number;
|
|
47
|
+
created?: boolean;
|
|
48
|
+
}>;
|
|
49
|
+
unmatched?: string[];
|
|
50
|
+
}
|
|
51
|
+
export interface RunSummary {
|
|
52
|
+
total?: number;
|
|
53
|
+
passed?: number;
|
|
54
|
+
failed?: number;
|
|
55
|
+
blocked?: number;
|
|
56
|
+
skipped?: number;
|
|
57
|
+
untested?: number;
|
|
58
|
+
flaky?: number;
|
|
59
|
+
pass_rate?: number;
|
|
60
|
+
duration_ms?: number;
|
|
61
|
+
}
|
|
62
|
+
export interface TestRunResponse {
|
|
63
|
+
id?: number;
|
|
64
|
+
name?: string;
|
|
65
|
+
url?: string;
|
|
66
|
+
summary?: RunSummary;
|
|
67
|
+
[k: string]: unknown;
|
|
68
|
+
}
|
|
69
|
+
export interface ProjectResponse {
|
|
70
|
+
project_id: number;
|
|
71
|
+
code: string;
|
|
72
|
+
name: string;
|
|
73
|
+
plugin_enabled: boolean;
|
|
74
|
+
}
|
|
75
|
+
/** Accepts `https://planitro.app`, `https://planitro.app/`, `…/api/v1` or `…/api/v1/tests`. */
|
|
76
|
+
export declare function normalizeBaseUrl(url: string): string;
|
|
77
|
+
/** True for plain-http URLs that are not on this machine (the key would travel unencrypted). */
|
|
78
|
+
export declare function isInsecureUrl(url: string): boolean;
|
|
79
|
+
/** HTTP client for the public `/api/v1/tests` API. Uses Node 18+ global fetch/FormData/Blob; zero deps. */
|
|
80
|
+
export declare class PlanitroClient {
|
|
81
|
+
readonly baseUrl: string;
|
|
82
|
+
private readonly apiKey;
|
|
83
|
+
private readonly retries;
|
|
84
|
+
private readonly backoffMs;
|
|
85
|
+
private readonly timeoutMs;
|
|
86
|
+
private readonly userAgent;
|
|
87
|
+
constructor(opts: ClientOptions);
|
|
88
|
+
/** Makes a request, retrying transient failures. Throws PlanitroError (never includes the API key). */
|
|
89
|
+
request<T>(method: string, apiPath: string, body?: {
|
|
90
|
+
json?: unknown;
|
|
91
|
+
form?: () => FormData;
|
|
92
|
+
}, timeoutMs?: number): Promise<T>;
|
|
93
|
+
project(): Promise<ProjectResponse>;
|
|
94
|
+
createRun(body: CreateRunBody): Promise<CreateRunResponse>;
|
|
95
|
+
postResults(runId: number | string, results: ResultPayload[], autoCreate: boolean): Promise<ResultsResponse>;
|
|
96
|
+
/** `timing` keeps the original end of a run that already happened (uploads/replays). */
|
|
97
|
+
completeRun(runId: number | string, timing?: {
|
|
98
|
+
durationMs?: number;
|
|
99
|
+
completedAt?: string;
|
|
100
|
+
}): Promise<TestRunResponse>;
|
|
101
|
+
/** Uploads one file. Returns false (without calling the server) when it is missing or larger than 50 MB. */
|
|
102
|
+
uploadAttachment(runId: number | string, resultId: number | string, att: LocalAttachment, log?: Logger): Promise<boolean>;
|
|
103
|
+
/** `POST /runs/junit` — files are read up front; the server creates and completes the run. */
|
|
104
|
+
uploadJunit(files: string[], fields: Record<string, string | boolean | undefined>): Promise<TestRunResponse & {
|
|
105
|
+
run_id?: number;
|
|
106
|
+
}>;
|
|
107
|
+
}
|
|
108
|
+
/** Runs async jobs one after another; never rejects. Used to keep result posts ordered. */
|
|
109
|
+
export declare class SerialQueue {
|
|
110
|
+
private tail;
|
|
111
|
+
private pending;
|
|
112
|
+
push(job: () => Promise<void>): Promise<void>;
|
|
113
|
+
get size(): number;
|
|
114
|
+
/** Resolves when everything queued so far (and anything queued while waiting) is done. */
|
|
115
|
+
idle(): Promise<void>;
|
|
116
|
+
}
|