@m00nsolutions/playwright-reporter 1.0.6 → 1.0.7

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.
Files changed (3) hide show
  1. package/README.md +91 -0
  2. package/index.mjs +84 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -81,6 +81,70 @@ M00N_LAUNCH="Nightly Build"
81
81
  M00N_TAGS=smoke,regression
82
82
  ```
83
83
 
84
+ ## CI/CD Auto-Detection
85
+
86
+ The reporter **automatically detects** CI/CD environment variables from popular providers and includes them as run attributes. No configuration needed — just run your tests in CI and the dashboard will display branch, commit, build URL, and more.
87
+
88
+ ### Supported Providers
89
+
90
+ | Provider | Detection Variable |
91
+ |---|---|
92
+ | **GitHub Actions** | `GITHUB_ACTIONS` |
93
+ | **GitLab CI** | `GITLAB_CI` |
94
+ | **Jenkins** | `JENKINS_URL` |
95
+ | **Bitbucket Pipelines** | `BITBUCKET_PIPELINE_UUID` |
96
+ | **Azure DevOps** | `TF_BUILD` |
97
+ | **CircleCI** | `CIRCLECI` |
98
+ | **Travis CI** | `TRAVIS` |
99
+
100
+ ### Auto-Detected Attributes
101
+
102
+ The following attributes are automatically populated when running in a supported CI environment:
103
+
104
+ | Attribute | Description | GitHub Actions | GitLab CI | Jenkins | Bitbucket | Azure DevOps | CircleCI | Travis CI |
105
+ |---|---|---|---|---|---|---|---|---|
106
+ | `ci_provider` | CI provider name | `GitHub Actions` | `GitLab CI` | `Jenkins` | `Bitbucket Pipelines` | `Azure DevOps` | `CircleCI` | `Travis CI` |
107
+ | `branch` | Git branch | `GITHUB_REF_NAME` | `CI_COMMIT_REF_NAME` | `BRANCH_NAME` | `BITBUCKET_BRANCH` | `BUILD_SOURCEBRANCH` | `CIRCLE_BRANCH` | `TRAVIS_BRANCH` |
108
+ | `commit` | Git commit SHA | `GITHUB_SHA` | `CI_COMMIT_SHA` | `GIT_COMMIT` | `BITBUCKET_COMMIT` | `BUILD_SOURCEVERSION` | `CIRCLE_SHA1` | `TRAVIS_COMMIT` |
109
+ | `pipeline` | Pipeline/workflow name | `GITHUB_WORKFLOW` | `CI_PIPELINE_NAME` | `JOB_NAME` | — | `BUILD_DEFINITIONNAME` | `CIRCLE_WORKFLOW_JOB_NAME` | — |
110
+ | `build_number` | Build number | `GITHUB_RUN_NUMBER` | `CI_PIPELINE_ID` | `BUILD_NUMBER` | `BITBUCKET_BUILD_NUMBER` | `BUILD_BUILDNUMBER` | `CIRCLE_BUILD_NUM` | `TRAVIS_BUILD_NUMBER` |
111
+ | `build_url` | Link to build | Auto-composed | `CI_PIPELINE_URL` | `BUILD_URL` | Auto-composed | Auto-composed | `CIRCLE_BUILD_URL` | `TRAVIS_BUILD_WEB_URL` |
112
+ | `trigger` | What triggered the build | `GITHUB_EVENT_NAME` | `CI_PIPELINE_SOURCE` | — | — | `BUILD_REASON` | — | `TRAVIS_EVENT_TYPE` |
113
+ | `triggered_by` | User who triggered | `GITHUB_ACTOR` | `CI_GITLAB_USER_LOGIN` | — | — | — | `CIRCLE_USERNAME` | — |
114
+
115
+ ### Manual Override
116
+
117
+ User-provided attributes always take precedence over auto-detected values. To override any auto-detected attribute, simply set it in the `attributes` config:
118
+
119
+ ```typescript
120
+ reporter: [
121
+ ['@m00nsolutions/playwright-reporter', {
122
+ serverUrl: 'https://m00nreport.com',
123
+ apiKey: process.env.M00N_API_KEY,
124
+ attributes: {
125
+ branch: 'my-custom-branch', // Overrides auto-detected branch
126
+ environment: 'staging', // Custom attribute (not auto-detected)
127
+ },
128
+ }],
129
+ ],
130
+ ```
131
+
132
+ ### Custom CI Variables
133
+
134
+ For unsupported CI providers or additional metadata, pass any key-value pairs via `attributes`:
135
+
136
+ ```typescript
137
+ attributes: {
138
+ build_url: process.env.MY_CI_BUILD_URL,
139
+ branch: process.env.MY_CI_BRANCH,
140
+ commit: process.env.MY_CI_COMMIT,
141
+ environment: 'production',
142
+ region: 'us-east-1',
143
+ },
144
+ ```
145
+
146
+ The dashboard recognizes these attribute keys and displays them in the CI/CD banner: `branch`, `commit`, `pipeline`, `build_number`, `build_url`, `environment`, `trigger`.
147
+
84
148
  ## Usage Examples
85
149
 
86
150
  ### Basic Configuration
@@ -94,6 +158,33 @@ reporter: [
94
158
  ],
95
159
  ```
