@test2doc/playwright 0.3.3 → 0.5.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.
- package/README.md +28 -10
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -10
- package/dist/index.js.map +1 -1
- package/dist/screenshots.d.ts.map +1 -1
- package/dist/screenshots.js +17 -2
- package/dist/screenshots.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,9 +11,9 @@ The `@test2doc/playwright` package is a [Playwright](https://playwright.dev/) re
|
|
|
11
11
|
If you don't have Playwright currently installed, you can follow [Playwright's installation guide](https://playwright.dev/docs/intro#installing-playwright). (Don't forget to run `npx playwright install` to install browsers after Playwright itself!)
|
|
12
12
|
|
|
13
13
|
#### Docusaurus
|
|
14
|
-
This reporter generates markdown files for Docusaurus. If you don't have a Docusaurus app set up yet there is an install guide [here](https://docusaurus.io/docs/installation). If you have a monorepo I recommend using these [instructions](https://docusaurus.io/docs/installation#monorepos)
|
|
14
|
+
This reporter generates markdown files for Docusaurus. If you don't have a Docusaurus app set up yet, there is an install guide [here](https://docusaurus.io/docs/installation). If you have a monorepo, I recommend using these [instructions](https://docusaurus.io/docs/installation#monorepos).
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Alternatively, you can install the Docusaurus app within your current repo with:
|
|
17
17
|
|
|
18
18
|
```sh
|
|
19
19
|
npx create-docusaurus@latest doc classic --typescript
|
|
@@ -22,7 +22,7 @@ npx create-docusaurus@latest doc classic --typescript
|
|
|
22
22
|
This will make a `doc` directory with your Docusaurus app.
|
|
23
23
|
|
|
24
24
|
### Install the Reporter
|
|
25
|
-
After installing Playwright you can add the `@test2doc/playwright` with your package manager of choice:
|
|
25
|
+
After installing Playwright, you can add the `@test2doc/playwright` with your package manager of choice:
|
|
26
26
|
|
|
27
27
|
```sh
|
|
28
28
|
# npm
|
|
@@ -34,7 +34,7 @@ pnpm install @test2doc/playwright -D
|
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
#### Configure Playwright to work with Test2Doc's Reporter
|
|
37
|
-
Create a new config to run Test2Doc
|
|
37
|
+
Create a new config to run Test2Doc: `playwright-test2doc.config.ts`
|
|
38
38
|
|
|
39
39
|
```ts
|
|
40
40
|
// playwright-test2doc.config.ts
|
|
@@ -86,11 +86,11 @@ export default defineConfig({
|
|
|
86
86
|
|
|
87
87
|
Replace `"./doc/docs"` with a path to the `doc` directory of your Docusaurus app.
|
|
88
88
|
|
|
89
|
-
##### Add script to run
|
|
89
|
+
##### Add script to run Playwright to generate docs
|
|
90
90
|
|
|
91
91
|
Also add a script to build the docs in your project's `package.json`.
|
|
92
92
|
|
|
93
|
-
The `TEST2DOC=true` is required to activate the test2doc metadata to pass to the tests in a headless context. For normal test runs you probably don't want the extra noise of the metadata, so leave this out of your standard test run.
|
|
93
|
+
The `TEST2DOC=true` is required to activate the test2doc metadata to pass to the tests in a headless context. For normal test runs, you probably don't want the extra noise of the metadata, so leave this out of your standard test run.
|
|
94
94
|
|
|
95
95
|
```json
|
|
96
96
|
{
|
|
@@ -104,16 +104,16 @@ The `TEST2DOC=true` is required to activate the test2doc metadata to pass to the
|
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
## Verify installation
|
|
107
|
-
To verify your setup works, run `npm run docs:generate` and check that markdown files appear in your `./doc/docs` directory, or
|
|
107
|
+
To verify your setup works, run `npm run docs:generate` and check that markdown files appear in your `./doc/docs` directory, or wherever you specified the output directory in the `playwright-test2doc.config.ts` file.
|
|
108
108
|
|
|
109
109
|
## How it works
|
|
110
110
|
|
|
111
|
-
After this setup, every time you run your Playwright tests, the `@test2doc/playwright` reporter will automatically generate a new markdown file in your specified Docusaurus docs directory for each top-level describe block found in your Playwright test files.
|
|
111
|
+
After this setup, every time you run your Playwright tests, the `@test2doc/playwright` reporter will automatically generate a new markdown file in your specified Docusaurus docs directory for each test file and/or top-level describe block found in your Playwright test files.
|
|
112
112
|
|
|
113
113
|
### Adding Docusaurus Page Metadata
|
|
114
114
|
Docusaurus supports [markdown front matter](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs#markdown-front-matter) to allow for more control of pages and to help position links in the sidebar.
|
|
115
115
|
|
|
116
|
-
To add this metadata to the test2doc markdown files that are generated use the `withDocMeta` function in your
|
|
116
|
+
To add this metadata to the test2doc markdown files that are generated, use the `withDocMeta` function in your describe blocks in your test.
|
|
117
117
|
|
|
118
118
|
```ts
|
|
119
119
|
import { withDocMeta } from "@test2doc/playwright/DocMeta";
|
|
@@ -131,7 +131,7 @@ describe(withDocMeta("Title of Page", {
|
|
|
131
131
|
})
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
-
### Adding Docusaurus Category
|
|
134
|
+
### Adding Docusaurus Category Routes
|
|
135
135
|
Docusaurus supports grouping docs by [category](https://docusaurus.io/docs/sidebar/autogenerated#category-item-metadata).
|
|
136
136
|
|
|
137
137
|
By using the `withDocCategory` function for a describe block's title, this will add the metadata to allow Test2Doc to generate a new directory and a `__category__.json` file. It will then place all subsequent describes and tests under this new route.
|
|
@@ -179,4 +179,22 @@ test.describe(withDocMeta("describe block"), async () => {
|
|
|
179
179
|
})
|
|
180
180
|
})
|
|
181
181
|
})
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### Highlight an element
|
|
185
|
+
It's possible to highlight an element by passing in a locator of an element on the page.
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import { screenshot } from "@test2doc/playwright/screenshots"
|
|
189
|
+
...
|
|
190
|
+
|
|
191
|
+
test.describe(withDocMeta("describe block"), async () => {
|
|
192
|
+
test("test block", async ({ page }, testInfo) => {
|
|
193
|
+
...
|
|
194
|
+
test.step("step block", async () => {
|
|
195
|
+
await page.goto("http://localhost:5173/")
|
|
196
|
+
await screenshot(testInfo, page.getByRole("header", {name: "Page Title"}))
|
|
197
|
+
})
|
|
198
|
+
})
|
|
199
|
+
})
|
|
182
200
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ declare class Test2DocReporter implements Reporter {
|
|
|
14
14
|
private seenScreenshot;
|
|
15
15
|
constructor(options?: Test2DocReporterOptions);
|
|
16
16
|
onBegin(_config: FullConfig, suite: Suite): void;
|
|
17
|
+
private buildTestDocTree;
|
|
18
|
+
private buildDocTests;
|
|
17
19
|
private buildDocTree;
|
|
18
20
|
onStepBegin(test: TestCase, _result: TestResult, step: TestStep): void;
|
|
19
21
|
onStepEnd(test: TestCase, result: TestResult, step: TestStep): void;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,EACT,MAAM,2BAA2B,CAAA;AAoClC,UAAU,uBAAuB;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAwBD;;;GAGG;AACH,cAAM,gBAAiB,YAAW,QAAQ;IACxC,OAAO,CAAC,IAAI,CAAgB;IAC5B,OAAO,CAAC,MAAM,CAA4C;IAC1D,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,mBAAmB,CAAsB;IACjD,OAAO,CAAC,cAAc,CAAoB;gBAGxC,OAAO,GAAE,uBAER;IAKH,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK;IAUzC,OAAO,CAAC,YAAY;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,EACT,MAAM,2BAA2B,CAAA;AAoClC,UAAU,uBAAuB;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAwBD;;;GAGG;AACH,cAAM,gBAAiB,YAAW,QAAQ;IACxC,OAAO,CAAC,IAAI,CAAgB;IAC5B,OAAO,CAAC,MAAM,CAA4C;IAC1D,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,mBAAmB,CAAsB;IACjD,OAAO,CAAC,cAAc,CAAoB;gBAGxC,OAAO,GAAE,uBAER;IAKH,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK;IAUzC,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,YAAY;IAmBpB,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,IAAI;IAOtE,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,IAAI;IAqBnE,KAAK;IAKL,OAAO,CAAC,aAAa;IA4BrB,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,kBAAkB;IAW1B,OAAO,CAAC,cAAc;IAiCtB,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,gBAAgB;CA6BzB;AAED,eAAe,gBAAgB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -22,9 +22,30 @@ class Test2DocReporter {
|
|
|
22
22
|
onBegin(_config, suite) {
|
|
23
23
|
this.docs = [];
|
|
24
24
|
this.docMap.clear();
|
|
25
|
-
// this.docMap.set(suite.title, this.docs)
|
|
26
25
|
this.docs =
|
|
27
|
-
suite.suites[0]?.suites.flatMap(({ suites
|
|
26
|
+
suite.suites[0]?.suites.flatMap(({ suites, tests, title }) => [
|
|
27
|
+
...suites.map((s) => this.buildDocTree(s)),
|
|
28
|
+
...(tests.length > 0 ? [this.buildTestDocTree(title, tests)] : []),
|
|
29
|
+
]) || [];
|
|
30
|
+
}
|
|
31
|
+
buildTestDocTree(filename, tests) {
|
|
32
|
+
const title = filename.match(/^(.*?)\.(test|spec)\.(ts|js)$/)?.[1] ?? filename;
|
|
33
|
+
const docNode = {
|
|
34
|
+
title: title,
|
|
35
|
+
children: [],
|
|
36
|
+
tests: this.buildDocTests(tests),
|
|
37
|
+
};
|
|
38
|
+
return docNode;
|
|
39
|
+
}
|
|
40
|
+
buildDocTests(tests) {
|
|
41
|
+
return tests.map((test) => {
|
|
42
|
+
const testDoc = {
|
|
43
|
+
title: test.title,
|
|
44
|
+
steps: [],
|
|
45
|
+
};
|
|
46
|
+
this.docMap.set(test.title, testDoc);
|
|
47
|
+
return testDoc;
|
|
48
|
+
});
|
|
28
49
|
}
|
|
29
50
|
buildDocTree(suite) {
|
|
30
51
|
const docNode = {
|
|
@@ -36,14 +57,8 @@ class Test2DocReporter {
|
|
|
36
57
|
this.docMap.set(child.title, childDocNode);
|
|
37
58
|
docNode.children.push(childDocNode);
|
|
38
59
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
title: test.title,
|
|
42
|
-
steps: [],
|
|
43
|
-
};
|
|
44
|
-
this.docMap.set(test.title, testDoc);
|
|
45
|
-
docNode.tests = docNode.tests || [];
|
|
46
|
-
docNode.tests.push(testDoc);
|
|
60
|
+
if (suite.tests.length > 0) {
|
|
61
|
+
docNode.tests = this.buildDocTests(suite.tests);
|
|
47
62
|
}
|
|
48
63
|
return docNode;
|
|
49
64
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,SAAS,EACT,WAAW,EACX,QAAQ,EACR,UAAU,EACV,aAAa,GACd,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAM/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AA4ChC,0EAA0E;AAC1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EACtB,UAAU,qBAAqB,GAAG,qCAAqC,
|
|
1
|
+
{"version":3,"file":"screenshots.d.ts","sourceRoot":"","sources":["../src/screenshots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,IAAI,EACJ,qCAAqC,EACrC,qBAAqB,EACrB,QAAQ,EACT,MAAM,kBAAkB,CAAA;AAIzB,eAAO,MAAM,UAAU,GACrB,UAAU,QAAQ,EAClB,QAAQ,IAAI,GAAG,OAAO,EACtB,UAAU,qBAAqB,GAAG,qCAAqC,kBA0BxE,CAAA"}
|
package/dist/screenshots.js
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
let screenshotCounter = 0;
|
|
2
2
|
export const screenshot = async (testInfo, target, options) => {
|
|
3
3
|
const filename = `test2doc-${Date.now()}-${++screenshotCounter}.png`;
|
|
4
|
-
|
|
4
|
+
let screenshot;
|
|
5
|
+
if ("highlight" in target) {
|
|
6
|
+
// Target is a locator - highlight it first, then get its page
|
|
7
|
+
await target.highlight();
|
|
8
|
+
const page = target.page();
|
|
9
|
+
screenshot = await page.screenshot(options);
|
|
10
|
+
// Remove highlighting after taking the screenshot
|
|
11
|
+
const glassElements = page.locator("X-PW-GLASS");
|
|
12
|
+
await glassElements.evaluateAll((elements) => {
|
|
13
|
+
elements.forEach((el) => el.remove());
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
// Target is already a page
|
|
18
|
+
screenshot = await target.screenshot(options);
|
|
19
|
+
}
|
|
5
20
|
await testInfo.attach(filename, {
|
|
6
|
-
body:
|
|
21
|
+
body: screenshot,
|
|
7
22
|
contentType: "image/png",
|
|
8
23
|
});
|
|
9
24
|
};
|
package/dist/screenshots.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshots.js","sourceRoot":"","sources":["../src/screenshots.ts"],"names":[],"mappings":"AAQA,IAAI,iBAAiB,GAAG,CAAC,CAAA;AAEzB,MAAM,CAAC,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