transit-core-taf 1.0.17 → 1.0.19

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.
@@ -11,3 +11,5 @@ export * from './baseapi/apiutils';
11
11
  export * from './constants/test-tags';
12
12
  export * from './utils/testrail/client';
13
13
  export * from './utils/testrail-importer';
14
+ export { default as TestRailReporter } from './reporters/testrail-reporter';
15
+ export type { TestRailReporterOptions } from './reporters/testrail-reporter';
@@ -13,7 +13,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
16
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.TestRailReporter = void 0;
17
21
  __exportStar(require("./baseui/basepagevalidations"), exports);
18
22
  __exportStar(require("./baseui/basepageactions"), exports);
19
23
  __exportStar(require("./baseui/basepagewaits"), exports);
@@ -27,3 +31,5 @@ __exportStar(require("./baseapi/apiutils"), exports);
27
31
  __exportStar(require("./constants/test-tags"), exports);
28
32
  __exportStar(require("./utils/testrail/client"), exports);
29
33
  __exportStar(require("./utils/testrail-importer"), exports);
34
+ var testrail_reporter_1 = require("./reporters/testrail-reporter");
35
+ Object.defineProperty(exports, "TestRailReporter", { enumerable: true, get: function () { return __importDefault(testrail_reporter_1).default; } });
@@ -1,23 +1,14 @@
1
- import { Reporter, FullConfig, Suite, TestCase, TestResult } from '@playwright/test/reporter';
2
- export interface TestRailReporterOptions {
3
- host: string;
4
- user: string;
5
- token?: string;
6
- password?: string;
7
- projectId: string;
8
- suiteId: number;
9
- runName?: string;
10
- enabled?: boolean;
1
+ import { Reporter, FullConfig, Suite, FullResult } from '@playwright/test/reporter';
2
+ import { TestRailJunitImporterOptions } from '../utils/testrail-importer';
3
+ export interface TestRailReporterOptions extends Omit<TestRailJunitImporterOptions, 'junitPath' | 'onstart' | 'onend'> {
4
+ outputFile?: string;
11
5
  }
12
6
  declare class TestRailReporter implements Reporter {
13
- private client;
14
- private runId;
15
- private suiteId;
16
- private enabled;
17
- private runName?;
18
- constructor(options?: TestRailReporterOptions);
19
- onBegin(config: FullConfig, suite: Suite): Promise<void>;
20
- onTestEnd(test: TestCase, result: TestResult): Promise<void>;
21
- private getCaseId;
7
+ private options;
8
+ private config;
9
+ constructor(options: TestRailReporterOptions);
10
+ onBegin(config: FullConfig, suite: Suite): void;
11
+ onEnd(result: FullResult): Promise<void>;
12
+ private getJunitReporter;
22
13
  }
23
14
  export default TestRailReporter;
@@ -1,92 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const client_1 = require("../utils/testrail/client");
3
+ const testrail_importer_1 = require("../utils/testrail-importer");
4
4
  class TestRailReporter {
5
- client = null;
6
- runId = null;
7
- suiteId = null;
8
- enabled = false;
9
- runName;
5
+ options;
6
+ config;
10
7
  constructor(options) {
11
- const isEnabled = options?.enabled ?? process.env.TESTRAIL_REPORTER_ENABLED === 'true';
12
- if (isEnabled) {
13
- this.enabled = true;
14
- try {
15
- const host = options?.host ?? process.env.TESTRAIL_HOST;
16
- const user = options?.user ?? process.env.TESTRAIL_USER;
17
- const token = options?.token ?? process.env.TESTRAIL_TOKEN;
18
- const password = options?.password ?? process.env.TESTRAIL_PASSWORD;
19
- const projectId = options?.projectId ?? process.env.TESTRAIL_PROJECT_ID;
20
- if (!host || !user || !(token || password) || !projectId) {
21
- throw new Error('TestRail credentials (host, user, projectId, and token/password) are not fully set in options or environment variables.');
22
- }
23
- this.client = new client_1.TestRailClient({ host, user, projectId, token, password });
24
- const suiteIdEnv = options?.suiteId?.toString() ?? process.env.TESTRAIL_SUITE_ID;
25
- if (!suiteIdEnv) {
26
- throw new Error('TESTRAIL_SUITE_ID is not set in options or environment variables.');
27
- }
28
- this.suiteId = parseInt(suiteIdEnv, 10);
29
- if (isNaN(this.suiteId)) {
30
- throw new Error('TESTRAIL_SUITE_ID is not a valid number.');
31
- }
32
- this.runName = options?.runName;
33
- }
34
- catch (error) {
35
- console.error('Failed to initialize TestRail reporter:', error);
36
- this.enabled = false;
37
- }
38
- }
39
- else {
40
- console.log("TestRail reporter is disabled. Set TESTRAIL_REPORTER_ENABLED to 'true' or provide enabled:true in options.");
8
+ if (!options.runId) {
9
+ throw new Error('TestRail Reporter requires a `runId` to be specified.');
41
10
  }
11
+ this.options = options;
12
+ console.log('Initialized TestRail Reporter.');
13
+ }
14
+ onBegin(config, suite) {
15
+ this.config = config;
16
+ console.log(`Starting the run with ${suite.allTests().length} tests`);
42
17
  }
43
- async onBegin(config, suite) {
44
- if (!this.enabled || !this.client || !this.suiteId)
18
+ async onEnd(result) {
19
+ console.log(`Run finished with status: ${result.status}`);
20
+ if (process.env.EXEC_ENVIRONMENT !== 'remote') {
21
+ console.log('Skipping TestRail results upload for non-remote execution.');
45
22
  return;
46
- const timestamp = new Date().toLocaleString();
47
- const runName = this.runName ?? `Automated Test Run - ${timestamp}`;
48
- const runDescription = `Playwright test run executed on ${timestamp}`;
49
- try {
50
- const run = await this.client.createTestRun(this.suiteId, runName, runDescription);
51
- this.runId = run.id;
52
23
  }
53
- catch (error) {
54
- console.error('Failed to create TestRail test run. Disabling reporter.');
55
- this.enabled = false;
24
+ // Find the JUnit reporter's output file path from the Playwright config
25
+ const junitReporter = this.getJunitReporter(this.config);
26
+ if (!junitReporter) {
27
+ console.error('Error: JUnit reporter not found in Playwright config. The TestRail reporter depends on the output of the JUnit reporter.');
28
+ return;
56
29
  }
57
- }
58
- async onTestEnd(test, result) {
59
- if (!this.enabled || !this.client || !this.runId)
30
+ const junitPath = junitReporter.outputFile || junitReporter._outputFile;
31
+ if (!junitPath) {
32
+ console.error('Error: Could not determine the output file path for the JUnit reporter.');
60
33
  return;
61
- const caseId = this.getCaseId(test);
62
- if (caseId) {
63
- const comment = result.status === 'failed' || result.status === 'timedOut'
64
- ? `Test failed with error: ${result.error?.message}`
65
- : `Test completed with status: ${result.status}`;
66
- try {
67
- await this.client.addResultForCase(this.runId, caseId, result.status, comment);
68
- console.log(`Successfully reported result for Case C${caseId} to TestRail.`);
69
- }
70
- catch (error) {
71
- console.error(`Failed to report result for Case C${caseId}.`);
72
- }
73
34
  }
74
- }
75
- getCaseId(test) {
76
- const caseIdRegex = /C(\d+)/;
77
- // Check tags first
78
- for (const tag of test.tags) {
79
- const match = tag.match(caseIdRegex);
80
- if (match) {
81
- return parseInt(match[1], 10);
82
- }
35
+ console.log(`Using JUnit report from: ${junitPath}`);
36
+ try {
37
+ await (0, testrail_importer_1.uploadJunitToTestRail)({
38
+ ...this.options,
39
+ junitPath,
40
+ });
41
+ console.log('Successfully uploaded test results to TestRail.');
83
42
  }
84
- // Fallback to title
85
- const titleMatch = test.title.match(caseIdRegex);
86
- if (titleMatch) {
87
- return parseInt(titleMatch[1], 10);
43
+ catch (error) {
44
+ console.error('Failed to upload results to TestRail:', error);
88
45
  }
89
- return null;
46
+ }
47
+ getJunitReporter(config) {
48
+ // Playwright wraps reporters in an array, e.g., ['junit', { outputFile: 'results.xml' }]
49
+ const reporter = config.reporter.find((r) => r[0] === 'junit');
50
+ return reporter ? reporter[1] : undefined;
90
51
  }
91
52
  }
92
53
  exports.default = TestRailReporter;
@@ -5,6 +5,14 @@ export interface TestRailClientOptions {
5
5
  token?: string;
6
6
  password?: string;
7
7
  }
8
+ export interface TestRailResult {
9
+ status_id: number;
10
+ comment?: string;
11
+ version?: string;
12
+ elapsed?: string;
13
+ defects?: string;
14
+ assignedto_id?: number;
15
+ }
8
16
  export declare class TestRailClient {
9
17
  private host;
10
18
  private user;
@@ -15,4 +23,5 @@ export declare class TestRailClient {
15
23
  private apiPost;
16
24
  createTestRun(suiteId: number, name: string, description: string): Promise<any>;
17
25
  loadJunitReport(runId: number, xmlContent: string): Promise<any>;
26
+ addResultForCase(runId: number, caseId: number, result: TestRailResult): Promise<any>;
18
27
  }
@@ -71,5 +71,18 @@ class TestRailClient {
71
71
  console.log(`Successfully uploaded JUnit report to TestRail.`);
72
72
  return result;
73
73
  }
74
+ async addResultForCase(runId, caseId, result) {
75
+ const endpoint = `add_result_for_case/${runId}/${caseId}`;
76
+ console.log(`Adding result for Case ID: ${caseId} in Test Run ID: ${runId}`);
77
+ try {
78
+ const response = await this.apiPost(endpoint, result);
79
+ console.log(`Successfully added result for Case ID: ${caseId}.`);
80
+ return response;
81
+ }
82
+ catch (error) {
83
+ console.error(`Failed to add result for Case ID: ${caseId}.`, error);
84
+ throw error;
85
+ }
86
+ }
74
87
  }
75
88
  exports.TestRailClient = TestRailClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "transit-core-taf",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "Transit Core Automation Framework",
5
5
  "main": "dist/transit-core-taf/index.js",
6
6
  "types": "dist/transit-core-taf/index.d.ts",