96
160
 
161
+ ### GitHub Actions Example
162
+
163
+ ```yaml
164
+ # .github/workflows/tests.yml
165
+ jobs:
166
+ test:
167
+ runs-on: ubuntu-latest
168
+ steps:
169
+ - uses: actions/checkout@v4
170
+ - run: npx playwright test
171
+ env:
172
+ M00N_API_KEY: ${{ secrets.M00N_API_KEY }}
173
+ ```
174
+
175
+ The reporter will automatically capture `branch`, `commit`, `build_url`, `pipeline`, `build_number`, `trigger`, and `triggered_by` from GitHub Actions environment variables.
176
+
177
+ ### GitLab CI Example
178
+
179
+ ```yaml
180
+ # .gitlab-ci.yml
181
+ test:
182
+ script:
183
+ - npx playwright test
184
+ variables:
185
+ M00N_API_KEY: $M00N_API_KEY
186
+ ```
187
+
97
188
  ## Real-time Step Streaming
98
189
 
99
190
  When `realtime: true` (default), the reporter streams test steps to the dashboard as they execute. This allows you to:
package/index.mjs CHANGED
@@ -470,6 +470,84 @@ function parseTags(tags) {
470
470
  return [];
471
471
  }
472
472
 
473
+ /**
474
+ * Auto-detect CI/CD environment variables from common providers.
475
+ * Returns a flat key-value object using attribute names that the
476
+ * M00n Report dashboard recognizes (branch, commit, pipeline, etc.).
477
+ * User-provided attributes always take precedence over auto-detected ones.
478
+ */
479
+ function detectCIAttributes() {
480
+ const env = process.env;
481
+ const attrs = {};
482
+
483
+ if (env.GITHUB_ACTIONS) {
484
+ attrs.ci_provider = 'GitHub Actions';
485
+ if (env.GITHUB_WORKFLOW) attrs.pipeline = env.GITHUB_WORKFLOW;
486
+ if (env.GITHUB_RUN_NUMBER) attrs.build_number = env.GITHUB_RUN_NUMBER;
487
+ if (env.GITHUB_SHA) attrs.commit = env.GITHUB_SHA;
488
+ if (env.GITHUB_REF_NAME) attrs.branch = env.GITHUB_REF_NAME;
489
+ else if (env.GITHUB_REF) attrs.branch = env.GITHUB_REF.replace(/^refs\/heads\//, '');
490
+ if (env.GITHUB_EVENT_NAME) attrs.trigger = env.GITHUB_EVENT_NAME;
491
+ if (env.GITHUB_ACTOR) attrs.triggered_by = env.GITHUB_ACTOR;
492
+ if (env.GITHUB_SERVER_URL && env.GITHUB_REPOSITORY && env.GITHUB_RUN_ID) {
493
+ attrs.build_url = `${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}`;
494
+ }
495
+ } else if (env.GITLAB_CI) {
496
+ attrs.ci_provider = 'GitLab CI';
497
+ if (env.CI_PIPELINE_NAME) attrs.pipeline = env.CI_PIPELINE_NAME;
498
+ if (env.CI_PIPELINE_ID) attrs.build_number = env.CI_PIPELINE_ID;
499
+ if (env.CI_PIPELINE_URL) attrs.build_url = env.CI_PIPELINE_URL;
500
+ if (env.CI_PIPELINE_SOURCE) attrs.trigger = env.CI_PIPELINE_SOURCE;
501
+ if (env.CI_COMMIT_SHA) attrs.commit = env.CI_COMMIT_SHA;
502
+ if (env.CI_COMMIT_REF_NAME) attrs.branch = env.CI_COMMIT_REF_NAME;
503
+ if (env.CI_JOB_URL) attrs.ci_job_url = env.CI_JOB_URL;
504
+ if (env.CI_GITLAB_USER_LOGIN) attrs.triggered_by = env.CI_GITLAB_USER_LOGIN;
505
+ } else if (env.JENKINS_URL) {
506
+ attrs.ci_provider = 'Jenkins';
507
+ if (env.JOB_NAME) attrs.pipeline = env.JOB_NAME;
508
+ if (env.BUILD_NUMBER) attrs.build_number = env.BUILD_NUMBER;
509
+ if (env.BUILD_URL) attrs.build_url = env.BUILD_URL;
510
+ if (env.GIT_COMMIT) attrs.commit = env.GIT_COMMIT;
511
+ if (env.BRANCH_NAME) attrs.branch = env.BRANCH_NAME;
512
+ else if (env.GIT_BRANCH) attrs.branch = env.GIT_BRANCH;
513
+ } else if (env.BITBUCKET_PIPELINE_UUID) {
514
+ attrs.ci_provider = 'Bitbucket Pipelines';
515
+ if (env.BITBUCKET_BUILD_NUMBER) attrs.build_number = env.BITBUCKET_BUILD_NUMBER;
516
+ if (env.BITBUCKET_COMMIT) attrs.commit = env.BITBUCKET_COMMIT;
517
+ if (env.BITBUCKET_BRANCH) attrs.branch = env.BITBUCKET_BRANCH;
518
+ if (env.BITBUCKET_REPO_SLUG && env.BITBUCKET_WORKSPACE && env.BITBUCKET_BUILD_NUMBER) {
519
+ attrs.build_url = `https://bitbucket.org/${env.BITBUCKET_WORKSPACE}/${env.BITBUCKET_REPO_SLUG}/pipelines/results/${env.BITBUCKET_BUILD_NUMBER}`;
520
+ }
521
+ } else if (env.TF_BUILD) {
522
+ attrs.ci_provider = 'Azure DevOps';
523
+ if (env.BUILD_DEFINITIONNAME) attrs.pipeline = env.BUILD_DEFINITIONNAME;
524
+ if (env.BUILD_BUILDNUMBER) attrs.build_number = env.BUILD_BUILDNUMBER;
525
+ if (env.BUILD_SOURCEVERSION) attrs.commit = env.BUILD_SOURCEVERSION;
526
+ if (env.BUILD_SOURCEBRANCH) attrs.branch = env.BUILD_SOURCEBRANCH.replace(/^refs\/heads\//, '');
527
+ if (env.BUILD_REASON) attrs.trigger = env.BUILD_REASON;
528
+ if (env.SYSTEM_TEAMFOUNDATIONSERVERURI && env.SYSTEM_TEAMPROJECT && env.BUILD_BUILDID) {
529
+ attrs.build_url = `${env.SYSTEM_TEAMFOUNDATIONSERVERURI}${env.SYSTEM_TEAMPROJECT}/_build/results?buildId=${env.BUILD_BUILDID}`;
530
+ }
531
+ } else if (env.CIRCLECI) {
532
+ attrs.ci_provider = 'CircleCI';
533
+ if (env.CIRCLE_WORKFLOW_JOB_NAME) attrs.pipeline = env.CIRCLE_WORKFLOW_JOB_NAME;
534
+ if (env.CIRCLE_BUILD_NUM) attrs.build_number = env.CIRCLE_BUILD_NUM;
535
+ if (env.CIRCLE_BUILD_URL) attrs.build_url = env.CIRCLE_BUILD_URL;
536
+ if (env.CIRCLE_SHA1) attrs.commit = env.CIRCLE_SHA1;
537
+ if (env.CIRCLE_BRANCH) attrs.branch = env.CIRCLE_BRANCH;
538
+ if (env.CIRCLE_USERNAME) attrs.triggered_by = env.CIRCLE_USERNAME;
539
+ } else if (env.TRAVIS) {
540
+ attrs.ci_provider = 'Travis CI';
541
+ if (env.TRAVIS_BUILD_NUMBER) attrs.build_number = env.TRAVIS_BUILD_NUMBER;
542
+ if (env.TRAVIS_BUILD_WEB_URL) attrs.build_url = env.TRAVIS_BUILD_WEB_URL;
543
+ if (env.TRAVIS_COMMIT) attrs.commit = env.TRAVIS_COMMIT;
544
+ if (env.TRAVIS_BRANCH) attrs.branch = env.TRAVIS_BRANCH;
545
+ if (env.TRAVIS_EVENT_TYPE) attrs.trigger = env.TRAVIS_EVENT_TYPE;
546
+ }
547
+
548
+ return attrs;
549
+ }
550
+
473
551
  function extractAnnotations(test) {
474
552
  const result = {};
475
553
  const caseIdAnn = test?.annotations?.find(a => a?.type === 'caseId')?.description;
@@ -1488,10 +1566,13 @@ export default class M00nReporter {
1488
1566
  return { ok: true };
1489
1567
  }).catch(err => ({ ok: false, error: err }));
1490
1568
 
1491
- // Normalize attributes: flat key-value object
1492
- const attributes = this.opts.attributes && typeof this.opts.attributes === 'object'
1493
- ? { ...this.opts.attributes }
1569
+ // Auto-detect CI environment variables, then overlay user-provided attributes
1570
+ // User attributes always take precedence over auto-detected ones
1571
+ const ciAttrs = detectCIAttributes();
1572
+ const userAttrs = this.opts.attributes && typeof this.opts.attributes === 'object'
1573
+ ? this.opts.attributes
1494
1574
  : {};
1575
+ const attributes = { ...ciAttrs, ...userAttrs };
1495
1576
 
1496
1577
  // Add workers count from Playwright config (useful for timeline visualization)
1497
1578
  if (config.workers != null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m00nsolutions/playwright-reporter",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Playwright test reporter for M00n Report dashboard - real-time test result streaming with step tracking, attachments, and retry support",
5
5
  "main": "index.mjs",
6
6
  "type": "module",