@augment-vir/test 31.50.0 → 31.50.2
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/dist/augments/test-playwright.d.ts +24 -10
- package/dist/augments/test-playwright.js +24 -10
- package/dist/augments/universal-testing-suite/it-cases-with-context.d.ts +1 -1
- package/dist/augments/universal-testing-suite/universal-it.d.ts +1 -1
- package/dist/augments/universal-testing-suite/universal-it.js +5 -0
- package/dist/augments/universal-testing-suite/universal-snapshot.d.ts +1 -1
- package/dist/augments/universal-testing-suite/universal-test-context.d.ts +10 -3
- package/dist/augments/universal-testing-suite/universal-test-context.js +7 -0
- package/dist/test-playwright/enter-text.d.ts +2 -2
- package/dist/test-playwright/enter-text.js +5 -3
- package/dist/test-playwright/get-option.d.ts +2 -1
- package/dist/test-playwright/get-option.js +4 -2
- package/dist/test-playwright/local-storage.d.ts +2 -2
- package/dist/test-playwright/local-storage.js +4 -2
- package/dist/test-playwright/nav.d.ts +15 -10
- package/dist/test-playwright/nav.js +23 -13
- package/dist/test-playwright/new-page-or-download.d.ts +2 -1
- package/dist/test-playwright/new-page-or-download.js +6 -4
- package/dist/test-playwright/screenshot.d.ts +29 -8
- package/dist/test-playwright/screenshot.js +43 -12
- package/package.json +3 -3
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import { RuntimeEnvError } from '@augment-vir/core';
|
|
2
2
|
export { type MenuOptionOptions } from '../test-playwright/get-option.js';
|
|
3
|
-
export { playwrightTeatNameUrlParam, type
|
|
4
|
-
export { type LocatorScreenshotOptions } from '../test-playwright/screenshot.js';
|
|
3
|
+
export { playwrightTeatNameUrlParam, type NavOptions } from '../test-playwright/nav.js';
|
|
4
|
+
export { type LocatorScreenshotOptions, type SaveScreenshotOptions, type TakeScreenshotOptions, } from '../test-playwright/screenshot.js';
|
|
5
5
|
declare function importPlaywrightTestApi(this: void): Promise<RuntimeEnvError | {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
navigation: {
|
|
7
|
+
/** Navigate to a URL in Playwright via given paths. */
|
|
8
|
+
navigateTo: typeof import("../test-playwright/nav.js").navigateTo;
|
|
9
|
+
extractNavUrl: typeof import("../test-playwright/nav.js").extractNavUrl;
|
|
10
|
+
};
|
|
8
11
|
/**
|
|
9
12
|
* Expects that all matches for the given locator are either visible or hidden (controlled
|
|
10
13
|
* by `isVisible`).
|
|
11
14
|
*/
|
|
12
15
|
expectAllVisible: typeof import("../test-playwright/all-visible.js").expectAllVisible;
|
|
13
|
-
/**
|
|
14
|
-
* Similar to Playwright's `expect().toHaveScreenshot` but allows images to have different
|
|
15
|
-
* sizes and has default comparison threshold options that are wide enough to allow testing
|
|
16
|
-
* between different operating systems without failure (usually).
|
|
17
|
-
*/
|
|
18
|
-
expectScreenshot: typeof import("../test-playwright/screenshot.js").expectScreenshot;
|
|
19
16
|
/** Clicks a label to select its input and then types the given text. */
|
|
20
17
|
enterTextByLabel: typeof import("../test-playwright/enter-text").enterTextByLabel;
|
|
21
18
|
/** Find the matching (or first) element with the "option" role. */
|
|
@@ -29,6 +26,23 @@ declare function importPlaywrightTestApi(this: void): Promise<RuntimeEnvError |
|
|
|
29
26
|
handleNewPageOrDownload: typeof import("../test-playwright/new-page-or-download").handleNewPageOrDownload;
|
|
30
27
|
/** Read from a page's local storage (using `page.evaluate`). */
|
|
31
28
|
readLocalStorage: typeof import("../test-playwright/local-storage.js").readLocalStorage;
|
|
29
|
+
/** Screenshot methods. */
|
|
30
|
+
screenshot: {
|
|
31
|
+
/**
|
|
32
|
+
* Similar to Playwright's `expect().toHaveScreenshot` but allows images to have
|
|
33
|
+
* different sizes and has default comparison threshold options that are wide enough to
|
|
34
|
+
* allow testing between different operating systems without failure (usually).
|
|
35
|
+
*/
|
|
36
|
+
expectScreenshot: typeof import("../test-playwright/screenshot.js").expectScreenshot;
|
|
37
|
+
/** Get the path to save the given screenshot file name to. */
|
|
38
|
+
getScreenshotPath: typeof import("../test-playwright/screenshot.js").getScreenshotPath;
|
|
39
|
+
/**
|
|
40
|
+
* Take and immediately save a screenshot.
|
|
41
|
+
*
|
|
42
|
+
* @returns The path that the screenshot was saved to.
|
|
43
|
+
*/
|
|
44
|
+
takeScreenshot: typeof import("../test-playwright/screenshot.js").takeScreenshot;
|
|
45
|
+
};
|
|
32
46
|
}>;
|
|
33
47
|
/**
|
|
34
48
|
* A suite of Playwright test helpers. This is only accessible within a Playwright test runtime. If
|
|
@@ -7,25 +7,22 @@ async function importPlaywrightTestApi() {
|
|
|
7
7
|
const { checkHasClass } = await import('../test-playwright/has-class');
|
|
8
8
|
const { enterTextByLabel } = await import('../test-playwright/enter-text');
|
|
9
9
|
const { expectAllVisible } = await import('../test-playwright/all-visible.js');
|
|
10
|
-
const { expectScreenshot } = await import('../test-playwright/screenshot.js');
|
|
11
10
|
const { getMenuOption } = await import('../test-playwright/get-option');
|
|
11
|
+
const { getScreenshotPath, takeScreenshot, expectScreenshot } = await import('../test-playwright/screenshot.js');
|
|
12
12
|
const { handleNewPageOrDownload } = await import('../test-playwright/new-page-or-download');
|
|
13
|
-
const {
|
|
13
|
+
const { navigateTo, extractNavUrl } = await import('../test-playwright/nav.js');
|
|
14
14
|
const { readLocalStorage } = await import('../test-playwright/local-storage.js');
|
|
15
15
|
return {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
navigation: {
|
|
17
|
+
/** Navigate to a URL in Playwright via given paths. */
|
|
18
|
+
navigateTo,
|
|
19
|
+
extractNavUrl,
|
|
20
|
+
},
|
|
18
21
|
/**
|
|
19
22
|
* Expects that all matches for the given locator are either visible or hidden (controlled
|
|
20
23
|
* by `isVisible`).
|
|
21
24
|
*/
|
|
22
25
|
expectAllVisible,
|
|
23
|
-
/**
|
|
24
|
-
* Similar to Playwright's `expect().toHaveScreenshot` but allows images to have different
|
|
25
|
-
* sizes and has default comparison threshold options that are wide enough to allow testing
|
|
26
|
-
* between different operating systems without failure (usually).
|
|
27
|
-
*/
|
|
28
|
-
expectScreenshot,
|
|
29
26
|
/** Clicks a label to select its input and then types the given text. */
|
|
30
27
|
enterTextByLabel,
|
|
31
28
|
/** Find the matching (or first) element with the "option" role. */
|
|
@@ -39,6 +36,23 @@ async function importPlaywrightTestApi() {
|
|
|
39
36
|
handleNewPageOrDownload,
|
|
40
37
|
/** Read from a page's local storage (using `page.evaluate`). */
|
|
41
38
|
readLocalStorage,
|
|
39
|
+
/** Screenshot methods. */
|
|
40
|
+
screenshot: {
|
|
41
|
+
/**
|
|
42
|
+
* Similar to Playwright's `expect().toHaveScreenshot` but allows images to have
|
|
43
|
+
* different sizes and has default comparison threshold options that are wide enough to
|
|
44
|
+
* allow testing between different operating systems without failure (usually).
|
|
45
|
+
*/
|
|
46
|
+
expectScreenshot,
|
|
47
|
+
/** Get the path to save the given screenshot file name to. */
|
|
48
|
+
getScreenshotPath,
|
|
49
|
+
/**
|
|
50
|
+
* Take and immediately save a screenshot.
|
|
51
|
+
*
|
|
52
|
+
* @returns The path that the screenshot was saved to.
|
|
53
|
+
*/
|
|
54
|
+
takeScreenshot,
|
|
55
|
+
},
|
|
42
56
|
};
|
|
43
57
|
}
|
|
44
58
|
/**
|
|
@@ -9,7 +9,7 @@ import { type UniversalTestContext } from './universal-test-context.js';
|
|
|
9
9
|
* @category Package : @augment-vir/test
|
|
10
10
|
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
11
11
|
*/
|
|
12
|
-
export type BaseFunctionWithContext = (testContext: UniversalTestContext
|
|
12
|
+
export type BaseFunctionWithContext = (testContext: Readonly<UniversalTestContext>, ...args: any[]) => any;
|
|
13
13
|
/**
|
|
14
14
|
* Input for a test function with context that only has a single input.
|
|
15
15
|
*
|
|
@@ -10,7 +10,7 @@ import { type UniversalTestContext } from './universal-test-context.js';
|
|
|
10
10
|
* @category Package : @augment-vir/test
|
|
11
11
|
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
12
12
|
*/
|
|
13
|
-
export type UniversalItCallback = (this: void, context: UniversalTestContext) => Promise<void> | void;
|
|
13
|
+
export type UniversalItCallback = (this: void, context: Readonly<UniversalTestContext>) => Promise<void> | void;
|
|
14
14
|
/**
|
|
15
15
|
* A minimal interface for {@link it}. This is used in {@link UniversalIt}.
|
|
16
16
|
*
|
|
@@ -27,6 +27,11 @@ async function createPlaywrightIt() {
|
|
|
27
27
|
const originalPlaywrightIt = 'default' in rawPlaywrightImport
|
|
28
28
|
? rawPlaywrightImport.default
|
|
29
29
|
: rawPlaywrightImport;
|
|
30
|
+
/**
|
|
31
|
+
* Right now this wrapper nukes Playwright's file detection. See
|
|
32
|
+
* https://github.com/microsoft/playwright/issues/23157#issuecomment-1574955057 for possible
|
|
33
|
+
* help.
|
|
34
|
+
*/
|
|
30
35
|
const playwrightIt = Object.assign((doesThis, callback) => {
|
|
31
36
|
return originalPlaywrightIt(doesThis, async ({ page, baseURL, browser, context, extraHTTPHeaders, viewport, video, userAgent, timezoneId, serviceWorkers, screenshot, isMobile, headless, hasTouch, }, testInfo) => {
|
|
32
37
|
const playwrightTestContext = {
|
|
@@ -22,4 +22,4 @@ export declare class SnapshotFileMissingError extends Error {
|
|
|
22
22
|
* @category Package : @augment-vir/test
|
|
23
23
|
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
24
24
|
*/
|
|
25
|
-
export declare function assertSnapshot(this: void, testContext: UniversalTestContext
|
|
25
|
+
export declare function assertSnapshot(this: void, testContext: Readonly<UniversalTestContext>, data: unknown): Promise<void>;
|
|
@@ -58,6 +58,13 @@ export type PlaywrightTestContext = SelectFrom<PlaywrightTestArgs & PlaywrightTe
|
|
|
58
58
|
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
59
59
|
*/
|
|
60
60
|
export type UniversalTestContext = NodeTestContext | MochaTestContext | PlaywrightTestContext;
|
|
61
|
+
/**
|
|
62
|
+
* Used to determine which test context is in use.
|
|
63
|
+
*
|
|
64
|
+
* @category Test : Util
|
|
65
|
+
* @category Package : @augment-vir/test
|
|
66
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
67
|
+
*/
|
|
61
68
|
export declare enum TestEnv {
|
|
62
69
|
Node = "node",
|
|
63
70
|
Web = "web",
|
|
@@ -109,7 +116,7 @@ export declare function cleanTestNameAsDir(testName: string): string;
|
|
|
109
116
|
* @throws `TypeError` if the context does not match the env.
|
|
110
117
|
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
111
118
|
*/
|
|
112
|
-
export declare function assertWrapTestContext<const SpecificEnv extends TestEnv>(this: void, context: UniversalTestContext
|
|
119
|
+
export declare function assertWrapTestContext<const SpecificEnv extends TestEnv>(this: void, context: Readonly<UniversalTestContext>, env: SpecificEnv): TestContextByEnv[SpecificEnv];
|
|
113
120
|
/**
|
|
114
121
|
* Asserts that the given context is for the given env, otherwise throws an Error.
|
|
115
122
|
*
|
|
@@ -117,7 +124,7 @@ export declare function assertWrapTestContext<const SpecificEnv extends TestEnv>
|
|
|
117
124
|
* @category Package : @augment-vir/test
|
|
118
125
|
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
119
126
|
*/
|
|
120
|
-
export declare function assertTestContext<const SpecificEnv extends TestEnv>(this: void, context: UniversalTestContext
|
|
127
|
+
export declare function assertTestContext<const SpecificEnv extends TestEnv>(this: void, context: Readonly<UniversalTestContext>, env: SpecificEnv): asserts context is TestContextByEnv[SpecificEnv];
|
|
121
128
|
/**
|
|
122
129
|
* Checks that the given context is for the given env.
|
|
123
130
|
*
|
|
@@ -125,7 +132,7 @@ export declare function assertTestContext<const SpecificEnv extends TestEnv>(thi
|
|
|
125
132
|
* @category Package : @augment-vir/test
|
|
126
133
|
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
127
134
|
*/
|
|
128
|
-
export declare function isTestContext<const SpecificEnv extends TestEnv>(this: void, context: UniversalTestContext
|
|
135
|
+
export declare function isTestContext<const SpecificEnv extends TestEnv>(this: void, context: Readonly<UniversalTestContext>, env: SpecificEnv): context is TestContextByEnv[SpecificEnv];
|
|
129
136
|
/**
|
|
130
137
|
* Determine the env for the given test context.
|
|
131
138
|
*
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { assertWrap } from '@augment-vir/assert';
|
|
2
2
|
import { camelCaseToKebabCase, sanitizeFilePath } from '@augment-vir/common';
|
|
3
|
+
/**
|
|
4
|
+
* Used to determine which test context is in use.
|
|
5
|
+
*
|
|
6
|
+
* @category Test : Util
|
|
7
|
+
* @category Package : @augment-vir/test
|
|
8
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
9
|
+
*/
|
|
3
10
|
export var TestEnv;
|
|
4
11
|
(function (TestEnv) {
|
|
5
12
|
TestEnv["Node"] = "node";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type UniversalTestContext } from '../augments/universal-testing-suite/universal-test-context.js';
|
|
2
2
|
/**
|
|
3
3
|
* Clicks a label to select its input and then types the given text.
|
|
4
4
|
*
|
|
5
5
|
* @category Internal
|
|
6
6
|
*/
|
|
7
|
-
export declare function enterTextByLabel(
|
|
7
|
+
export declare function enterTextByLabel(testContext: Readonly<UniversalTestContext>, { label, text }: {
|
|
8
8
|
label: string;
|
|
9
9
|
text: string;
|
|
10
10
|
}): Promise<void>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { assertTestContext, TestEnv, } from '../augments/universal-testing-suite/universal-test-context.js';
|
|
1
2
|
/**
|
|
2
3
|
* Clicks a label to select its input and then types the given text.
|
|
3
4
|
*
|
|
4
5
|
* @category Internal
|
|
5
6
|
*/
|
|
6
|
-
export async function enterTextByLabel(
|
|
7
|
-
|
|
8
|
-
await page.
|
|
7
|
+
export async function enterTextByLabel(testContext, { label, text }) {
|
|
8
|
+
assertTestContext(testContext, TestEnv.Playwright);
|
|
9
|
+
await testContext.page.getByLabel(label).first().click();
|
|
10
|
+
await testContext.page.keyboard.type(text);
|
|
9
11
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Page } from '@playwright/test';
|
|
2
|
+
import { type UniversalTestContext } from '../augments/universal-testing-suite/universal-test-context.js';
|
|
2
3
|
/**
|
|
3
4
|
* Options for `testPlaywright.getMenuOption`.
|
|
4
5
|
*
|
|
@@ -12,4 +13,4 @@ export type MenuOptionOptions = Parameters<Page['getByRole']>[1] & Partial<{
|
|
|
12
13
|
*
|
|
13
14
|
* @category Internal
|
|
14
15
|
*/
|
|
15
|
-
export declare function getMenuOption(
|
|
16
|
+
export declare function getMenuOption(testContext: Readonly<UniversalTestContext>, options?: MenuOptionOptions | undefined): import("playwright-core").Locator;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { assertTestContext, TestEnv, } from '../augments/universal-testing-suite/universal-test-context.js';
|
|
1
2
|
/**
|
|
2
3
|
* Find the matching (or first) "option" element.
|
|
3
4
|
*
|
|
4
5
|
* @category Internal
|
|
5
6
|
*/
|
|
6
|
-
export function getMenuOption(
|
|
7
|
-
|
|
7
|
+
export function getMenuOption(testContext, options) {
|
|
8
|
+
assertTestContext(testContext, TestEnv.Playwright);
|
|
9
|
+
const baseLocator = testContext.page.getByRole('option', options);
|
|
8
10
|
if (options && 'nth' in options) {
|
|
9
11
|
return baseLocator.nth(options.nth);
|
|
10
12
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type UniversalTestContext } from '../augments/universal-testing-suite/universal-test-context.js';
|
|
2
2
|
/**
|
|
3
3
|
* Read from a page's local storage.
|
|
4
4
|
*
|
|
5
5
|
* @category Internal
|
|
6
6
|
*/
|
|
7
|
-
export declare function readLocalStorage(
|
|
7
|
+
export declare function readLocalStorage(testContext: Readonly<UniversalTestContext>, storageKey: string): Promise<string | undefined>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { assertTestContext, TestEnv, } from '../augments/universal-testing-suite/universal-test-context.js';
|
|
1
2
|
/**
|
|
2
3
|
* Read from a page's local storage.
|
|
3
4
|
*
|
|
4
5
|
* @category Internal
|
|
5
6
|
*/
|
|
6
|
-
export async function readLocalStorage(
|
|
7
|
-
|
|
7
|
+
export async function readLocalStorage(testContext, storageKey) {
|
|
8
|
+
assertTestContext(testContext, TestEnv.Playwright);
|
|
9
|
+
return ((await testContext.page.evaluate((keyToRead) => {
|
|
8
10
|
return localStorage.getItem(keyToRead);
|
|
9
11
|
}, storageKey)) || undefined);
|
|
10
12
|
}
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { type GenericTreePaths } from 'spa-router-vir';
|
|
2
|
+
import { type UrlOverrides } from 'url-vir';
|
|
2
3
|
import { type UniversalTestContext } from '../augments/universal-testing-suite/universal-test-context.js';
|
|
4
|
+
/**
|
|
5
|
+
* Converts {@link NavOptions} into an actionable URL string.
|
|
6
|
+
*
|
|
7
|
+
* @category Internal
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractNavUrl(testContext: Readonly<UniversalTestContext>, options: Readonly<NavOptions>): string;
|
|
3
10
|
/**
|
|
4
11
|
* Used for the `path` argument of `testPlaywright.nav`.
|
|
5
12
|
*
|
|
6
13
|
* @category Internal
|
|
7
14
|
*/
|
|
8
|
-
export type
|
|
9
|
-
/**
|
|
10
|
-
|
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
export type NavOptions = Omit<UrlOverrides, 'paths'> & {
|
|
16
|
+
/** If not provided, the page's current URL will be used. */
|
|
17
|
+
baseFrontendUrl?: string | undefined;
|
|
18
|
+
paths?: string[]
|
|
19
|
+
/** Prefer using tree paths with `frontendPathTree` */
|
|
20
|
+
| GenericTreePaths;
|
|
21
|
+
};
|
|
13
22
|
/**
|
|
14
23
|
* The test name appended to the frontend when `testPlaywright.nav` is used.
|
|
15
24
|
*
|
|
@@ -21,8 +30,4 @@ export declare const playwrightTeatNameUrlParam = "test-name";
|
|
|
21
30
|
*
|
|
22
31
|
* @category Internal
|
|
23
32
|
*/
|
|
24
|
-
export declare function
|
|
25
|
-
path: NavPath;
|
|
26
|
-
/** If not provided, the page's current URL will be used. */
|
|
27
|
-
baseFrontendUrl?: string | undefined;
|
|
28
|
-
}): Promise<void>;
|
|
33
|
+
export declare function navigateTo(testContext: Readonly<UniversalTestContext>, options: Readonly<NavOptions>): Promise<void>;
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { omitObjectKeys } from '@augment-vir/common';
|
|
2
3
|
import { buildUrl } from 'url-vir';
|
|
3
|
-
import { assertTestContext, extractTestNameAsDir, TestEnv, } from '../augments/universal-testing-suite/universal-test-context.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
import { assertTestContext, assertWrapTestContext, extractTestNameAsDir, TestEnv, } from '../augments/universal-testing-suite/universal-test-context.js';
|
|
5
|
+
/**
|
|
6
|
+
* Converts {@link NavOptions} into an actionable URL string.
|
|
7
|
+
*
|
|
8
|
+
* @category Internal
|
|
9
|
+
*/
|
|
10
|
+
export function extractNavUrl(testContext, options) {
|
|
11
|
+
return buildUrl(options.baseFrontendUrl ||
|
|
12
|
+
assertWrapTestContext(testContext, TestEnv.Playwright).page.url(), {
|
|
13
|
+
...omitObjectKeys(options, ['paths']),
|
|
14
|
+
...(options.paths
|
|
15
|
+
? check.isArray(options.paths)
|
|
16
|
+
? {
|
|
17
|
+
paths: options.paths,
|
|
18
|
+
}
|
|
19
|
+
: {
|
|
20
|
+
paths: options.paths.fullPaths,
|
|
21
|
+
}
|
|
22
|
+
: {}),
|
|
23
|
+
}).href;
|
|
14
24
|
}
|
|
15
25
|
/**
|
|
16
26
|
* The test name appended to the frontend when `testPlaywright.nav` is used.
|
|
@@ -23,11 +33,11 @@ export const playwrightTeatNameUrlParam = 'test-name';
|
|
|
23
33
|
*
|
|
24
34
|
* @category Internal
|
|
25
35
|
*/
|
|
26
|
-
export async function
|
|
36
|
+
export async function navigateTo(testContext, options) {
|
|
27
37
|
assertTestContext(testContext, TestEnv.Playwright);
|
|
28
38
|
const page = testContext.page;
|
|
29
39
|
const testName = extractTestNameAsDir(testContext);
|
|
30
|
-
const finalPath = buildUrl(extractNavUrl(
|
|
40
|
+
const finalPath = buildUrl(extractNavUrl(testContext, options), {
|
|
31
41
|
search: {
|
|
32
42
|
[playwrightTeatNameUrlParam]: [testName],
|
|
33
43
|
},
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { type MaybePromise } from '@augment-vir/common';
|
|
2
2
|
import { type Download, type Page } from '@playwright/test';
|
|
3
3
|
import { type RequireExactlyOne } from 'type-fest';
|
|
4
|
+
import { type UniversalTestContext } from '../augments/universal-testing-suite/universal-test-context.js';
|
|
4
5
|
/**
|
|
5
6
|
* Run the trigger and catch a new page _or_ a new download (sometimes Playwright inconsistently
|
|
6
7
|
* chooses on or the other).
|
|
7
8
|
*
|
|
8
9
|
* @category Internal
|
|
9
10
|
*/
|
|
10
|
-
export declare function handleNewPageOrDownload(
|
|
11
|
+
export declare function handleNewPageOrDownload(testContext: Readonly<UniversalTestContext>, trigger: () => MaybePromise<void>): Promise<RequireExactlyOne<{
|
|
11
12
|
newPage: Page;
|
|
12
13
|
download: Download;
|
|
13
14
|
}>>;
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
+
import { assertTestContext, TestEnv, } from '../augments/universal-testing-suite/universal-test-context.js';
|
|
1
2
|
/**
|
|
2
3
|
* Run the trigger and catch a new page _or_ a new download (sometimes Playwright inconsistently
|
|
3
4
|
* chooses on or the other).
|
|
4
5
|
*
|
|
5
6
|
* @category Internal
|
|
6
7
|
*/
|
|
7
|
-
export async function handleNewPageOrDownload(
|
|
8
|
+
export async function handleNewPageOrDownload(testContext, trigger) {
|
|
9
|
+
assertTestContext(testContext, TestEnv.Playwright);
|
|
8
10
|
const openOrDownload = Promise.race([
|
|
9
|
-
page
|
|
11
|
+
testContext.page
|
|
10
12
|
.context()
|
|
11
13
|
.waitForEvent('page', async (newPage) => {
|
|
12
|
-
return (await newPage.opener()) === page;
|
|
14
|
+
return (await newPage.opener()) === testContext.page;
|
|
13
15
|
})
|
|
14
16
|
.then((result) => {
|
|
15
17
|
return { page: result };
|
|
16
18
|
}),
|
|
17
|
-
page.waitForEvent('download').then((result) => {
|
|
19
|
+
testContext.page.waitForEvent('download').then((result) => {
|
|
18
20
|
return { download: result };
|
|
19
21
|
}),
|
|
20
22
|
]);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type PartialWithUndefined } from '@augment-vir/common';
|
|
2
|
+
import { type Locator } from '@playwright/test';
|
|
3
|
+
import { type UniversalTestContext } from '../augments/universal-testing-suite/universal-test-context.js';
|
|
2
4
|
/** This is used for type extraction because Playwright does not export the types we need. */
|
|
3
5
|
declare function extractScreenshotMethod(): {
|
|
4
6
|
(name: string | ReadonlyArray<string>, options?: {
|
|
@@ -49,6 +51,31 @@ export declare const defaultScreenshotOptions: {
|
|
|
49
51
|
threshold: number;
|
|
50
52
|
maxDiffPixelRatio: number;
|
|
51
53
|
};
|
|
54
|
+
export type TakeScreenshotOptions = PartialWithUndefined<{
|
|
55
|
+
/** If no locator is provided then the whole page is use. */
|
|
56
|
+
locator: Readonly<Locator>;
|
|
57
|
+
}> & Partial<LocatorScreenshotOptions>;
|
|
58
|
+
/**
|
|
59
|
+
* Get the path to save the given screenshot file name to.
|
|
60
|
+
*
|
|
61
|
+
* @category Internal
|
|
62
|
+
*/
|
|
63
|
+
export declare function getScreenshotPath(testContext: Readonly<UniversalTestContext>, screenshotBaseName: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Options for taking _and_ saving a screenshot.
|
|
66
|
+
*
|
|
67
|
+
* @category Internal
|
|
68
|
+
*/
|
|
69
|
+
export type SaveScreenshotOptions = TakeScreenshotOptions & {
|
|
70
|
+
screenshotBaseName: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Take and immediately save a screenshot.
|
|
74
|
+
*
|
|
75
|
+
* @category Internal
|
|
76
|
+
* @returns The path that the screenshot was saved to.
|
|
77
|
+
*/
|
|
78
|
+
export declare function takeScreenshot(testContext: Readonly<UniversalTestContext>, options: Readonly<SaveScreenshotOptions>): Promise<string>;
|
|
52
79
|
/**
|
|
53
80
|
* Similar to Playwright's `expect().toHaveScreenshot` but allows images to have different sizes and
|
|
54
81
|
* has default comparison threshold options that are wide enough to allow testing between different
|
|
@@ -56,11 +83,5 @@ export declare const defaultScreenshotOptions: {
|
|
|
56
83
|
*
|
|
57
84
|
* @category Internal
|
|
58
85
|
*/
|
|
59
|
-
export declare function expectScreenshot(
|
|
60
|
-
testInfo: Readonly<TestInfo>;
|
|
61
|
-
/** If no locator is provided, a screenshot of the whole page will be taken. */
|
|
62
|
-
locator: Readonly<Locator> | undefined;
|
|
63
|
-
screenshotName: string;
|
|
64
|
-
options?: Partial<LocatorScreenshotOptions> | undefined;
|
|
65
|
-
}): Promise<void>;
|
|
86
|
+
export declare function expectScreenshot(testContext: Readonly<UniversalTestContext>, options: Readonly<SaveScreenshotOptions>): Promise<void>;
|
|
66
87
|
export {};
|
|
@@ -8,6 +8,7 @@ import { relative } from 'node:path';
|
|
|
8
8
|
import pixelmatch from 'pixelmatch';
|
|
9
9
|
import { PNG } from 'pngjs';
|
|
10
10
|
import sharp from 'sharp';
|
|
11
|
+
import { assertTestContext, assertWrapTestContext, TestEnv, } from '../augments/universal-testing-suite/universal-test-context.js';
|
|
11
12
|
/** This is used for type extraction because Playwright does not export the types we need. */
|
|
12
13
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
13
14
|
function extractScreenshotMethod() {
|
|
@@ -62,18 +63,48 @@ async function padToSameCanvas(aBuf, bBuf) {
|
|
|
62
63
|
dimensions,
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
|
-
async function
|
|
66
|
-
if (locator) {
|
|
66
|
+
async function takeScreenshotBuffer(testContext, options = {}) {
|
|
67
|
+
if (options.locator) {
|
|
67
68
|
/** The locator expectation has different options than the page expectation. */
|
|
68
|
-
return await locator.screenshot({
|
|
69
|
+
return await options.locator.screenshot({
|
|
70
|
+
...defaultScreenshotOptions,
|
|
71
|
+
...options,
|
|
72
|
+
});
|
|
69
73
|
}
|
|
70
74
|
else {
|
|
71
|
-
|
|
75
|
+
assertTestContext(testContext, TestEnv.Playwright);
|
|
76
|
+
return await testContext.page.screenshot({
|
|
72
77
|
...defaultScreenshotOptions,
|
|
73
78
|
...options,
|
|
74
79
|
});
|
|
75
80
|
}
|
|
76
81
|
}
|
|
82
|
+
/** @returns The path that the screenshot was saved to. */
|
|
83
|
+
async function saveScreenshotBuffer(testContext, screenshotBuffer, screenshotBaseName) {
|
|
84
|
+
assertTestContext(testContext, TestEnv.Playwright);
|
|
85
|
+
const screenshotPath = getScreenshotPath(testContext, screenshotBaseName);
|
|
86
|
+
await writeFileAndDir(screenshotPath, screenshotBuffer);
|
|
87
|
+
return screenshotPath;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get the path to save the given screenshot file name to.
|
|
91
|
+
*
|
|
92
|
+
* @category Internal
|
|
93
|
+
*/
|
|
94
|
+
export function getScreenshotPath(testContext, screenshotBaseName) {
|
|
95
|
+
assertTestContext(testContext, TestEnv.Playwright);
|
|
96
|
+
const screenshotFileName = addSuffix({ value: screenshotBaseName, suffix: '.png' });
|
|
97
|
+
return testContext.testInfo.snapshotPath(screenshotFileName);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Take and immediately save a screenshot.
|
|
101
|
+
*
|
|
102
|
+
* @category Internal
|
|
103
|
+
* @returns The path that the screenshot was saved to.
|
|
104
|
+
*/
|
|
105
|
+
export async function takeScreenshot(testContext, options) {
|
|
106
|
+
return await saveScreenshotBuffer(testContext, await takeScreenshotBuffer(testContext, options), options.screenshotBaseName);
|
|
107
|
+
}
|
|
77
108
|
/**
|
|
78
109
|
* Similar to Playwright's `expect().toHaveScreenshot` but allows images to have different sizes and
|
|
79
110
|
* has default comparison threshold options that are wide enough to allow testing between different
|
|
@@ -81,25 +112,25 @@ async function takeScreenshot({ locator, page, options, }) {
|
|
|
81
112
|
*
|
|
82
113
|
* @category Internal
|
|
83
114
|
*/
|
|
84
|
-
export async function expectScreenshot(
|
|
85
|
-
|
|
86
|
-
const currentScreenshotBuffer = await
|
|
87
|
-
const screenshotFilePath =
|
|
115
|
+
export async function expectScreenshot(testContext, options) {
|
|
116
|
+
assertTestContext(testContext, TestEnv.Playwright);
|
|
117
|
+
const currentScreenshotBuffer = await takeScreenshotBuffer(testContext, options);
|
|
118
|
+
const screenshotFilePath = getScreenshotPath(testContext, options.screenshotBaseName);
|
|
88
119
|
async function writeNewScreenshot() {
|
|
89
120
|
log.mutate(`Updated screenshot: ${relative(process.cwd(), screenshotFilePath)}`);
|
|
90
|
-
await
|
|
121
|
+
await saveScreenshotBuffer(testContext, currentScreenshotBuffer, screenshotFilePath);
|
|
91
122
|
}
|
|
92
123
|
async function writeExpectationScreenshot(contents, fileName) {
|
|
93
|
-
const filePath = testInfo.outputPath(addSuffix({ value: fileName, suffix: '.png' }));
|
|
124
|
+
const filePath = assertWrapTestContext(testContext, TestEnv.Playwright).testInfo.outputPath(addSuffix({ value: fileName, suffix: '.png' }));
|
|
94
125
|
await writeFileAndDir(filePath, contents);
|
|
95
126
|
}
|
|
96
127
|
if (existsSync(screenshotFilePath)) {
|
|
97
|
-
if (testInfo.config.updateSnapshots === 'changed') {
|
|
128
|
+
if (testContext.testInfo.config.updateSnapshots === 'changed') {
|
|
98
129
|
await writeNewScreenshot();
|
|
99
130
|
}
|
|
100
131
|
}
|
|
101
132
|
else {
|
|
102
|
-
if (testInfo.config.updateSnapshots !== 'none') {
|
|
133
|
+
if (testContext.testInfo.config.updateSnapshots !== 'none') {
|
|
103
134
|
await writeNewScreenshot();
|
|
104
135
|
}
|
|
105
136
|
await writeExpectationScreenshot(currentScreenshotBuffer, 'actual');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/test",
|
|
3
|
-
"version": "31.50.
|
|
3
|
+
"version": "31.50.2",
|
|
4
4
|
"description": "A universal testing suite that works with Mocha style test runners _and_ Node.js's built-in test runner.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"test",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"test:web": "virmator test --no-deps web 'src/test-web/**/*.test.ts' 'src/augments/universal-testing-suite/**/*.test.ts'"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@augment-vir/assert": "^31.50.
|
|
48
|
-
"@augment-vir/common": "^31.50.
|
|
47
|
+
"@augment-vir/assert": "^31.50.2",
|
|
48
|
+
"@augment-vir/common": "^31.50.2",
|
|
49
49
|
"@open-wc/testing-helpers": "^3.0.1",
|
|
50
50
|
"@virmator/test": "^14.2.2",
|
|
51
51
|
"type-fest": "^5.2.0"
|