@lokalise/playwright-reporters 1.6.0 → 1.7.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.
@@ -15,7 +15,7 @@ export declare const formFailedTestData: (test: TestCase, result: TestResult, te
15
15
  name: string;
16
16
  team: string | null;
17
17
  testRunId: string;
18
- status: import("playwright/types/test").TestStatus;
18
+ status: "failed" | "interrupted" | "passed" | "timedOut" | "skipped";
19
19
  hooksDuration: number;
20
20
  beforeHookDuration: number;
21
21
  afterHookDuration: number;
@@ -32,7 +32,7 @@ export declare const formFlakyTestData: (test: TestCase, result: TestResult, tes
32
32
  name: string;
33
33
  team: string | null;
34
34
  testRunId: string;
35
- status: import("playwright/types/test").TestStatus;
35
+ status: "failed" | "interrupted" | "passed" | "timedOut" | "skipped";
36
36
  hooksDuration: number;
37
37
  beforeHookDuration: number;
38
38
  afterHookDuration: number;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import AnalyticsReporter, { defineAnalyticsReporterConfig } from './analytics/reporter';
2
+ import PermissionsReporter, { definePermissionsReporterConfig } from './permissions/reporter';
2
3
  import RetryReporter, { defineRetryReporterConfig } from './retry/reporter';
3
4
  import StepDurationReporter, { defineStepDurationReporterConfig } from './stepDuration/reporter';
4
5
  import TimelineReporter, { defineTimelineReporterConfig } from './timeline/reporter';
5
- export { AnalyticsReporter, defineAnalyticsReporterConfig, RetryReporter, defineRetryReporterConfig, TimelineReporter, defineTimelineReporterConfig, StepDurationReporter, defineStepDurationReporterConfig, };
6
+ export { AnalyticsReporter, defineAnalyticsReporterConfig, RetryReporter, defineRetryReporterConfig, TimelineReporter, defineTimelineReporterConfig, StepDurationReporter, defineStepDurationReporterConfig, PermissionsReporter, definePermissionsReporterConfig };
package/dist/index.js CHANGED
@@ -23,16 +23,19 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.defineStepDurationReporterConfig = exports.StepDurationReporter = exports.defineTimelineReporterConfig = exports.TimelineReporter = exports.defineRetryReporterConfig = exports.RetryReporter = exports.defineAnalyticsReporterConfig = exports.AnalyticsReporter = void 0;
26
+ exports.definePermissionsReporterConfig = exports.PermissionsReporter = exports.defineStepDurationReporterConfig = exports.StepDurationReporter = exports.defineTimelineReporterConfig = exports.TimelineReporter = exports.defineRetryReporterConfig = exports.RetryReporter = exports.defineAnalyticsReporterConfig = exports.AnalyticsReporter = void 0;
27
27
  const reporter_1 = __importStar(require("./analytics/reporter"));
28
28
  exports.AnalyticsReporter = reporter_1.default;
29
29
  Object.defineProperty(exports, "defineAnalyticsReporterConfig", { enumerable: true, get: function () { return reporter_1.defineAnalyticsReporterConfig; } });
30
- const reporter_2 = __importStar(require("./retry/reporter"));
31
- exports.RetryReporter = reporter_2.default;
32
- Object.defineProperty(exports, "defineRetryReporterConfig", { enumerable: true, get: function () { return reporter_2.defineRetryReporterConfig; } });
33
- const reporter_3 = __importStar(require("./stepDuration/reporter"));
34
- exports.StepDurationReporter = reporter_3.default;
35
- Object.defineProperty(exports, "defineStepDurationReporterConfig", { enumerable: true, get: function () { return reporter_3.defineStepDurationReporterConfig; } });
36
- const reporter_4 = __importStar(require("./timeline/reporter"));
37
- exports.TimelineReporter = reporter_4.default;
38
- Object.defineProperty(exports, "defineTimelineReporterConfig", { enumerable: true, get: function () { return reporter_4.defineTimelineReporterConfig; } });
30
+ const reporter_2 = __importStar(require("./permissions/reporter"));
31
+ exports.PermissionsReporter = reporter_2.default;
32
+ Object.defineProperty(exports, "definePermissionsReporterConfig", { enumerable: true, get: function () { return reporter_2.definePermissionsReporterConfig; } });
33
+ const reporter_3 = __importStar(require("./retry/reporter"));
34
+ exports.RetryReporter = reporter_3.default;
35
+ Object.defineProperty(exports, "defineRetryReporterConfig", { enumerable: true, get: function () { return reporter_3.defineRetryReporterConfig; } });
36
+ const reporter_4 = __importStar(require("./stepDuration/reporter"));
37
+ exports.StepDurationReporter = reporter_4.default;
38
+ Object.defineProperty(exports, "defineStepDurationReporterConfig", { enumerable: true, get: function () { return reporter_4.defineStepDurationReporterConfig; } });
39
+ const reporter_5 = __importStar(require("./timeline/reporter"));
40
+ exports.TimelineReporter = reporter_5.default;
41
+ Object.defineProperty(exports, "defineTimelineReporterConfig", { enumerable: true, get: function () { return reporter_5.defineTimelineReporterConfig; } });
@@ -0,0 +1,13 @@
1
+ import type { PermissionsReportData } from "./reporter";
2
+ export type ElasticOptions = {
3
+ permissionsIndex: string;
4
+ elasticUrl: string;
5
+ elasticToken: string;
6
+ };
7
+ export declare class Elastic {
8
+ private readonly options;
9
+ private request;
10
+ constructor(options: ElasticOptions);
11
+ setRequestContext(): Promise<void>;
12
+ savePermissionsData(testData: PermissionsReportData): Promise<void>;
13
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Elastic = void 0;
4
+ const test_1 = require("@playwright/test");
5
+ class Elastic {
6
+ constructor(options) {
7
+ this.options = options;
8
+ }
9
+ async setRequestContext() {
10
+ this.request = await test_1.request.newContext({
11
+ baseURL: this.options.elasticUrl,
12
+ ignoreHTTPSErrors: true,
13
+ ...(this.options.elasticToken && {
14
+ extraHTTPHeaders: { Authorization: `ApiKey ${this.options.elasticToken}` },
15
+ }),
16
+ });
17
+ }
18
+ async savePermissionsData(testData) {
19
+ try {
20
+ await this.request.post(`/${this.options.permissionsIndex}/_doc`, { data: testData });
21
+ }
22
+ catch (error) {
23
+ console.error("Failed to save permissions data");
24
+ console.error(error);
25
+ }
26
+ }
27
+ }
28
+ exports.Elastic = Elastic;
@@ -0,0 +1,25 @@
1
+ import type { TestCase, TestResult, Reporter, TestStep } from '@playwright/test/reporter';
2
+ import { type ElasticOptions } from './elastic';
3
+ type ReporterOptions = {
4
+ annotationName: string;
5
+ stepName: string;
6
+ debug: boolean;
7
+ } & ElasticOptions;
8
+ export type PermissionsReportData = {
9
+ title: string;
10
+ permissions: Record<string, boolean>;
11
+ failedStep: string;
12
+ timestamp: number;
13
+ };
14
+ export default class PermissionsReporter implements Reporter {
15
+ private readonly options;
16
+ private readonly elastic;
17
+ private readonly debugLogging;
18
+ private failedTestData;
19
+ constructor(options: ReporterOptions);
20
+ onBegin(): Promise<void>;
21
+ onTestEnd(test: TestCase): Promise<void>;
22
+ onStepEnd(test: TestCase, _result: TestResult, step: TestStep): void;
23
+ }
24
+ export declare const definePermissionsReporterConfig: (options: ConstructorParameters<typeof PermissionsReporter>[0]) => ReporterOptions;
25
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.definePermissionsReporterConfig = void 0;
4
+ const elastic_1 = require("./elastic");
5
+ // eslint-disable-next-line import/no-default-export
6
+ class PermissionsReporter {
7
+ constructor(options) {
8
+ this.elastic = new elastic_1.Elastic(options);
9
+ this.options = options;
10
+ this.failedTestData = {};
11
+ this.debugLogging = options.debug ? console.info : () => { };
12
+ }
13
+ async onBegin() {
14
+ await this.elastic.setRequestContext();
15
+ }
16
+ async onTestEnd(test) {
17
+ // Omit the results if the test is passing
18
+ if (test.outcome() === 'expected') {
19
+ this.debugLogging('Not reporting test - test passed');
20
+ return;
21
+ }
22
+ // Omit the results if the test does not contain the annotation
23
+ if (!test.annotations.find((annotation) => annotation.type === this.options.annotationName)) {
24
+ this.debugLogging('Not reporting test - no permission annotation');
25
+ return;
26
+ }
27
+ // Test Title
28
+ const testTitle = test.title;
29
+ // Permissions as object
30
+ const testPermissions = test.annotations.find((annotation) => annotation.type === this.options.annotationName);
31
+ const permissionContents = testPermissions?.description ? JSON.parse(testPermissions.description) : {};
32
+ // Which step failed
33
+ const failedStep = this.failedTestData[test.id];
34
+ // Send payload body
35
+ const reportData = {
36
+ title: testTitle,
37
+ permissions: permissionContents,
38
+ failedStep,
39
+ timestamp: Date.now()
40
+ };
41
+ await this.elastic.savePermissionsData(reportData);
42
+ }
43
+ onStepEnd(test, _result, step) {
44
+ if (!step.title.includes(this.options.stepName)) {
45
+ this.debugLogging('Not reporting step - no step annotation', step.title);
46
+ return;
47
+ }
48
+ if (!step.error) {
49
+ this.debugLogging("Not reporting step - no error");
50
+ return;
51
+ }
52
+ this.debugLogging('Captured step name with error:', step.title);
53
+ this.failedTestData[test.id] = step.title;
54
+ }
55
+ }
56
+ exports.default = PermissionsReporter;
57
+ const definePermissionsReporterConfig = (options) => options;
58
+ exports.definePermissionsReporterConfig = definePermissionsReporterConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lokalise/playwright-reporters",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "scripts": {
5
5
  "lint:eslint": "eslint --cache . --ext .js,.cjs,.ts",
6
6
  "lint:ts": "tsc --noEmit",
@@ -41,35 +41,39 @@
41
41
  "./testSimilarity": {
42
42
  "import": "./dist/testSimilarity/reporter.js",
43
43
  "require": "./dist/testSimilarity/reporter.js"
44
+ },
45
+ "./permissions": {
46
+ "import": "./dist/permissions/reporter.js",
47
+ "require": "./dist/permissions/reporter.js"
44
48
  }
45
49
  },
46
50
  "publishConfig": {
47
51
  "access": "public"
48
52
  },
49
53
  "devDependencies": {
50
- "@commitlint/cli": "19.2.2",
54
+ "@commitlint/cli": "19.3.0",
51
55
  "@commitlint/config-conventional": "19.2.2",
52
- "@commitlint/prompt-cli": "19.2.2",
56
+ "@commitlint/prompt-cli": "19.3.1",
53
57
  "@lokalise/eslint-config-frontend": "^4.6.0",
54
- "@lokalise/prettier-config": "^1.0.0",
58
+ "@lokalise/prettier-config": "^1.0.1",
55
59
  "@semantic-release/changelog": "6.0.3",
56
- "@semantic-release/commit-analyzer": "12.0.0",
60
+ "@semantic-release/commit-analyzer": "13.0.0",
57
61
  "@semantic-release/git": "10.0.1",
58
- "@semantic-release/github": "10.0.3",
59
- "@semantic-release/npm": "12.0.0",
62
+ "@semantic-release/github": "10.0.6",
63
+ "@semantic-release/npm": "12.0.1",
60
64
  "@semantic-release/release-notes-generator": "13.0.0",
61
- "@types/lodash": "^4.17.0",
62
- "@types/node": "^20.12.7",
65
+ "@types/lodash": "^4.17.5",
66
+ "@types/node": "^20.14.2",
63
67
  "eslint-config-prettier": "^9.1.0",
64
68
  "eslint-plugin-prettier": "^5.1.3",
65
69
  "husky": "9.0.11",
66
- "prettier": "^3.2.5",
67
- "semantic-release": "23.0.8",
70
+ "prettier": "^3.3.2",
71
+ "semantic-release": "23.1.1",
68
72
  "typescript": "5.4.5"
69
73
  },
70
74
  "dependencies": {
71
75
  "@faker-js/faker": "^8.4.1",
72
- "@playwright/test": "^1.43.1",
76
+ "@playwright/test": "^1.44.1",
73
77
  "fastest-levenshtein": "^1.0.16",
74
78
  "lodash": "^4.17.21"
75
79
  },