@alex_neo/playwright-azure-reporter 1.9.1 → 1.10.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.
@@ -6,25 +6,25 @@ on:
6
6
 
7
7
  jobs:
8
8
  publish:
9
- runs-on: ubuntu-latest
10
- permissions:
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
11
  contents: read
12
- packages: write
12
+ packages: write
13
13
  steps:
14
14
  - name: Checkout
15
15
  uses: actions/checkout@v3
16
16
  - name: Setup Node.js
17
17
  uses: actions/setup-node@v3
18
18
  with:
19
- node-version: '16.x'
19
+ node-version: '>=18'
20
20
  registry-url: 'https://registry.npmjs.org'
21
21
  # Defaults to the user or organization that owns the workflow file
22
22
  scope: '@alex_neo'
23
23
  - name: Install dependencies
24
- run: yarn
24
+ run: yarn --ignore-engines
25
25
  - name: Build
26
26
  run: yarn build
27
27
  - name: Publish
28
28
  run: yarn publish --access public
29
29
  env:
30
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
30
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -20,9 +20,9 @@ jobs:
20
20
  - name: Setup Node.js
21
21
  uses: actions/setup-node@v3
22
22
  with:
23
- node-version: '16.x'
23
+ node-version: '>=18'
24
24
  - name: Install dependencies
25
- run: yarn
25
+ run: yarn --ignore-engines
26
26
  - name: Install Playwright
27
27
  run: npx playwright install chromium
28
28
  - name: Build project
