@thisisagile/easy-playwright 20.1.1 → 21.0.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 +11 -0
- package/dist/PlaywrightTester.d.ts +3 -11
- package/dist/PlaywrightTester.js +2 -22
- package/dist/PlaywrightTester.js.map +1 -1
- package/package.json +4 -4
- package/src/PlaywrightTester.ts +3 -21
package/README.md
CHANGED
|
@@ -280,3 +280,14 @@ The `@requires` decorator group also contains `@requires.labCoat()` this decorat
|
|
|
280
280
|
|
|
281
281
|
To use these decorators, the generic `security` middleware must be loaded first. In most cases, it should be added to the `pre` list of handlers of a service.
|
|
282
282
|
The security middleware takes an optional configuration object, which is documented [in code](packages/easy-express/src/express/SecurityHandler.ts).
|
|
283
|
+
|
|
284
|
+
## Side effects and tree shaking
|
|
285
|
+
Every package declares `sideEffects` in its `package.json`, so a bundler only keeps the modules a consumer actually uses. Contributors keep that declaration true by following these rules:
|
|
286
|
+
|
|
287
|
+
- **No module-level mutation of anything outside the module.** Do not patch globals, prototypes or imported objects when a module loads. If something must be configured, configure it in the module that needs it, so it is kept exactly when that module is used.
|
|
288
|
+
- **Catalogue values are pure factories.** Build enum and catalogue values with plain constructors or factory calls that only create objects, so an unused value can be dropped.
|
|
289
|
+
- **A module that must run for its effect on import is listed explicitly.** `easy-test` lists its index and matcher files because `import '@thisisagile/easy-test'` exists to call `expect.extend`. `easy-test-react` lists its index because importing it mocks the timezone. Runtime packages declare `false`.
|
|
290
|
+
- **`DateTime` and `Meta` are deliberately not listed.** `DateTime` extends Day.js and `Meta` loads `reflect-metadata` at module level, but only their own exports need that setup. Bundlers keep a module's top-level code whenever any of its exports are used, so they stay correct unlisted. Listing them would make every root import, such as `isDefined`, pay for Day.js and `reflect-metadata`.
|
|
291
|
+
- **No `emitDecoratorMetadata`.** Nothing in easy reads `design:` metadata; decorators store what they need under their own keys.
|
|
292
|
+
|
|
293
|
+
`test/bundle/workspaces.mjs` checks these rules against the packed packages.
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Json } from "@thisisagile/easy";
|
|
2
2
|
import { Browser, Page } from "playwright";
|
|
3
|
-
import { TestElement, Tester } from "@thisisagile/easy-test-web";
|
|
3
|
+
import { ClosableBrowserTester, TestElement, Tester } from "@thisisagile/easy-test-web";
|
|
4
4
|
//#region src/PlaywrightTester.d.ts
|
|
5
5
|
export type BrowserType = 'Chromium' | 'Webkit' | 'Firefox';
|
|
6
|
-
export declare class PlaywrightTester implements Tester {
|
|
7
|
-
host: string;
|
|
8
|
-
private readonly browser;
|
|
9
|
-
private readonly page;
|
|
10
|
-
constructor(host: string, browser: Browser, page: Page);
|
|
6
|
+
export declare class PlaywrightTester extends ClosableBrowserTester<Page> implements Tester {
|
|
11
7
|
get url(): string;
|
|
12
8
|
static launch: (browserType: BrowserType, headless: boolean, launchProps: Json) => Promise<Browser>;
|
|
13
9
|
static init(browserType: BrowserType, host?: string, headless?: boolean, width?: number, height?: number, launchProps?: {}): Promise<Tester>;
|
|
@@ -18,10 +14,6 @@ export declare class PlaywrightTester implements Tester {
|
|
|
18
14
|
by(key: string, value: string): TestElement;
|
|
19
15
|
submit(): TestElement;
|
|
20
16
|
row(contains: string): TestElement;
|
|
21
|
-
redirect(url: string): Promise<boolean>;
|
|
22
|
-
goto(to: UseCase, id?: Id): Promise<boolean>;
|
|
23
|
-
wait(): Promise<boolean>;
|
|
24
|
-
close(): Promise<void>;
|
|
25
17
|
private byXPath;
|
|
26
18
|
}
|
|
27
19
|
//#endregion
|
package/dist/PlaywrightTester.js
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
import { PlaywrightElement } from "./PlaywrightElement.js";
|
|
2
2
|
import { ctx } from "@thisisagile/easy";
|
|
3
3
|
import { chromium, firefox, webkit } from "playwright";
|
|
4
|
-
import {
|
|
4
|
+
import { ClosableBrowserTester } from "@thisisagile/easy-test-web";
|
|
5
5
|
//#region src/PlaywrightTester.ts
|
|
6
|
-
var PlaywrightTester = class PlaywrightTester {
|
|
7
|
-
host;
|
|
8
|
-
browser;
|
|
9
|
-
page;
|
|
10
|
-
constructor(host, browser, page) {
|
|
11
|
-
this.host = host;
|
|
12
|
-
this.browser = browser;
|
|
13
|
-
this.page = page;
|
|
14
|
-
}
|
|
6
|
+
var PlaywrightTester = class PlaywrightTester extends ClosableBrowserTester {
|
|
15
7
|
get url() {
|
|
16
8
|
return this.page.url();
|
|
17
9
|
}
|
|
@@ -62,18 +54,6 @@ var PlaywrightTester = class PlaywrightTester {
|
|
|
62
54
|
row(contains) {
|
|
63
55
|
return this.byXPath(`(//tr[contains(., '${contains}')])[1]`);
|
|
64
56
|
}
|
|
65
|
-
redirect(url) {
|
|
66
|
-
return this.page.goto(url).then((r) => r?.ok() ?? false);
|
|
67
|
-
}
|
|
68
|
-
goto(to, id) {
|
|
69
|
-
return this.redirect(toUrl(to, this.host, id));
|
|
70
|
-
}
|
|
71
|
-
wait() {
|
|
72
|
-
return this.page.waitForNavigation().then((r) => r?.ok() || false);
|
|
73
|
-
}
|
|
74
|
-
close() {
|
|
75
|
-
return this.browser.close();
|
|
76
|
-
}
|
|
77
57
|
byXPath(q) {
|
|
78
58
|
const h = this.page.waitForSelector(`${q}`);
|
|
79
59
|
return new PlaywrightElement(h);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlaywrightTester.js","names":[],"sources":["../src/PlaywrightTester.ts"],"sourcesContent":["import playwright, { Browser, chromium, firefox, Page, webkit } from 'playwright';\nimport { PlaywrightElement } from './PlaywrightElement';\nimport { ctx,
|
|
1
|
+
{"version":3,"file":"PlaywrightTester.js","names":[],"sources":["../src/PlaywrightTester.ts"],"sourcesContent":["import playwright, { Browser, chromium, firefox, Page, webkit } from 'playwright';\nimport { PlaywrightElement } from './PlaywrightElement';\nimport { ctx, Json } from '@thisisagile/easy';\nimport { ClosableBrowserTester, TestElement, Tester } from '@thisisagile/easy-test-web';\n\nexport type BrowserType = 'Chromium' | 'Webkit' | 'Firefox';\n\nexport class PlaywrightTester extends ClosableBrowserTester<Page> implements Tester {\n get url(): string {\n return this.page.url();\n }\n\n /* istanbul ignore next */\n static launch = (browserType: BrowserType, headless: boolean, launchProps: Json): Promise<Browser> => {\n const options: playwright.LaunchOptions = {\n headless: headless,\n args: ['--no-sandbox', '--start-maximized'],\n ...launchProps,\n };\n switch (browserType) {\n case 'Firefox':\n return firefox.launch(options);\n case 'Webkit':\n return webkit.launch(options);\n default:\n return chromium.launch(options);\n }\n };\n\n /* istanbul ignore next */\n static async init(\n browserType: BrowserType,\n host: string = ctx.env.get('webHost', '') as string,\n headless = true,\n width = 1200,\n height = 800,\n launchProps = {}\n ): Promise<Tester> {\n const browser = await PlaywrightTester.launch(browserType, headless, launchProps);\n const page = await browser.newPage();\n await page.setViewportSize({ width, height });\n return new PlaywrightTester(host, browser, page);\n }\n\n byClass(c: string): TestElement {\n const h = this.page.waitForSelector(`.${c}`);\n return new PlaywrightElement(h);\n }\n\n byId(id: string): TestElement {\n const h = this.page.waitForSelector(`#${id}`);\n return new PlaywrightElement(h);\n }\n\n byDataTestId(id: string): TestElement {\n return this.by('data-testid', id);\n }\n\n byName(name: string): TestElement {\n return this.by('name', name);\n }\n\n by(key: string, value: string): TestElement {\n const h = this.page.waitForSelector(`[${key}=${value}]`);\n return new PlaywrightElement(h);\n }\n\n submit(): TestElement {\n return this.by('type', 'submit');\n }\n\n row(contains: string): TestElement {\n // Select the first row that contains the given input\n return this.byXPath(`(//tr[contains(., '${contains}')])[1]`);\n }\n\n private byXPath(q: string): TestElement {\n const h = this.page.waitForSelector(`${q}`);\n return new PlaywrightElement(h);\n }\n}\n"],"mappings":";;;;;AAOA,IAAa,mBAAb,MAAa,yBAAyB,sBAA8C;CAClF,IAAI,MAAc;EAChB,OAAO,KAAK,KAAK,IAAI;CACvB;;CAGA,OAAO,UAAU,aAA0B,UAAmB,gBAAwC;EACpG,MAAM,UAAoC;GAC9B;GACV,MAAM,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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisisagile/easy-playwright",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "21.0.0",
|
|
4
4
|
"description": "Straightforward wrapper library for Playwright web testing framework",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"scripts": {
|
|
25
25
|
"lint": "yarn g:eslint . --ext .js,.jsx,.ts,.tsx --fix",
|
|
26
26
|
"format": "yarn g:prettier --check --write src test *.json",
|
|
27
|
-
"build": "yarn g:tsdown
|
|
27
|
+
"build": "yarn g:tsdown",
|
|
28
28
|
"test": "yarn g:jest --coverage",
|
|
29
29
|
"prepack": "yarn g:copy-readme"
|
|
30
30
|
},
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"@thisisagile/easy-test": "*"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@thisisagile/easy": "^
|
|
47
|
-
"@thisisagile/easy-test-web": "^
|
|
46
|
+
"@thisisagile/easy": "^21.0.0",
|
|
47
|
+
"@thisisagile/easy-test-web": "^21.0.0",
|
|
48
48
|
"playwright": "^1.41.2"
|
|
49
49
|
},
|
|
50
50
|
"exports": {
|
package/src/PlaywrightTester.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import playwright, { Browser, chromium, firefox, Page, webkit } from 'playwright';
|
|
2
2
|
import { PlaywrightElement } from './PlaywrightElement';
|
|
3
|
-
import { ctx,
|
|
4
|
-
import { TestElement, Tester
|
|
3
|
+
import { ctx, Json } from '@thisisagile/easy';
|
|
4
|
+
import { ClosableBrowserTester, TestElement, Tester } from '@thisisagile/easy-test-web';
|
|
5
5
|
|
|
6
6
|
export type BrowserType = 'Chromium' | 'Webkit' | 'Firefox';
|
|
7
7
|
|
|
8
|
-
export class PlaywrightTester implements Tester {
|
|
9
|
-
constructor(public host: string, private readonly browser: Browser, private readonly page: Page) {}
|
|
10
|
-
|
|
8
|
+
export class PlaywrightTester extends ClosableBrowserTester<Page> implements Tester {
|
|
11
9
|
get url(): string {
|
|
12
10
|
return this.page.url();
|
|
13
11
|
}
|
|
@@ -76,22 +74,6 @@ export class PlaywrightTester implements Tester {
|
|
|
76
74
|
return this.byXPath(`(//tr[contains(., '${contains}')])[1]`);
|
|
77
75
|
}
|
|
78
76
|
|
|
79
|
-
redirect(url: string): Promise<boolean> {
|
|
80
|
-
return this.page.goto(url).then(r => r?.ok() ?? false);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
goto(to: UseCase, id?: Id): Promise<boolean> {
|
|
84
|
-
return this.redirect(toUrl(to, this.host, id));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
wait(): Promise<boolean> {
|
|
88
|
-
return this.page.waitForNavigation().then(r => r?.ok() || false);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
close(): Promise<void> {
|
|
92
|
-
return this.browser.close();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
77
|
private byXPath(q: string): TestElement {
|
|
96
78
|
const h = this.page.waitForSelector(`${q}`);
|
|
97
79
|
return new PlaywrightElement(h);
|