reporting-labs 0.6.12 → 0.6.13
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/README.md +31 -1
- package/bin/cli.js +13 -0
- package/bin/config-template.txt +2 -0
- package/bin/snippets.code-snippets +78 -0
- package/dist/comments.d.ts +26 -0
- package/dist/comments.js +125 -0
- package/dist/reporter.d.ts +2 -0
- package/dist/reporter.js +36 -6
- package/dist/types.d.ts +3 -0
- package/dist/wdio/reporter.d.ts +2 -0
- package/dist/wdio/reporter.js +46 -3
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
<p align="center"><img src="https://raw.githubusercontent.com/naveenautomationlabs/reporting-labs/main/assets/logo-wordmark.svg" alt="reportingLabs" width="320"></p>
|
|
2
2
|
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://www.npmjs.com/package/reporting-labs"><img src="https://img.shields.io/npm/v/reporting-labs.svg?label=npm" alt="npm"></a>
|
|
5
|
+
<a href="https://reportinglabs.dev"><img src="https://img.shields.io/badge/docs-reportinglabs.dev-1A56DB.svg" alt="Docs"></a>
|
|
6
|
+
<a href="https://reportinglabs.dev/support"><img src="https://img.shields.io/badge/%E2%99%A5%20Support-reportingLabs-E5405E?style=flat" alt="Support reportingLabs"></a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
3
9
|
# reportingLabs
|
|
4
10
|
|
|
5
11
|
**A beautiful test report in one HTML file. It tells you what broke, who owns it, and whether it is new.**
|
|
6
12
|
|
|
7
13
|
reportingLabs turns a test run into a single HTML file. No server. No upload. No login. Open the file in a browser, attach it to a CI job, or send it on Slack or email. It just works.
|
|
8
14
|
|
|
9
|
-
Today it ships with a **Playwright** reporter
|
|
15
|
+
Today it ships with a **Playwright** reporter and a **WebdriverIO** reporter. Cypress and Jest/Vitest are on the roadmap. The same report is also available for [Java](https://github.com/naveenautomationlabs/reporting-labs-java) and [Python](https://github.com/naveenautomationlabs/reporting-labs-python).
|
|
16
|
+
|
|
17
|
+
> ♥ **Free and open source, no paid tier.** If reportingLabs saves your team time, [support its development](https://reportinglabs.dev/support) (Razorpay for India, Stripe for everywhere else). A ⭐ on GitHub helps too.
|
|
10
18
|
|
|
11
19
|
<p align="center"><img src="https://raw.githubusercontent.com/naveenautomationlabs/reporting-labs/main/docs/quickstart.gif" alt="reportingLabs in three steps: install, tag your tests, open one HTML file" width="900"></p>
|
|
12
20
|
|
|
@@ -113,6 +121,28 @@ One line per test. With this the report can rank failures by priority, group the
|
|
|
113
121
|
- Forgot one? After every run the console lists the tests that have no `meta()`, with file and line. Turn it off with `warnMissingMeta: false`.
|
|
114
122
|
- `priority`, `severity`, `feature` and `owner` each get a tab in the Breakdown chart and a filter on the Tests page. Want the same for your own key, say `meta({ team: 'web' })`? Add it to `dimensions` in the config: `dimensions: ['priority', 'severity', 'feature', 'owner', 'team']`.
|
|
115
123
|
|
|
124
|
+
### Or write it as a comment (no code change)
|
|
125
|
+
|
|
126
|
+
`meta()` stays the main way. If your team prefers not to add calls to the tests, the same meta can sit in a comment right above the test or `test.describe`:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
/**
|
|
130
|
+
* Completes a purchase with a saved card.
|
|
131
|
+
* @priority P0 @owner naveen @feature payment @story SHOP-250
|
|
132
|
+
* @smoke
|
|
133
|
+
*/
|
|
134
|
+
test('completes purchase', async ({ page }) => {
|
|
135
|
+
// ... your test as usual, no meta() needed
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
- `@key value` pairs become meta (known keys, plus keys in `dimensions` or `links`). A line of bare `@words` (` * @smoke @regression`) becomes tags, so `@P0` and `@critical` still set priority and severity; a mention inside a sentence ("reported by @naveen") is ignored.
|
|
140
|
+
- A comment above `test.describe` applies to every test inside; the test's own comment wins over it.
|
|
141
|
+
- If a test has both, **`meta()` wins** over the comment.
|
|
142
|
+
- Only a comment touching the test counts: a file header separated by a blank line is ignored, and so are JSDoc tags like `@param`.
|
|
143
|
+
- Works with the WebdriverIO reporter too (above `it()` / `describe()`). Turn it off with `commentMeta: false`.
|
|
144
|
+
- **Snippets:** `npx reporting-labs snippets` adds VS Code snippets, so you type `rlmeta` (or `rltest`, `rlit`, `rldescribe`) and press Tab instead of writing the comment by hand. `init` adds them too.
|
|
145
|
+
|
|
116
146
|
### `log()`: a line in the report
|
|
117
147
|
|
|
118
148
|
```ts
|
package/bin/cli.js
CHANGED
|
@@ -5,10 +5,21 @@ const args = process.argv.slice(2);
|
|
|
5
5
|
const cmd = args[0];
|
|
6
6
|
const has = f => args.includes(f);
|
|
7
7
|
|
|
8
|
+
/** Editor snippets (rlmeta, rltest, rlit, rldescribe) in .vscode/, so meta comments are one word + Tab away. */
|
|
9
|
+
function writeSnippets(force) {
|
|
10
|
+
const file = path.resolve('.vscode', 'reporting-labs.code-snippets');
|
|
11
|
+
if (fs.existsSync(file) && !force) return `.vscode/reporting-labs.code-snippets already exists (use --force to replace it).`;
|
|
12
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
13
|
+
fs.copyFileSync(path.join(__dirname, 'snippets.code-snippets'), file);
|
|
14
|
+
return 'Created .vscode/reporting-labs.code-snippets: in VS Code type rlmeta, rltest, rlit or rldescribe and press Tab.';
|
|
15
|
+
}
|
|
16
|
+
|
|
8
17
|
if (cmd === 'merge') {
|
|
9
18
|
const { merge, parseArgs } = require('./merge');
|
|
10
19
|
const { dirs, opts } = parseArgs(args.slice(1));
|
|
11
20
|
merge(dirs, opts);
|
|
21
|
+
} else if (cmd === 'snippets') {
|
|
22
|
+
console.log(writeSnippets(has('--force')));
|
|
12
23
|
} else if (cmd === 'init') {
|
|
13
24
|
const js = has('--js');
|
|
14
25
|
const file = path.resolve(js ? 'reporting-labs.config.js' : 'reporting-labs.config.ts');
|
|
@@ -35,12 +46,14 @@ if (cmd === 'merge') {
|
|
|
35
46
|
console.log(` import reportingLabs from './${base}';`);
|
|
36
47
|
}
|
|
37
48
|
console.log(" reporter: [['list'], ['reporting-labs', reportingLabs]],");
|
|
49
|
+
if (!has('--no-snippets')) { console.log(''); console.log(writeSnippets(false)); }
|
|
38
50
|
} else {
|
|
39
51
|
console.log(`reporting-labs
|
|
40
52
|
|
|
41
53
|
npx reporting-labs init write reporting-labs.config.ts with every option, commented
|
|
42
54
|
npx reporting-labs init --js same, as reporting-labs.config.js
|
|
43
55
|
npx reporting-labs init --force overwrite an existing config file
|
|
56
|
+
npx reporting-labs snippets add VS Code snippets: rlmeta, rltest, rlit, rldescribe (meta comments)
|
|
44
57
|
npx reporting-labs merge <dirs> combine several shard runs into one report (see 'merge --help')
|
|
45
58
|
|
|
46
59
|
Then in playwright.config.ts:
|
package/bin/config-template.txt
CHANGED
|
@@ -38,6 +38,8 @@ const config: ReportingLabsOptions = {
|
|
|
38
38
|
// announce: true, // print the report path after the run
|
|
39
39
|
// open: 'on-failure', // open the report in the browser: 'on-failure' | 'always' | 'never'; never in CI
|
|
40
40
|
// warnMissingMeta: true, // after the run, list tests that have no meta() in the console
|
|
41
|
+
// commentMeta: true, // read meta from a comment above a test: /** @owner naveen @priority P0 */ (meta() wins)
|
|
42
|
+
// pdf: true, // also write a print-ready report.pdf (false to skip, { file } to rename, { chromePath } to name the browser)
|
|
41
43
|
|
|
42
44
|
// ── Test details ─────────────────────────────────────────────────────────────
|
|
43
45
|
// Values come from meta({ priority, severity, owner, feature, epic, story, ... }) in your tests.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"reportingLabs: meta comment": {
|
|
3
|
+
"scope": "javascript,typescript,javascriptreact,typescriptreact",
|
|
4
|
+
"prefix": ["rlmeta", "/**rl"],
|
|
5
|
+
"description": "reportingLabs meta as a comment above a test or describe",
|
|
6
|
+
"body": [
|
|
7
|
+
"/**",
|
|
8
|
+
" * @priority ${1|P0,P1,P2,P3,P4|} @owner ${2:name} @feature ${3:area}",
|
|
9
|
+
" * @story ${4:SHOP-123}",
|
|
10
|
+
" */"
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
"reportingLabs: Playwright test with meta": {
|
|
14
|
+
"scope": "javascript,typescript,javascriptreact,typescriptreact",
|
|
15
|
+
"prefix": "rltest",
|
|
16
|
+
"description": "A Playwright test with reportingLabs meta in a comment",
|
|
17
|
+
"body": [
|
|
18
|
+
"/**",
|
|
19
|
+
" * @priority ${1|P0,P1,P2,P3,P4|} @owner ${2:name} @feature ${3:area}",
|
|
20
|
+
" * @story ${4:SHOP-123}",
|
|
21
|
+
" */",
|
|
22
|
+
"test('${5:does something}', async ({ page }) => {",
|
|
23
|
+
"\t$0",
|
|
24
|
+
"});"
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
"reportingLabs: WebdriverIO it() with meta": {
|
|
28
|
+
"scope": "javascript,typescript",
|
|
29
|
+
"prefix": "rlit",
|
|
30
|
+
"description": "A WebdriverIO / Mocha test with reportingLabs meta in a comment",
|
|
31
|
+
"body": [
|
|
32
|
+
"/**",
|
|
33
|
+
" * @priority ${1|P0,P1,P2,P3,P4|} @owner ${2:name} @feature ${3:area}",
|
|
34
|
+
" * @story ${4:SHOP-123}",
|
|
35
|
+
" */",
|
|
36
|
+
"it('${5:does something}', async () => {",
|
|
37
|
+
"\t$0",
|
|
38
|
+
"});"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"reportingLabs: describe with meta": {
|
|
42
|
+
"scope": "javascript,typescript,javascriptreact,typescriptreact",
|
|
43
|
+
"prefix": "rldescribe",
|
|
44
|
+
"description": "A describe block whose meta applies to every test inside",
|
|
45
|
+
"body": [
|
|
46
|
+
"/** @owner ${1:name} @feature ${2:area} */",
|
|
47
|
+
"${3|test.describe,describe|}('${4:Feature}', () => {",
|
|
48
|
+
"\t$0",
|
|
49
|
+
"});"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"reportingLabs: meta in a docstring": {
|
|
53
|
+
"scope": "python",
|
|
54
|
+
"prefix": "rlmeta",
|
|
55
|
+
"description": "reportingLabs meta in a test docstring",
|
|
56
|
+
"body": [
|
|
57
|
+
"\"\"\"${1:What this test checks}.",
|
|
58
|
+
"",
|
|
59
|
+
"@priority ${2|P0,P1,P2,P3,P4|} @owner ${3:name} @feature ${4:area}",
|
|
60
|
+
"@story ${5:SHOP-123}",
|
|
61
|
+
"\"\"\""
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"reportingLabs: pytest test with meta": {
|
|
65
|
+
"scope": "python",
|
|
66
|
+
"prefix": "rltest",
|
|
67
|
+
"description": "A pytest test with reportingLabs meta in its docstring",
|
|
68
|
+
"body": [
|
|
69
|
+
"def test_${1:does_something}(${2:page}):",
|
|
70
|
+
"\t\"\"\"${3:What this test checks}.",
|
|
71
|
+
"",
|
|
72
|
+
"\t@priority ${4|P0,P1,P2,P3,P4|} @owner ${5:name} @feature ${6:area}",
|
|
73
|
+
"\t@story ${7:SHOP-123}",
|
|
74
|
+
"\t\"\"\"",
|
|
75
|
+
"\t$0"
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Meta written as a comment right above a test or describe, so a team can tag tests without calling meta():
|
|
3
|
+
*
|
|
4
|
+
* /**
|
|
5
|
+
* * @owner naveen @priority P0 @jira SHOP-12
|
|
6
|
+
* * @smoke
|
|
7
|
+
* *\/
|
|
8
|
+
* test('places an order', async ({ page }) => { ... });
|
|
9
|
+
*
|
|
10
|
+
* `@key value` pairs become meta; a bare `@word` on a line of tags becomes a tag (so `@P0` / `@critical` still set
|
|
11
|
+
* priority and severity), while a mention inside a sentence ("reported by @naveen") is ignored. Only a comment that
|
|
12
|
+
* starts its own line and touches the test line counts: a file header separated by a blank line does not.
|
|
13
|
+
* JSDoc's own tags (@param, @returns, @ts-ignore...) are ignored.
|
|
14
|
+
*/
|
|
15
|
+
export interface CommentMeta {
|
|
16
|
+
meta: Record<string, string>;
|
|
17
|
+
tags: string[];
|
|
18
|
+
}
|
|
19
|
+
/** The text of the comment that ends on the line just above `line` (1-based), or ''. */
|
|
20
|
+
export declare function commentAbove(file: string, line: number): string;
|
|
21
|
+
/** `@key value` pairs and bare `@tags` in a comment's text. A value runs to the next ` @key` or the end of the line. */
|
|
22
|
+
export declare function parseCommentMeta(text: string): CommentMeta;
|
|
23
|
+
/** Comment meta for one location, or empty. */
|
|
24
|
+
export declare function commentMetaAt(file: string, line: number): CommentMeta;
|
|
25
|
+
/** Find the line of `it('title'` / `test("title"` / `describe(`title`` in a file (WebdriverIO gives no line). */
|
|
26
|
+
export declare function lineOfTitle(file: string, title: string, kinds?: string, after?: number): number;
|
package/dist/comments.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.commentAbove = commentAbove;
|
|
37
|
+
exports.parseCommentMeta = parseCommentMeta;
|
|
38
|
+
exports.commentMetaAt = commentMetaAt;
|
|
39
|
+
exports.lineOfTitle = lineOfTitle;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const JSDOC = new Set(['param', 'arg', 'argument', 'returns', 'return', 'type', 'typedef', 'template', 'example', 'see', 'link',
|
|
42
|
+
'throws', 'exception', 'deprecated', 'since', 'callback', 'property', 'prop', 'override', 'private', 'public', 'protected',
|
|
43
|
+
'readonly', 'async', 'function', 'func', 'method', 'class', 'constructor', 'module', 'namespace', 'memberof', 'inheritdoc',
|
|
44
|
+
'default', 'description', 'summary', 'version', 'license', 'file', 'fileoverview', 'internal', 'ignore', 'satisfies', 'jsx',
|
|
45
|
+
'flow', 'format', 'vitest-environment', 'jest-environment']);
|
|
46
|
+
const sources = new Map();
|
|
47
|
+
function linesOf(file) {
|
|
48
|
+
if (!sources.has(file)) {
|
|
49
|
+
try {
|
|
50
|
+
sources.set(file, fs.readFileSync(file, 'utf8').split(/\r?\n/));
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
sources.set(file, null);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return sources.get(file) ?? null;
|
|
57
|
+
}
|
|
58
|
+
/** The text of the comment that ends on the line just above `line` (1-based), or ''. */
|
|
59
|
+
function commentAbove(file, line) {
|
|
60
|
+
const lines = linesOf(file);
|
|
61
|
+
if (!lines || line < 2)
|
|
62
|
+
return '';
|
|
63
|
+
let i = line - 2;
|
|
64
|
+
const at = (k) => (lines[k] ?? '').trim();
|
|
65
|
+
if (at(i).endsWith('*/')) {
|
|
66
|
+
const end = i;
|
|
67
|
+
while (i >= 0 && !at(i).includes('/*'))
|
|
68
|
+
i--;
|
|
69
|
+
if (i < 0 || !at(i).startsWith('/*'))
|
|
70
|
+
return ''; // `foo(); /* x */` belongs to the code, not the test
|
|
71
|
+
return lines.slice(i, end + 1).join('\n')
|
|
72
|
+
.replace(/^\s*\/\*+/, '').replace(/\*+\/\s*$/, '')
|
|
73
|
+
.split('\n').map(l => l.replace(/^\s*\*+ ?/, '')).join('\n');
|
|
74
|
+
}
|
|
75
|
+
if (at(i).startsWith('//')) {
|
|
76
|
+
const out = [];
|
|
77
|
+
while (i >= 0 && at(i).startsWith('//')) {
|
|
78
|
+
out.unshift(at(i).replace(/^\/\/+\s?/, ''));
|
|
79
|
+
i--;
|
|
80
|
+
}
|
|
81
|
+
return out.join('\n');
|
|
82
|
+
}
|
|
83
|
+
return '';
|
|
84
|
+
}
|
|
85
|
+
/** `@key value` pairs and bare `@tags` in a comment's text. A value runs to the next ` @key` or the end of the line. */
|
|
86
|
+
function parseCommentMeta(text) {
|
|
87
|
+
const meta = {};
|
|
88
|
+
const tags = [];
|
|
89
|
+
for (const line of text.split('\n')) {
|
|
90
|
+
// a bare @word is a tag only on a line of tags (` * @smoke @regression`), never a mention in a sentence
|
|
91
|
+
const tagLine = line.trim().startsWith('@');
|
|
92
|
+
const re = /(?:^|\s)@([A-Za-z][\w.-]*)(?:[ \t]*[:=][ \t]*|[ \t]+(?!@))?(.*?)(?=\s+@[A-Za-z][\w.-]*|$)/g;
|
|
93
|
+
let m;
|
|
94
|
+
while ((m = re.exec(line))) {
|
|
95
|
+
const key = m[1];
|
|
96
|
+
if (JSDOC.has(key.toLowerCase()) || /^(ts-|eslint|jsx|prettier)/i.test(key))
|
|
97
|
+
continue;
|
|
98
|
+
// `@owner 'naveen'` / `@feature "Cart and checkout"`: the quotes are not part of the value
|
|
99
|
+
const value = m[2].trim().replace(/^(['"`])(.*)\1$/, '$2').trim();
|
|
100
|
+
if (value)
|
|
101
|
+
meta[key.toLowerCase()] = value;
|
|
102
|
+
else if (tagLine && !tags.includes('@' + key))
|
|
103
|
+
tags.push('@' + key);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return { meta, tags };
|
|
107
|
+
}
|
|
108
|
+
/** Comment meta for one location, or empty. */
|
|
109
|
+
function commentMetaAt(file, line) {
|
|
110
|
+
const text = commentAbove(file, line);
|
|
111
|
+
return text ? parseCommentMeta(text) : { meta: {}, tags: [] };
|
|
112
|
+
}
|
|
113
|
+
/** Find the line of `it('title'` / `test("title"` / `describe(`title`` in a file (WebdriverIO gives no line). */
|
|
114
|
+
function lineOfTitle(file, title, kinds = 'it|test|specify|describe|context|suite', after = 0) {
|
|
115
|
+
const lines = linesOf(file);
|
|
116
|
+
if (!lines || !title)
|
|
117
|
+
return 0;
|
|
118
|
+
const esc = title.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
119
|
+
const re = new RegExp(`\\b(?:${kinds})(?:\\.\\w+)*\\s*\\(\\s*(['"\`])${esc}\\1`);
|
|
120
|
+
// search after the enclosing describe's line, so two describes with an it('logs in') each find their own
|
|
121
|
+
for (let i = Math.max(0, after); i < lines.length; i++)
|
|
122
|
+
if (re.test(lines[i]))
|
|
123
|
+
return i + 1;
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
package/dist/reporter.d.ts
CHANGED
|
@@ -45,6 +45,8 @@ export default class ReportingLabsReporter implements Reporter {
|
|
|
45
45
|
* An object value (meta({ octaneTestCase: { id, p } })) is folded to its display text and, when the key has a
|
|
46
46
|
* link template, to a ready-made href in `links`; the other fields never show in the report.
|
|
47
47
|
*/
|
|
48
|
+
/** Meta from comments above the test and its describe blocks (outer first, the test's own comment last). */
|
|
49
|
+
private commentMeta;
|
|
48
50
|
private extractMeta;
|
|
49
51
|
/** A local image file (path relative to the config) is embedded as a data URI so the report stays self-contained. URLs and data URIs pass through. */
|
|
50
52
|
private resolveLogo;
|
package/dist/reporter.js
CHANGED
|
@@ -45,6 +45,7 @@ const template_1 = require("./template");
|
|
|
45
45
|
const mask_1 = require("./mask");
|
|
46
46
|
const explain_1 = require("./explain");
|
|
47
47
|
const pdf_1 = require("./pdf");
|
|
48
|
+
const comments_1 = require("./comments");
|
|
48
49
|
const DEFAULT_EMBED_LIMIT = 2 * 1024 * 1024;
|
|
49
50
|
/** Attach steps created by log() and the automatic API capture; the data shows in its own section, so hide the step. */
|
|
50
51
|
function isInternalAttach(s) {
|
|
@@ -135,7 +136,8 @@ class ReportingLabsReporter {
|
|
|
135
136
|
const last = test.results[test.results.length - 1];
|
|
136
137
|
const resultAnn = (last?.annotations ?? []);
|
|
137
138
|
const annotations = [...test.annotations, ...resultAnn.filter(a => !test.annotations.some(b => b.type === a.type && b.description === a.description))];
|
|
138
|
-
const
|
|
139
|
+
const fromComments = this.commentMeta(test);
|
|
140
|
+
const extracted = this.extractMeta(test, fromComments);
|
|
139
141
|
tests.push({
|
|
140
142
|
id: test.id,
|
|
141
143
|
key: `${project}::${file}::${[...titlePath, test.title].join(' › ')}${test.repeatEachIndex ? ' #' + (test.repeatEachIndex + 1) : ''}`,
|
|
@@ -145,7 +147,7 @@ class ReportingLabsReporter {
|
|
|
145
147
|
line: test.location.line,
|
|
146
148
|
column: test.location.column,
|
|
147
149
|
project,
|
|
148
|
-
tags: test.tags,
|
|
150
|
+
tags: [...test.tags, ...fromComments.tags.filter(g => !test.tags.includes(g))],
|
|
149
151
|
annotations,
|
|
150
152
|
meta: extracted.meta,
|
|
151
153
|
links: Object.keys(extracted.links).length ? extracted.links : undefined,
|
|
@@ -273,7 +275,8 @@ class ReportingLabsReporter {
|
|
|
273
275
|
console.log(` ${(t.file + ':' + t.line).padEnd(w)} ${t.title}`);
|
|
274
276
|
if (missing.length > show.length)
|
|
275
277
|
console.log(` … and ${missing.length - show.length} more`);
|
|
276
|
-
console.log(" Add meta({ priority: 'P1', owner: 'name', feature: 'area' }) at the top of the test
|
|
278
|
+
console.log(" Add meta({ priority: 'P1', owner: 'name', feature: 'area' }) at the top of the test, or a comment right above it:");
|
|
279
|
+
console.log(" /** @priority P1 @owner name @feature area */. Set warnMissingMeta: false to hide this.");
|
|
277
280
|
}
|
|
278
281
|
/** Open the report in the default browser, like Playwright's HTML reporter. Never in CI. */
|
|
279
282
|
maybeOpen(file, result) {
|
|
@@ -423,12 +426,36 @@ class ReportingLabsReporter {
|
|
|
423
426
|
* An object value (meta({ octaneTestCase: { id, p } })) is folded to its display text and, when the key has a
|
|
424
427
|
* link template, to a ready-made href in `links`; the other fields never show in the report.
|
|
425
428
|
*/
|
|
426
|
-
|
|
429
|
+
/** Meta from comments above the test and its describe blocks (outer first, the test's own comment last). */
|
|
430
|
+
commentMeta(test) {
|
|
431
|
+
const out = { meta: {}, tags: [] };
|
|
432
|
+
if (this.options.commentMeta === false)
|
|
433
|
+
return out;
|
|
434
|
+
try {
|
|
435
|
+
const dims = this.metaKeys();
|
|
436
|
+
const at = [];
|
|
437
|
+
for (let s = test.parent; s; s = s.parent)
|
|
438
|
+
if (s.type === 'describe' && s.location)
|
|
439
|
+
at.unshift(s.location);
|
|
440
|
+
at.push(test.location);
|
|
441
|
+
for (const loc of at) {
|
|
442
|
+
const c = (0, comments_1.commentMetaAt)(loc.file, loc.line);
|
|
443
|
+
Object.assign(out.meta, c.meta);
|
|
444
|
+
// a meta key left without a value (`@priority`) is not a tag
|
|
445
|
+
for (const g of c.tags)
|
|
446
|
+
if (!out.tags.includes(g) && !dims.includes(g.slice(1).toLowerCase()))
|
|
447
|
+
out.tags.push(g);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
catch { /* comments are a convenience: never fail the report over them */ }
|
|
451
|
+
return out;
|
|
452
|
+
}
|
|
453
|
+
extractMeta(test, fromComments = { meta: {}, tags: [] }) {
|
|
427
454
|
const dims = this.metaKeys();
|
|
428
455
|
const meta = {};
|
|
429
456
|
const links = {};
|
|
430
|
-
// Tags first (describe-level, then test-level),
|
|
431
|
-
for (const raw of test.tags) {
|
|
457
|
+
// Tags first (describe-level, then test-level), then comments, then annotations: meta() in the code wins.
|
|
458
|
+
for (const raw of [...test.tags, ...fromComments.tags]) {
|
|
432
459
|
const tag = raw.replace(/^@/, '');
|
|
433
460
|
const m = tag.match(/^([a-z_-]+)[:=](.+)$/i);
|
|
434
461
|
if (m && dims.includes(m[1].toLowerCase())) {
|
|
@@ -440,6 +467,9 @@ class ReportingLabsReporter {
|
|
|
440
467
|
if (/^(blocker|critical|major|minor|trivial)$/i.test(tag) && dims.includes('severity') && !meta.severity)
|
|
441
468
|
meta.severity = tag.toLowerCase();
|
|
442
469
|
}
|
|
470
|
+
for (const [k, v] of Object.entries(fromComments.meta))
|
|
471
|
+
if (dims.includes(k))
|
|
472
|
+
meta[k] = v;
|
|
443
473
|
for (const a of test.annotations) {
|
|
444
474
|
const k = a.type.toLowerCase();
|
|
445
475
|
if (!dims.includes(k) || !a.description)
|
package/dist/types.d.ts
CHANGED
|
@@ -27,6 +27,9 @@ export interface ReportingLabsOptions {
|
|
|
27
27
|
file?: string;
|
|
28
28
|
chromePath?: string;
|
|
29
29
|
};
|
|
30
|
+
/** Read meta from a comment right above a test or describe: `/** @owner naveen @priority P0 *\/`. `@key value`
|
|
31
|
+
* pairs become meta, a bare `@word` a tag; meta() in the test wins. Default: true */
|
|
32
|
+
commentMeta?: boolean;
|
|
30
33
|
/** Inline screenshots as base64 (single file, opens anywhere). Default: true */
|
|
31
34
|
embedAttachments?: boolean;
|
|
32
35
|
/** Max size (bytes) of a single attachment to embed. Larger ones are copied as files. Default: 2 MB */
|
package/dist/wdio/reporter.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export interface ReportingLabsWdioOptions {
|
|
|
19
19
|
maskKeys?: string[];
|
|
20
20
|
maskValues?: string[];
|
|
21
21
|
maskFromEnv?: boolean;
|
|
22
|
+
/** Read meta from a comment right above it() / describe(): `/** @owner naveen @priority P0 *\/`. Default: true */
|
|
23
|
+
commentMeta?: boolean;
|
|
22
24
|
[k: string]: unknown;
|
|
23
25
|
}
|
|
24
26
|
export default class ReportingLabsWdioReporter extends EventEmitter {
|
package/dist/wdio/reporter.js
CHANGED
|
@@ -52,6 +52,8 @@ const fs = __importStar(require("fs"));
|
|
|
52
52
|
const path = __importStar(require("path"));
|
|
53
53
|
const mask_1 = require("../mask");
|
|
54
54
|
const explain_1 = require("../explain");
|
|
55
|
+
const comments_1 = require("../comments");
|
|
56
|
+
const url_1 = require("url");
|
|
55
57
|
const META_KEYS = ['priority', 'severity', 'feature', 'owner', 'epic', 'story', 'issue', 'bug', 'component', 'module', 'team', 'sprint', 'testcase', 'tms', 'requirement'];
|
|
56
58
|
exports.META_KEYS = META_KEYS;
|
|
57
59
|
/** WebDriver command name → readable step verb. Commands not listed (reads, internals) are not steps. */
|
|
@@ -121,14 +123,43 @@ class ReportingLabsWdioReporter extends node_events_1.EventEmitter {
|
|
|
121
123
|
retry: test.retries || 0, status: 'passed', duration: 0, startTime: now, workerIndex: numericCid(this.cid),
|
|
122
124
|
errors: [], steps: [], attachments: [], stdout: [], stderr: [], logs: [], data: [], api: [],
|
|
123
125
|
};
|
|
124
|
-
const
|
|
126
|
+
const abs = srcPath(test.file || this.specs[0] || '');
|
|
127
|
+
const file = this.rel(abs);
|
|
125
128
|
const tagSource = [test.title || '', ...this.suiteStack].join(' ');
|
|
126
|
-
const tags =
|
|
129
|
+
const tags = tagSource.match(/@[A-Za-z][\w:.=-]*/g) || [];
|
|
130
|
+
// WDIO gives no line numbers: find it('title') in the spec, for the source link and the comment above it
|
|
131
|
+
// Each describe is looked up after the one around it, then the test after its own describe.
|
|
132
|
+
const at = [];
|
|
133
|
+
let from = 0;
|
|
134
|
+
for (const st of this.suiteStack) {
|
|
135
|
+
const ln = abs ? (0, comments_1.lineOfTitle)(abs, st, 'describe|context|suite', from) : 0;
|
|
136
|
+
if (ln) {
|
|
137
|
+
at.push(ln);
|
|
138
|
+
from = ln;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const line = abs ? (0, comments_1.lineOfTitle)(abs, test.title || '', 'it|test|specify', from) : 0;
|
|
142
|
+
const fromComments = {};
|
|
143
|
+
if (abs && this.options.commentMeta !== false) {
|
|
144
|
+
try {
|
|
145
|
+
for (const ln of [...at, line].filter(Boolean)) {
|
|
146
|
+
const c = (0, comments_1.commentMetaAt)(abs, ln);
|
|
147
|
+
Object.assign(fromComments, c.meta);
|
|
148
|
+
for (const g of c.tags)
|
|
149
|
+
if (!tags.includes(g) && !META_KEYS.includes(g.slice(1).toLowerCase()))
|
|
150
|
+
tags.push(g);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch { /* comments are a convenience: never fail the run over them */ }
|
|
154
|
+
}
|
|
127
155
|
const { meta } = metaFromTags(tags, META_KEYS);
|
|
156
|
+
for (const [k, v] of Object.entries(fromComments))
|
|
157
|
+
if (META_KEYS.includes(k))
|
|
158
|
+
meta[k] = this.masker.maskStr(v);
|
|
128
159
|
const t = {
|
|
129
160
|
id: test.uid || `${file}:${test.title}`,
|
|
130
161
|
key: '', title: this.masker.maskStr(test.title || ''), path: this.suiteStack.map(s => this.masker.maskStr(s)),
|
|
131
|
-
file, line
|
|
162
|
+
file, line, project: this.capsName, tags, annotations: [], meta,
|
|
132
163
|
outcome: 'passed', duration: 0, results: [result], retries: test.retries,
|
|
133
164
|
};
|
|
134
165
|
t.key = `${t.project}::${t.file}::${[...t.path, t.title].join(' › ')}`;
|
|
@@ -237,6 +268,7 @@ class ReportingLabsWdioReporter extends node_events_1.EventEmitter {
|
|
|
237
268
|
catch { /* best-effort; finalize will simply see fewer parts */ }
|
|
238
269
|
}
|
|
239
270
|
rel(file) {
|
|
271
|
+
file = srcPath(file);
|
|
240
272
|
if (!file)
|
|
241
273
|
return file;
|
|
242
274
|
try {
|
|
@@ -330,3 +362,14 @@ function metaFromTags(tags, dims) {
|
|
|
330
362
|
}
|
|
331
363
|
return { meta, clean };
|
|
332
364
|
}
|
|
365
|
+
/** A spec path WDIO may hand over as a file:// URL. */
|
|
366
|
+
function srcPath(f) {
|
|
367
|
+
if (!f.startsWith('file:'))
|
|
368
|
+
return f;
|
|
369
|
+
try {
|
|
370
|
+
return (0, url_1.fileURLToPath)(f);
|
|
371
|
+
}
|
|
372
|
+
catch {
|
|
373
|
+
return f;
|
|
374
|
+
}
|
|
375
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reporting-labs",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.13",
|
|
4
4
|
"description": "reportingLabs – beautiful, customizable single-file HTML test reports. One line of config. Playwright adapter included, more runners on the way.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"test-report",
|
|
@@ -71,6 +71,10 @@
|
|
|
71
71
|
"bugs": {
|
|
72
72
|
"url": "https://github.com/naveenautomationlabs/reporting-labs/issues"
|
|
73
73
|
},
|
|
74
|
+
"funding": {
|
|
75
|
+
"type": "individual",
|
|
76
|
+
"url": "https://reportinglabs.dev/support"
|
|
77
|
+
},
|
|
74
78
|
"engines": {
|
|
75
79
|
"node": ">=18"
|
|
76
80
|
},
|