package/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ # [1.10.0](https://github.com/alexneo2003/playwright-azure-reporter/compare/v1.10.0-beta.0...v1.10.0) (2024-08-06)
2
+
3
+
4
+ ### Features
5
+
6
+ * rework logger and reporter ([1186113](https://github.com/alexneo2003/playwright-azure-reporter/commit/118611375dac554c6671fd19b6a3d036e7052ad5))
7
+
8
+
9
+
10
+ # [1.10.0-beta.0](https://github.com/alexneo2003/playwright-azure-reporter/compare/v1.9.1...v1.10.0-beta.0) (2024-08-05)
11
+
12
+
13
+ ### Features
14
+
15
+ * AZURE_PW_TEST_RUN_ID as Task variable ([8c7693a](https://github.com/alexneo2003/playwright-azure-reporter/commit/8c7693a510bf93ac2cb10c801a7d3b71295af420))
16
+
17
+
18
+
1
19
  ## [1.9.1](https://github.com/alexneo2003/playwright-azure-reporter/compare/v1.9.0...v1.9.1) (2024-06-04)
2
20
 
3
21
 
package/README.md CHANGED
@@ -181,6 +181,9 @@ Reporter options (\* - required):
181
181
  - `testPointMapper` - A callback to map the test runs to test configurations, e.g. by browser
182
182
 
183
183
  ```
184
+ import { TestCase } from '@playwright/test/reporter'
185
+ import { TestPoint } from 'azure-devops-node-api/interfaces/TestInterfaces'
186
+
184
187
  testPointMapper: async (testCase: TestCase, testPoints: TestPoint[]) => {
185
188
  switch(testCase.parent.project()?.use.browserName) {
186
189
  case 'chromium':
@@ -209,4 +212,19 @@ Reporter options (\* - required):
209
212
 
210
213
  ## Usefulness
211
214
 
212
- - **AZURE_PW_TEST_RUN_ID** - Id of current test run. It will be set in environment variables after test run created. Can be accessed by `process.env.AZURE_PW_TEST_RUN_ID`. Pay attention what `publishTestResultsMode` configuration you use.
215
+ - **AZURE_PW_TEST_RUN_ID** - Id of current test run. It will be set in environment variables after test run created. Can be accessed by `process.env.AZURE_PW_TEST_RUN_ID`. Pay attention what `publishTestResultsMode` configuration you use. If you use `testResult` mode - this variable will be set when test run created, at the start of tests execution, if you use `testRun` mode - this variable will be set when test run completed, at the end of tests execution.
216
+
217
+ > **Since version 1.10.0 you have access to `AZURE_PW_TEST_RUN_ID` environment variable in your ADO pipeline. You can get it from the Task Variables.**
218
+
219
+ Example of usage in Azure DevOps pipeline:
220
+
221
+ ```yaml
222
+ - script: npx playwright test
223
+ displayName: 'Run Playwright tests'
224
+ name: 'playwright'
225
+ env:
226
+ CI: 'true'
227
+
228
+ - script: echo $(playwright.AZURE_PW_TEST_RUN_ID)
229
+ displayName: 'Print test run id'
230
+ ```
@@ -0,0 +1,13 @@
1
+ declare class Logger {
2
+ private rootNamespace;
3
+ private namespace;
4
+ private isLogging;
5
+ constructor(isLogging: boolean);
6
+ private isDisabled;
7
+ private logMessage;
8
+ log(message: string): void;
9
+ warn(message: string): void;
10
+ error(message: string): void;
11
+ debug(message: any): void;
12
+ }
13
+ export default Logger;
package/dist/logger.js ADDED
@@ -0,0 +1,64 @@
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
+ const chalk_1 = __importDefault(require("chalk"));
7
+ const debug_1 = __importDefault(require("debug"));
8
+ class Logger {
9
+ rootNamespace;
10
+ namespace;
11
+ isLogging;
12
+ constructor(isLogging) {
13
+ this.rootNamespace = 'azure:pw';
14
+ this.namespace = process.env.AZUREPWDEBUG === '1' ? 'azure:pw:*' : 'azure:pw:log,azure:pw:warn,azure:pw:error';
15
+ this.isLogging = isLogging;
16
+ if (this.isLogging && !this.isDisabled()) {
17
+ debug_1.default.enable(this.namespace);
18
+ }
19
+ }
20
+ isDisabled() {
21
+ return process.env.AZURE_PW_DISABLED === 'true';
22
+ }
23
+ // eslint-disable-next-line no-unused-vars
24
+ logMessage(level, message, colorFunc) {
25
+ if (!this.isDisabled()) {
26
+ if (typeof message === 'object') {
27
+ message = JSON.stringify(message, null, 2);
28
+ }
29
+ let enabled = false;
30
+ if (['warn', 'error'].includes(level) || this.namespace === 'azure:pw:*') {
31
+ enabled = debug_1.default.enabled(`${this.rootNamespace}:${level}`);
32
+ debug_1.default.enable(`${this.rootNamespace}:${level}`);
33
+ const log = (0, debug_1.default)(this.rootNamespace).extend(level);
34
+ log.log = console.log.bind(console);
35
+ log(colorFunc(message));
36
+ if (!enabled) {
37
+ debug_1.default.disable();
38
+ }
39
+ }
40
+ else {
41
+ const log = (0, debug_1.default)(this.rootNamespace).extend(level);
42
+ log.log = console.log.bind(console);
43
+ log(colorFunc(message));
44
+ }
45
+ if (this.isLogging && !this.isDisabled()) {
46
+ debug_1.default.enable(this.namespace);
47
+ }
48
+ }
49
+ }
50
+ log(message) {
51
+ this.logMessage('log', message, chalk_1.default.white);
52
+ }
53
+ warn(message) {
54
+ this.logMessage('warn', message, chalk_1.default.yellow);
55
+ }
56
+ error(message) {
57
+ this.logMessage('error', message, chalk_1.default.red);
58
+ }
59
+ debug(message) {
60
+ this.logMessage('debug', message, chalk_1.default.blue);
61
+ }
62
+ }
63
+ exports.default = Logger;
64
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAC1B,kDAA0B;AAE1B,MAAM,MAAM;IACF,aAAa,CAAS;IACtB,SAAS,CAAS;IAClB,SAAS,CAAU;IAE3B,YAAY,SAAkB;QAC5B,IAAI,CAAC,aAAa,GAAG,UAAU,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,2CAA2C,CAAC;QAC/G,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE;YACxC,eAAK,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAC9B;IACH,CAAC;IAEO,UAAU;QAChB,OAAO,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,MAAM,CAAC;IAClD,CAAC;IAED,0CAA0C;IAClC,UAAU,CAAC,KAAa,EAAE,OAAe,EAAE,SAAkC;QACnF,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE;YACtB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;gBAC/B,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC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ClB,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,eAAK,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,OAAe;QACnB,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,eAAK,CAAC,GAAG,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,OAAY;QAChB,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,eAAK,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;CACF;AAED,kBAAe,MAAM,CAAC"}
@@ -23,8 +23,7 @@ export interface AzureReporterOptions {
23
23
  testRunId?: number;
24
24
  }
25
25
  declare class AzureDevOpsReporter implements Reporter {
26
- private _debug;
27
- private _debugWarning;
26
+ private _logger;
28
27
  private _testApi;
29
28
  private _coreApi;
30
29
  private _publishedResultsCount;
@@ -37,6 +36,7 @@ declare class AzureDevOpsReporter implements Reporter {
37
36
  private _planId;
38
37
  private _logging;
39
38
  private _isDisabled;
39
+ private _setIsDisable;
40
40
  private _testRunTitle;
41
41
  private _uploadAttachments;
42
42
  private _attachmentsType;
@@ -59,8 +59,8 @@ declare class AzureDevOpsReporter implements Reporter {
59
59
  onTestEnd(test: TestCase, testResult: TestResult): Promise<void>;
60
60
  onEnd(): Promise<void>;
61
61
  printsToStdio(): boolean;
62
- private _log;
63
- private _warning;
62
+ private _anonymizeString;
63
+ private _anonymizeObject;
64
64
  private _extractMatches;
65
65
  private _getCaseIds;
66
66
  private _logTestItem;
@@ -73,5 +73,6 @@ declare class AzureDevOpsReporter implements Reporter {
73
73
  private _mapToAzureState;
74
74
  private _publishCaseResult;
75
75
  private _publishTestResults;
76
+ private _setAzurePWTestRunId;
76
77
  }
77
78
  export default AzureDevOpsReporter;