@sentinelqa/playwright 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 +54 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +84 -0
- package/dist/reporter.d.ts +17 -0
- package/dist/reporter.js +56 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) SentinelQA
|
|
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
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @sentinelqa/playwright
|
|
2
|
+
|
|
3
|
+
Playwright config wrapper and reporter for SentinelQA.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i -D @sentinelqa/playwright
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineConfig } from "@playwright/test";
|
|
15
|
+
import { withSentinel } from "@sentinelqa/playwright";
|
|
16
|
+
|
|
17
|
+
export default withSentinel(
|
|
18
|
+
defineConfig({
|
|
19
|
+
use: {
|
|
20
|
+
trace: "retain-on-failure",
|
|
21
|
+
screenshot: "only-on-failure",
|
|
22
|
+
video: "retain-on-failure"
|
|
23
|
+
}
|
|
24
|
+
}),
|
|
25
|
+
{
|
|
26
|
+
project: "my-app"
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Set your ingest token in CI:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
SENTINEL_TOKEN=your_project_ingest_token
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Then keep your existing Playwright command:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx playwright test
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## What it does
|
|
44
|
+
|
|
45
|
+
- Ensures a Playwright JSON report is written
|
|
46
|
+
- Ensures the Playwright HTML report is written
|
|
47
|
+
- Uploads `playwright-report/` and `test-results/` to Sentinel after the run
|
|
48
|
+
- Preserves the same Sentinel link output as the uploader CLI
|
|
49
|
+
|
|
50
|
+
## Notes
|
|
51
|
+
|
|
52
|
+
- Uploads run only when `SENTINEL_TOKEN` is set
|
|
53
|
+
- Uploads currently require GitHub Actions, GitLab CI, or CircleCI metadata
|
|
54
|
+
- Local runs keep working; upload is skipped outside supported CI providers
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type ReporterEntry = string | [string] | [string, Record<string, unknown>];
|
|
2
|
+
type PlaywrightUseOptions = {
|
|
3
|
+
trace?: string;
|
|
4
|
+
screenshot?: string;
|
|
5
|
+
video?: string;
|
|
6
|
+
};
|
|
7
|
+
type PlaywrightConfig = {
|
|
8
|
+
reporter?: ReporterEntry | ReporterEntry[];
|
|
9
|
+
outputDir?: string;
|
|
10
|
+
use?: PlaywrightUseOptions;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
export type SentinelPlaywrightOptions = {
|
|
14
|
+
project?: string;
|
|
15
|
+
playwrightJsonPath?: string;
|
|
16
|
+
playwrightReportDir?: string;
|
|
17
|
+
testResultsDir?: string;
|
|
18
|
+
artifactDirs?: string[];
|
|
19
|
+
};
|
|
20
|
+
export declare function withSentinel(config: PlaywrightConfig, options?: SentinelPlaywrightOptions): PlaywrightConfig;
|
|
21
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.withSentinel = withSentinel;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const DEFAULT_REPORT_DIR = "playwright-report";
|
|
9
|
+
const DEFAULT_TEST_RESULTS_DIR = "test-results";
|
|
10
|
+
const cloneEntry = (entry) => {
|
|
11
|
+
if (!Array.isArray(entry))
|
|
12
|
+
return entry;
|
|
13
|
+
const [name, options] = entry;
|
|
14
|
+
return options ? [name, { ...options }] : [name];
|
|
15
|
+
};
|
|
16
|
+
const normalizeReporter = (reporter) => {
|
|
17
|
+
if (!reporter)
|
|
18
|
+
return [];
|
|
19
|
+
if (!Array.isArray(reporter))
|
|
20
|
+
return [cloneEntry(reporter)];
|
|
21
|
+
if (reporter.length === 0)
|
|
22
|
+
return [];
|
|
23
|
+
const maybeTuple = typeof reporter[0] === "string" &&
|
|
24
|
+
(reporter.length === 1 ||
|
|
25
|
+
(reporter.length === 2 &&
|
|
26
|
+
!Array.isArray(reporter[1]) &&
|
|
27
|
+
typeof reporter[1] === "object"));
|
|
28
|
+
if (maybeTuple) {
|
|
29
|
+
return [cloneEntry(reporter)];
|
|
30
|
+
}
|
|
31
|
+
return reporter.map(cloneEntry);
|
|
32
|
+
};
|
|
33
|
+
const getReporterName = (entry) => {
|
|
34
|
+
return Array.isArray(entry) ? entry[0] : entry;
|
|
35
|
+
};
|
|
36
|
+
const setReporterOptions = (reporters, name, options) => {
|
|
37
|
+
const index = reporters.findIndex((entry) => getReporterName(entry) === name);
|
|
38
|
+
if (index === -1) {
|
|
39
|
+
reporters.push([name, options]);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const existing = reporters[index];
|
|
43
|
+
if (Array.isArray(existing)) {
|
|
44
|
+
reporters[index] = [name, { ...(existing[1] || {}), ...options }];
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
reporters[index] = [name, options];
|
|
48
|
+
};
|
|
49
|
+
function withSentinel(config, options = {}) {
|
|
50
|
+
const nextConfig = {
|
|
51
|
+
...config,
|
|
52
|
+
use: {
|
|
53
|
+
...config.use,
|
|
54
|
+
trace: config.use?.trace || "retain-on-failure",
|
|
55
|
+
screenshot: config.use?.screenshot || "only-on-failure",
|
|
56
|
+
video: config.use?.video || "retain-on-failure"
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const testResultsDir = options.testResultsDir || config.outputDir || DEFAULT_TEST_RESULTS_DIR;
|
|
60
|
+
const playwrightReportDir = options.playwrightReportDir || DEFAULT_REPORT_DIR;
|
|
61
|
+
const playwrightJsonPath = options.playwrightJsonPath || path_1.default.join(playwrightReportDir, "report.json");
|
|
62
|
+
nextConfig.outputDir = testResultsDir;
|
|
63
|
+
const reporters = normalizeReporter(config.reporter);
|
|
64
|
+
setReporterOptions(reporters, "json", { outputFile: playwrightJsonPath });
|
|
65
|
+
setReporterOptions(reporters, "html", {
|
|
66
|
+
outputFolder: playwrightReportDir,
|
|
67
|
+
open: "never"
|
|
68
|
+
});
|
|
69
|
+
const sentinelReporterPath = require.resolve("./reporter");
|
|
70
|
+
const sentinelReporterOptions = {
|
|
71
|
+
project: options.project || null,
|
|
72
|
+
playwrightJsonPath,
|
|
73
|
+
playwrightReportDir,
|
|
74
|
+
testResultsDir,
|
|
75
|
+
artifactDirs: options.artifactDirs || []
|
|
76
|
+
};
|
|
77
|
+
const sentinelIndex = reporters.findIndex((entry) => getReporterName(entry) === sentinelReporterPath);
|
|
78
|
+
if (sentinelIndex !== -1) {
|
|
79
|
+
reporters.splice(sentinelIndex, 1);
|
|
80
|
+
}
|
|
81
|
+
reporters.push([sentinelReporterPath, sentinelReporterOptions]);
|
|
82
|
+
nextConfig.reporter = reporters;
|
|
83
|
+
return nextConfig;
|
|
84
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type ReporterOptions = {
|
|
2
|
+
project?: string | null;
|
|
3
|
+
playwrightJsonPath: string;
|
|
4
|
+
playwrightReportDir: string;
|
|
5
|
+
testResultsDir: string;
|
|
6
|
+
artifactDirs?: string[];
|
|
7
|
+
};
|
|
8
|
+
declare class SentinelReporter {
|
|
9
|
+
private failedCount;
|
|
10
|
+
private totalCount;
|
|
11
|
+
private options;
|
|
12
|
+
constructor(options: ReporterOptions);
|
|
13
|
+
onBegin(config: any, suite: any): void;
|
|
14
|
+
onTestEnd(_test: any, result: any): void;
|
|
15
|
+
onEnd(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export = SentinelReporter;
|
package/dist/reporter.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const node_1 = require("@sentinelqa/uploader/node");
|
|
3
|
+
const pluralize = (count, singular, plural) => {
|
|
4
|
+
return count === 1 ? singular : plural;
|
|
5
|
+
};
|
|
6
|
+
class SentinelReporter {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.failedCount = 0;
|
|
9
|
+
this.totalCount = 0;
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
onBegin(config, suite) {
|
|
13
|
+
this.totalCount = typeof suite?.allTests === "function" ? suite.allTests().length : 0;
|
|
14
|
+
if (config?.projects?.length && !this.options.project) {
|
|
15
|
+
this.options.project = config.projects[0]?.name || null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
onTestEnd(_test, result) {
|
|
19
|
+
if (!result)
|
|
20
|
+
return;
|
|
21
|
+
if (["failed", "timedOut", "interrupted"].includes(result.status)) {
|
|
22
|
+
this.failedCount += 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async onEnd() {
|
|
26
|
+
console.log("Playwright run finished");
|
|
27
|
+
console.log(`${this.failedCount} ${pluralize(this.failedCount, "test", "tests")} failed`);
|
|
28
|
+
if (!process.env.SENTINEL_TOKEN) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!(0, node_1.hasSupportedCiEnv)(process.env)) {
|
|
32
|
+
console.log("");
|
|
33
|
+
console.log("Skipping Sentinel upload because no supported CI environment was detected.");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
console.log("");
|
|
37
|
+
console.log("Uploading failure artifacts to Sentinel...");
|
|
38
|
+
console.log("");
|
|
39
|
+
const exitCode = await (0, node_1.runSentinelUpload)({
|
|
40
|
+
playwrightJsonPath: this.options.playwrightJsonPath,
|
|
41
|
+
playwrightReportDir: this.options.playwrightReportDir,
|
|
42
|
+
testResultsDir: this.options.testResultsDir,
|
|
43
|
+
artifactDirs: this.options.artifactDirs || [],
|
|
44
|
+
suppressSummaryJson: true,
|
|
45
|
+
env: {
|
|
46
|
+
SENTINEL_REPORTER_PROJECT: this.options.project || undefined
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
if (exitCode !== 0) {
|
|
50
|
+
throw new Error(`Sentinel upload failed with exit code ${exitCode}`);
|
|
51
|
+
}
|
|
52
|
+
console.log("");
|
|
53
|
+
console.log("✔ Uploaded run to Sentinel");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
module.exports = SentinelReporter;
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sentinelqa/playwright",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Playwright config wrapper and reporter for SentinelQA",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/sentinelqa/sentinel"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"sentinelqa",
|
|
13
|
+
"playwright",
|
|
14
|
+
"ci",
|
|
15
|
+
"debugging",
|
|
16
|
+
"reporter"
|
|
17
|
+
],
|
|
18
|
+
"type": "commonjs",
|
|
19
|
+
"main": "dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./dist/index.js",
|
|
31
|
+
"./reporter": "./dist/reporter.js"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@playwright/test": ">=1.40.0"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@sentinelqa/uploader": "^0.1.20"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.json",
|
|
41
|
+
"publish:dry": "npm run build && npm pack --dry-run"
|
|
42
|
+
}
|
|
43
|
+
}
|