@gravity-ui/playwright-tools 0.4.1
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/LICENSE +21 -0
- package/README.md +9 -0
- package/actions/addExtraHttpHeader.d.ts +5 -0
- package/actions/addExtraHttpHeader.js +15 -0
- package/actions/addExtraHttpHeaders.d.ts +5 -0
- package/actions/addExtraHttpHeaders.js +17 -0
- package/actions/assertElementsHidden.d.ts +13 -0
- package/actions/assertElementsHidden.js +33 -0
- package/actions/clearExtraHttpHeaders.d.ts +5 -0
- package/actions/clearExtraHttpHeaders.js +15 -0
- package/actions/collectPageActivity/collectPageActivity.d.ts +11 -0
- package/actions/collectPageActivity/collectPageActivity.js +74 -0
- package/actions/collectPageActivity/constants.d.ts +2 -0
- package/actions/collectPageActivity/constants.js +17 -0
- package/actions/collectPageActivity/index.d.ts +2 -0
- package/actions/collectPageActivity/index.js +5 -0
- package/actions/collectPageActivity/isSameMessage.d.ts +2 -0
- package/actions/collectPageActivity/isSameMessage.js +10 -0
- package/actions/collectPageActivity/isSameResponse.d.ts +2 -0
- package/actions/collectPageActivity/isSameResponse.js +17 -0
- package/actions/collectPageActivity/normalizePathname.d.ts +1 -0
- package/actions/collectPageActivity/normalizePathname.js +8 -0
- package/actions/collectPageActivity/types.d.ts +23 -0
- package/actions/collectPageActivity/types.js +2 -0
- package/actions/disableAnimation.d.ts +8 -0
- package/actions/disableAnimation.js +35 -0
- package/actions/expect-request/expect-request.d.ts +3 -0
- package/actions/expect-request/expect-request.js +62 -0
- package/actions/expect-request/index.d.ts +2 -0
- package/actions/expect-request/index.js +5 -0
- package/actions/expect-request/matchers/compare/DiffLogger.d.ts +9 -0
- package/actions/expect-request/matchers/compare/DiffLogger.js +20 -0
- package/actions/expect-request/matchers/compare/DiffPrinter.d.ts +16 -0
- package/actions/expect-request/matchers/compare/DiffPrinter.js +80 -0
- package/actions/expect-request/matchers/compare/compare.d.ts +6 -0
- package/actions/expect-request/matchers/compare/compare.js +129 -0
- package/actions/expect-request/matchers/compare/constants.d.ts +20 -0
- package/actions/expect-request/matchers/compare/constants.js +23 -0
- package/actions/expect-request/matchers/compare/index.d.ts +4 -0
- package/actions/expect-request/matchers/compare/index.js +23 -0
- package/actions/expect-request/matchers/compare/print-json-diff.d.ts +6 -0
- package/actions/expect-request/matchers/compare/print-json-diff.js +366 -0
- package/actions/expect-request/matchers/compare/types.d.ts +59 -0
- package/actions/expect-request/matchers/compare/types.js +2 -0
- package/actions/expect-request/matchers/compare/utils.d.ts +5 -0
- package/actions/expect-request/matchers/compare/utils.js +19 -0
- package/actions/expect-request/matchers/match-body.d.ts +4 -0
- package/actions/expect-request/matchers/match-body.js +12 -0
- package/actions/expect-request/matchers/match-method.d.ts +2 -0
- package/actions/expect-request/matchers/match-method.js +14 -0
- package/actions/expect-request/matchers/match-query.d.ts +3 -0
- package/actions/expect-request/matchers/match-query.js +34 -0
- package/actions/expect-request/matchers/match-url.d.ts +1 -0
- package/actions/expect-request/matchers/match-url.js +13 -0
- package/actions/expect-request/matchers/match.d.ts +3 -0
- package/actions/expect-request/matchers/match.js +10 -0
- package/actions/expect-request/matchers/types.d.ts +3 -0
- package/actions/expect-request/matchers/types.js +2 -0
- package/actions/expect-request/matchers/utils.d.ts +1 -0
- package/actions/expect-request/matchers/utils.js +9 -0
- package/actions/expect-request/poll-with-timeout.d.ts +22 -0
- package/actions/expect-request/poll-with-timeout.js +39 -0
- package/actions/expect-request/types.d.ts +18 -0
- package/actions/expect-request/types.js +2 -0
- package/actions/getExtraHttpHeader.d.ts +5 -0
- package/actions/getExtraHttpHeader.js +14 -0
- package/actions/getExtraHttpHeaders.d.ts +7 -0
- package/actions/getExtraHttpHeaders.js +14 -0
- package/actions/getGlobalSettings.d.ts +5 -0
- package/actions/getGlobalSettings.js +10 -0
- package/actions/getTestSlug.d.ts +5 -0
- package/actions/getTestSlug.js +13 -0
- package/actions/hasExtraHttpHeader.d.ts +5 -0
- package/actions/hasExtraHttpHeader.js +14 -0
- package/actions/index.d.ts +18 -0
- package/actions/index.js +39 -0
- package/actions/matchScreenshot.d.ts +90 -0
- package/actions/matchScreenshot.js +104 -0
- package/actions/mockDate.d.ts +10 -0
- package/actions/mockDate.js +20 -0
- package/actions/removeExtraHttpHeader.d.ts +5 -0
- package/actions/removeExtraHttpHeader.js +15 -0
- package/actions/setCacheSettings.d.ts +7 -0
- package/actions/setCacheSettings.js +12 -0
- package/actions/setGlobalSettings.d.ts +12 -0
- package/actions/setGlobalSettings.js +19 -0
- package/actions/setTestSlug.d.ts +9 -0
- package/actions/setTestSlug.js +22 -0
- package/actions/waitForNetworkSettled.d.ts +7 -0
- package/actions/waitForNetworkSettled.js +48 -0
- package/auth/storage/applyStorageState.d.ts +10 -0
- package/auth/storage/applyStorageState.js +16 -0
- package/auth/storage/applyStorageStateFor.d.ts +9 -0
- package/auth/storage/applyStorageStateFor.js +19 -0
- package/auth/storage/deleteStorageStateFor.d.ts +6 -0
- package/auth/storage/deleteStorageStateFor.js +12 -0
- package/auth/storage/getStorageState.d.ts +27 -0
- package/auth/storage/getStorageState.js +18 -0
- package/auth/storage/getStorageStateFor.d.ts +24 -0
- package/auth/storage/getStorageStateFor.js +12 -0
- package/auth/storage/hasStorageStateFor.d.ts +6 -0
- package/auth/storage/hasStorageStateFor.js +12 -0
- package/auth/storage/index.d.ts +9 -0
- package/auth/storage/index.js +21 -0
- package/auth/storage/restoreCookies.d.ts +10 -0
- package/auth/storage/restoreCookies.js +16 -0
- package/auth/storage/restoreLocalStorage.d.ts +10 -0
- package/auth/storage/restoreLocalStorage.js +26 -0
- package/auth/storage/saveStorageStateFor.d.ts +8 -0
- package/auth/storage/saveStorageStateFor.js +15 -0
- package/config/browsers.d.ts +24 -0
- package/config/browsers.js +7 -0
- package/config/browsersDesktop.d.ts +14 -0
- package/config/browsersDesktop.js +28 -0
- package/config/browsersMobile.d.ts +14 -0
- package/config/browsersMobile.js +21 -0
- package/data/cacheSettings.d.ts +19 -0
- package/data/cacheSettings.js +21 -0
- package/data/extraHttpHeaders.d.ts +5 -0
- package/data/extraHttpHeaders.js +7 -0
- package/data/globalSettings.d.ts +100 -0
- package/data/globalSettings.js +112 -0
- package/data/storageStates.d.ts +36 -0
- package/data/storageStates.js +50 -0
- package/data/testSlugs.d.ts +5 -0
- package/data/testSlugs.js +7 -0
- package/fixtures/expect-request/expect-request-fixture.d.ts +8 -0
- package/fixtures/expect-request/expect-request-fixture.js +26 -0
- package/fixtures/expect-request/index.d.ts +3 -0
- package/fixtures/expect-request/index.js +5 -0
- package/fixtures/expect-request/types.d.ts +5 -0
- package/fixtures/expect-request/types.js +2 -0
- package/fixtures/expect-screenshot/expect-screenshot-fixture.d.ts +5 -0
- package/fixtures/expect-screenshot/expect-screenshot-fixture.js +28 -0
- package/fixtures/expect-screenshot/index.d.ts +2 -0
- package/fixtures/expect-screenshot/index.js +5 -0
- package/fixtures/expect-screenshot/types.d.ts +14 -0
- package/fixtures/expect-screenshot/types.js +2 -0
- package/fixtures/global-settings/global-settings-fixture.d.ts +3 -0
- package/fixtures/global-settings/global-settings-fixture.js +22 -0
- package/fixtures/global-settings/index.d.ts +2 -0
- package/fixtures/global-settings/index.js +5 -0
- package/fixtures/global-settings/types.d.ts +15 -0
- package/fixtures/global-settings/types.js +2 -0
- package/fixtures/index.d.ts +10 -0
- package/fixtures/index.js +13 -0
- package/fixtures/mock-network/har-patcher.d.ts +8 -0
- package/fixtures/mock-network/har-patcher.js +40 -0
- package/fixtures/mock-network/index.d.ts +2 -0
- package/fixtures/mock-network/index.js +5 -0
- package/fixtures/mock-network/mock-network-fixture.d.ts +6 -0
- package/fixtures/mock-network/mock-network-fixture.js +38 -0
- package/fixtures/mock-network/types.d.ts +86 -0
- package/fixtures/mock-network/types.js +2 -0
- package/fixtures/testSlug.d.ts +12 -0
- package/fixtures/testSlug.js +19 -0
- package/fixtures/types.d.ts +4 -0
- package/fixtures/types.js +2 -0
- package/har/addHarLookupTransform.d.ts +9 -0
- package/har/addHarLookupTransform.js +44 -0
- package/har/addHarOpenTransform.d.ts +6 -0
- package/har/addHarOpenTransform.js +41 -0
- package/har/addHarRecorderTransform.d.ts +6 -0
- package/har/addHarRecorderTransform.js +36 -0
- package/har/clearHeaders.d.ts +11 -0
- package/har/clearHeaders.js +25 -0
- package/har/getPlaywrightCoreModule.d.ts +4 -0
- package/har/getPlaywrightCoreModule.js +33 -0
- package/har/index.d.ts +11 -0
- package/har/index.js +17 -0
- package/har/initDumps.d.ts +66 -0
- package/har/initDumps.js +54 -0
- package/har/replaceBaseUrlInEntry.d.ts +9 -0
- package/har/replaceBaseUrlInEntry.js +29 -0
- package/har/setExtraHash.d.ts +5 -0
- package/har/setExtraHash.js +18 -0
- package/har/types.d.ts +175 -0
- package/har/types.js +3 -0
- package/package.json +74 -0
- package/utils/NeverError.d.ts +6 -0
- package/utils/NeverError.js +12 -0
- package/utils/deleteCache.d.ts +7 -0
- package/utils/deleteCache.js +15 -0
- package/utils/extractTestSlug.d.ts +12 -0
- package/utils/extractTestSlug.js +24 -0
- package/utils/fetchWithoutRejectUnauthorized.d.ts +4 -0
- package/utils/fetchWithoutRejectUnauthorized.js +28 -0
- package/utils/getCookieDomain.d.ts +4 -0
- package/utils/getCookieDomain.js +13 -0
- package/utils/index.d.ts +9 -0
- package/utils/index.js +21 -0
- package/utils/readCache.d.ts +8 -0
- package/utils/readCache.js +32 -0
- package/utils/waitForResolve.d.ts +24 -0
- package/utils/waitForResolve.js +40 -0
- package/utils/waitHttpService.d.ts +28 -0
- package/utils/waitHttpService.js +25 -0
- package/utils/writeCache.d.ts +8 -0
- package/utils/writeCache.js +18 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { Config } from '../actions/collectPageActivity';
|
|
2
|
+
import type { OnBeforeScreenshotCallback, OnSwitchThemeCallback, ScreenshotOptions, Theme } from '../actions/matchScreenshot';
|
|
3
|
+
/**
|
|
4
|
+
* Global settings for commands
|
|
5
|
+
*/
|
|
6
|
+
export declare const globalSettings: {
|
|
7
|
+
/**
|
|
8
|
+
* actions/assertElementsHidden
|
|
9
|
+
*/
|
|
10
|
+
assertElementsHidden: {
|
|
11
|
+
defaultWaitForVisibleTimeout: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* actions/matchScreenshot
|
|
15
|
+
*/
|
|
16
|
+
matchScreenshot: {
|
|
17
|
+
/**
|
|
18
|
+
* Screenshot creation and comparison parameters.
|
|
19
|
+
* Will be merged with those passed during the call.
|
|
20
|
+
*/
|
|
21
|
+
options: ScreenshotOptions;
|
|
22
|
+
/**
|
|
23
|
+
* CSS selectors (pure CSS) of elements to hide.
|
|
24
|
+
* Will be merged with those passed in the call.
|
|
25
|
+
*/
|
|
26
|
+
hideBySelector: string[] | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Pause before screenshot (ms)
|
|
29
|
+
*/
|
|
30
|
+
pause: number;
|
|
31
|
+
/**
|
|
32
|
+
* Use soft assertion
|
|
33
|
+
*/
|
|
34
|
+
soft: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Default screenshot name
|
|
37
|
+
*/
|
|
38
|
+
name: string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Should I add a slug to the screenshot file name?
|
|
41
|
+
*/
|
|
42
|
+
shouldPrependSlugToName: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Topics that require a screenshot
|
|
45
|
+
* By default, screenshots are taken for the current theme. Switching does not occur
|
|
46
|
+
*/
|
|
47
|
+
themes: Theme[] | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Callback before taking a screenshot. Useful for any special stabilizing actions
|
|
50
|
+
* @param page Page Current page
|
|
51
|
+
*/
|
|
52
|
+
onBeforeScreenshot: OnBeforeScreenshotCallback | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Callback to switch theme to pages before taking screenshot
|
|
55
|
+
* By default, switches the theme using `page.emulateMedia({ colorScheme: theme });`
|
|
56
|
+
* @param theme Theme The theme for which the screenshot will be taken
|
|
57
|
+
* @param page Page Current page
|
|
58
|
+
*/
|
|
59
|
+
onSwitchTheme: undefined | OnSwitchThemeCallback;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* actions/mockDate
|
|
63
|
+
*/
|
|
64
|
+
mockDate: {
|
|
65
|
+
/**
|
|
66
|
+
* Default date
|
|
67
|
+
*/
|
|
68
|
+
defaultDate: {
|
|
69
|
+
year: number;
|
|
70
|
+
month: number;
|
|
71
|
+
day: number;
|
|
72
|
+
hour: number;
|
|
73
|
+
min: number;
|
|
74
|
+
sec: number;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* utils/waitForResolve
|
|
79
|
+
*/
|
|
80
|
+
waitForResolve: {
|
|
81
|
+
/**
|
|
82
|
+
* Interval between checks (ms)
|
|
83
|
+
*/
|
|
84
|
+
interval: number;
|
|
85
|
+
/**
|
|
86
|
+
* Timeout after which checks are aborted (ms)
|
|
87
|
+
* `0` — without timeout
|
|
88
|
+
*/
|
|
89
|
+
timeout: number;
|
|
90
|
+
};
|
|
91
|
+
collectPageActivity: Pick<Required<Config>, "ignoredMessageTypes" | "expectedMessages" | "ignoredResponseStatuses" | "expectedResponses" | "requestIdHeader">;
|
|
92
|
+
waitForNetworkSettled: {
|
|
93
|
+
/** Timeout time after request */
|
|
94
|
+
delay: number;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
export type GlobalSettings = typeof globalSettings;
|
|
98
|
+
export type PartialGlobalSettings = {
|
|
99
|
+
[Key in keyof GlobalSettings]?: Partial<GlobalSettings[Key]>;
|
|
100
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.globalSettings = void 0;
|
|
4
|
+
const constants_1 = require("../actions/collectPageActivity/constants");
|
|
5
|
+
const collectPageActivity = {
|
|
6
|
+
ignoredMessageTypes: constants_1.defaultIgnoredMessageTypes,
|
|
7
|
+
expectedMessages: [
|
|
8
|
+
{
|
|
9
|
+
type: 'error',
|
|
10
|
+
text: /^Failed to load resource: the server responded with a status of/,
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
ignoredResponseStatuses: constants_1.defaultIgnoredResponseStatuses,
|
|
14
|
+
expectedResponses: [],
|
|
15
|
+
requestIdHeader: 'x-request-id',
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Global settings for commands
|
|
19
|
+
*/
|
|
20
|
+
exports.globalSettings = {
|
|
21
|
+
/**
|
|
22
|
+
* actions/assertElementsHidden
|
|
23
|
+
*/
|
|
24
|
+
assertElementsHidden: {
|
|
25
|
+
defaultWaitForVisibleTimeout: 300,
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
* actions/matchScreenshot
|
|
29
|
+
*/
|
|
30
|
+
matchScreenshot: {
|
|
31
|
+
/**
|
|
32
|
+
* Screenshot creation and comparison parameters.
|
|
33
|
+
* Will be merged with those passed during the call.
|
|
34
|
+
*/
|
|
35
|
+
options: {},
|
|
36
|
+
/**
|
|
37
|
+
* CSS selectors (pure CSS) of elements to hide.
|
|
38
|
+
* Will be merged with those passed in the call.
|
|
39
|
+
*/
|
|
40
|
+
hideBySelector: undefined,
|
|
41
|
+
/**
|
|
42
|
+
* Pause before screenshot (ms)
|
|
43
|
+
*/
|
|
44
|
+
pause: 1000,
|
|
45
|
+
/**
|
|
46
|
+
* Use soft assertion
|
|
47
|
+
*/
|
|
48
|
+
soft: true,
|
|
49
|
+
/**
|
|
50
|
+
* Default screenshot name
|
|
51
|
+
*/
|
|
52
|
+
name: 'plain',
|
|
53
|
+
/**
|
|
54
|
+
* Should I add a slug to the screenshot file name?
|
|
55
|
+
*/
|
|
56
|
+
shouldPrependSlugToName: true,
|
|
57
|
+
/**
|
|
58
|
+
* Topics that require a screenshot
|
|
59
|
+
* By default, screenshots are taken for the current theme. Switching does not occur
|
|
60
|
+
*/
|
|
61
|
+
themes: undefined,
|
|
62
|
+
/**
|
|
63
|
+
* Callback before taking a screenshot. Useful for any special stabilizing actions
|
|
64
|
+
* @param page Page Current page
|
|
65
|
+
*/
|
|
66
|
+
onBeforeScreenshot: undefined,
|
|
67
|
+
/**
|
|
68
|
+
* Callback to switch theme to pages before taking screenshot
|
|
69
|
+
* By default, switches the theme using `page.emulateMedia({ colorScheme: theme });`
|
|
70
|
+
* @param theme Theme The theme for which the screenshot will be taken
|
|
71
|
+
* @param page Page Current page
|
|
72
|
+
*/
|
|
73
|
+
onSwitchTheme: (async (theme, page) => {
|
|
74
|
+
await page.emulateMedia({ colorScheme: theme });
|
|
75
|
+
}),
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* actions/mockDate
|
|
79
|
+
*/
|
|
80
|
+
mockDate: {
|
|
81
|
+
/**
|
|
82
|
+
* Default date
|
|
83
|
+
*/
|
|
84
|
+
defaultDate: {
|
|
85
|
+
year: 2020,
|
|
86
|
+
month: 7,
|
|
87
|
+
day: 15,
|
|
88
|
+
hour: 12,
|
|
89
|
+
min: 0,
|
|
90
|
+
sec: 0,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* utils/waitForResolve
|
|
95
|
+
*/
|
|
96
|
+
waitForResolve: {
|
|
97
|
+
/**
|
|
98
|
+
* Interval between checks (ms)
|
|
99
|
+
*/
|
|
100
|
+
interval: 100,
|
|
101
|
+
/**
|
|
102
|
+
* Timeout after which checks are aborted (ms)
|
|
103
|
+
* `0` — without timeout
|
|
104
|
+
*/
|
|
105
|
+
timeout: 5000,
|
|
106
|
+
},
|
|
107
|
+
collectPageActivity,
|
|
108
|
+
waitForNetworkSettled: {
|
|
109
|
+
/** Timeout time after request */
|
|
110
|
+
delay: 0,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BrowserContext } from '@playwright/test';
|
|
2
|
+
export type StorageState = Awaited<ReturnType<BrowserContext['storageState']>>;
|
|
3
|
+
/**
|
|
4
|
+
* Adds a snapshot to the repository
|
|
5
|
+
*/
|
|
6
|
+
export declare function setState(key: string, state: StorageState): void;
|
|
7
|
+
/**
|
|
8
|
+
* Returns a snapshot from storage
|
|
9
|
+
*/
|
|
10
|
+
export declare function getState(key: string): Promise<{
|
|
11
|
+
cookies: Array<{
|
|
12
|
+
name: string;
|
|
13
|
+
value: string;
|
|
14
|
+
domain: string;
|
|
15
|
+
path: string;
|
|
16
|
+
expires: number;
|
|
17
|
+
httpOnly: boolean;
|
|
18
|
+
secure: boolean;
|
|
19
|
+
sameSite: "Strict" | "Lax" | "None";
|
|
20
|
+
}>;
|
|
21
|
+
origins: Array<{
|
|
22
|
+
origin: string;
|
|
23
|
+
localStorage: Array<{
|
|
24
|
+
name: string;
|
|
25
|
+
value: string;
|
|
26
|
+
}>;
|
|
27
|
+
}>;
|
|
28
|
+
} | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a snapshot is in the repository
|
|
31
|
+
*/
|
|
32
|
+
export declare function hasState(key: string): Promise<boolean>;
|
|
33
|
+
/**
|
|
34
|
+
* Deletes a snapshot from storage
|
|
35
|
+
*/
|
|
36
|
+
export declare function deleteState(key: string): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setState = setState;
|
|
4
|
+
exports.getState = getState;
|
|
5
|
+
exports.hasState = hasState;
|
|
6
|
+
exports.deleteState = deleteState;
|
|
7
|
+
const deleteCache_1 = require("../utils/deleteCache");
|
|
8
|
+
const readCache_1 = require("../utils/readCache");
|
|
9
|
+
const writeCache_1 = require("../utils/writeCache");
|
|
10
|
+
const cacheSettings_1 = require("./cacheSettings");
|
|
11
|
+
/**
|
|
12
|
+
* Browser Storage Snapshots
|
|
13
|
+
*/
|
|
14
|
+
const storageStates = new Map();
|
|
15
|
+
/**
|
|
16
|
+
* Adds a snapshot to the repository
|
|
17
|
+
*/
|
|
18
|
+
function setState(key, state) {
|
|
19
|
+
storageStates.set(key, state);
|
|
20
|
+
if (cacheSettings_1.cacheSettings.auth.path) {
|
|
21
|
+
void (0, writeCache_1.writeCache)(cacheSettings_1.cacheSettings.auth.path, key, state).catch((error) => console.warn(error));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns a snapshot from storage
|
|
26
|
+
*/
|
|
27
|
+
async function getState(key) {
|
|
28
|
+
if (!storageStates.has(key) && cacheSettings_1.cacheSettings.auth.path) {
|
|
29
|
+
const state = await (0, readCache_1.readCache)(cacheSettings_1.cacheSettings.auth.path, key, cacheSettings_1.cacheSettings.auth.ttl);
|
|
30
|
+
if (state) {
|
|
31
|
+
storageStates.set(key, state);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return storageStates.get(key);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Checks if a snapshot is in the repository
|
|
38
|
+
*/
|
|
39
|
+
async function hasState(key) {
|
|
40
|
+
return Boolean(await getState(key));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Deletes a snapshot from storage
|
|
44
|
+
*/
|
|
45
|
+
function deleteState(key) {
|
|
46
|
+
storageStates.delete(key);
|
|
47
|
+
if (cacheSettings_1.cacheSettings.auth.path) {
|
|
48
|
+
void (0, deleteCache_1.deleteCache)(cacheSettings_1.cacheSettings.auth.path, key);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PlaywrightTestArgs, PlaywrightTestOptions, TestFixture } from '@playwright/test';
|
|
2
|
+
import type { ExpectRequestFn } from './types';
|
|
3
|
+
export declare const expectRequestFixture: TestFixture<ExpectRequestFn, PlaywrightTestOptions & PlaywrightTestArgs>;
|
|
4
|
+
declare const fixtureOptions: {
|
|
5
|
+
readonly scope: "test";
|
|
6
|
+
};
|
|
7
|
+
export declare const expectRequest: [typeof expectRequestFixture, typeof fixtureOptions];
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expectRequest = exports.expectRequestFixture = void 0;
|
|
4
|
+
const expect_request_1 = require("../../actions/expect-request");
|
|
5
|
+
const expectRequestFixture = async ({ page, baseURL }, use) => {
|
|
6
|
+
if (!baseURL) {
|
|
7
|
+
throw new Error('Base URL required for requests matching!');
|
|
8
|
+
}
|
|
9
|
+
const requests = new Map();
|
|
10
|
+
page.on('request', (request) => {
|
|
11
|
+
const url = new URL(request.url());
|
|
12
|
+
const key = `${url.protocol}//${url.hostname}${url.pathname}`;
|
|
13
|
+
requests.set(key, request);
|
|
14
|
+
});
|
|
15
|
+
const boundExpectRequest = expect_request_1.expectRequest.bind(null, requests);
|
|
16
|
+
await use(boundExpectRequest);
|
|
17
|
+
requests.clear();
|
|
18
|
+
};
|
|
19
|
+
exports.expectRequestFixture = expectRequestFixture;
|
|
20
|
+
const fixtureOptions = {
|
|
21
|
+
scope: 'test',
|
|
22
|
+
};
|
|
23
|
+
exports.expectRequest = [
|
|
24
|
+
exports.expectRequestFixture,
|
|
25
|
+
fixtureOptions,
|
|
26
|
+
];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expectRequest = void 0;
|
|
4
|
+
var expect_request_fixture_1 = require("./expect-request-fixture");
|
|
5
|
+
Object.defineProperty(exports, "expectRequest", { enumerable: true, get: function () { return expect_request_fixture_1.expectRequest; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ExpectRequestFnMatcher, ExpectRequestFnOptions } from '../../actions/expect-request';
|
|
2
|
+
export type ExpectRequestFn = (url: string | RegExp, matcher?: ExpectRequestFnMatcher, options?: ExpectRequestFnOptions) => Promise<void>;
|
|
3
|
+
export interface ExpectRequestTestArgs {
|
|
4
|
+
expectRequest: ExpectRequestFn;
|
|
5
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PlaywrightTestArgs, PlaywrightTestOptions, TestFixture } from '@playwright/test';
|
|
2
|
+
import type { ExpectScreenshotFixtureBuilderParams, ExpectScreenshotFn } from './types';
|
|
3
|
+
export declare function expectScreenshotFixtureBuilder({ screenshotOptions, getDefaultMask, ...restDefaults }?: ExpectScreenshotFixtureBuilderParams): [TestFixture<ExpectScreenshotFn, PlaywrightTestArgs & PlaywrightTestOptions>, {
|
|
4
|
+
scope: "test";
|
|
5
|
+
}];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expectScreenshotFixtureBuilder = expectScreenshotFixtureBuilder;
|
|
4
|
+
const matchScreenshot_1 = require("../../actions/matchScreenshot");
|
|
5
|
+
function expectScreenshotFixtureBuilder({ screenshotOptions, getDefaultMask, ...restDefaults } = {}) {
|
|
6
|
+
const expectScreenshotFixture = async ({ page }, use) => {
|
|
7
|
+
const expectScreenshot = ({ options = {}, shouldUseDefaultMask = true, ...restParams } = {}) => {
|
|
8
|
+
const { mask = [] } = options;
|
|
9
|
+
const defaultMask = shouldUseDefaultMask && getDefaultMask ? getDefaultMask(page) : [];
|
|
10
|
+
const maskToUse = [...mask, ...defaultMask];
|
|
11
|
+
const mergedOptions = {
|
|
12
|
+
options: { ...screenshotOptions, ...options, mask: maskToUse },
|
|
13
|
+
...restDefaults,
|
|
14
|
+
...restParams,
|
|
15
|
+
};
|
|
16
|
+
return (0, matchScreenshot_1.matchScreenshot)(page, mergedOptions);
|
|
17
|
+
};
|
|
18
|
+
await use(expectScreenshot);
|
|
19
|
+
};
|
|
20
|
+
const fixtureOptions = {
|
|
21
|
+
scope: 'test',
|
|
22
|
+
};
|
|
23
|
+
const expectScreenshot = [
|
|
24
|
+
expectScreenshotFixture,
|
|
25
|
+
fixtureOptions,
|
|
26
|
+
];
|
|
27
|
+
return expectScreenshot;
|
|
28
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expectScreenshotFixtureBuilder = void 0;
|
|
4
|
+
var expect_screenshot_fixture_1 = require("./expect-screenshot-fixture");
|
|
5
|
+
Object.defineProperty(exports, "expectScreenshotFixtureBuilder", { enumerable: true, get: function () { return expect_screenshot_fixture_1.expectScreenshotFixtureBuilder; } });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Locator, Page } from '@playwright/test';
|
|
2
|
+
import type { MatchScreenshotOptions, ScreenshotOptions } from '../../actions/matchScreenshot';
|
|
3
|
+
export type DefaultScreenshotOptions = Omit<ScreenshotOptions, 'mask'>;
|
|
4
|
+
export type ExpectScreenshotOptions = MatchScreenshotOptions & {
|
|
5
|
+
shouldUseDefaultMask?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type ExpectScreenshotFixtureBuilderParams = Pick<MatchScreenshotOptions, 'hideBySelector' | 'pause' | 'soft' | 'shouldPrependSlugToName' | 'themes' | 'onBeforeScreenshot' | 'onSwitchTheme'> & {
|
|
8
|
+
screenshotOptions?: DefaultScreenshotOptions;
|
|
9
|
+
getDefaultMask?: (page: Page) => Locator[];
|
|
10
|
+
};
|
|
11
|
+
export type ExpectScreenshotFn = (params?: ExpectScreenshotOptions) => Promise<void>;
|
|
12
|
+
export type ExpectScreenshotTestArgs = {
|
|
13
|
+
expectScreenshot: ExpectScreenshotFn;
|
|
14
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions } from '@playwright/test';
|
|
2
|
+
import type { GlobalSettingsFixturesBuilderParams, GlobalSettingsTestArgs, GlobalSettingsWorkerArgs } from './types';
|
|
3
|
+
export declare function globalSettingsFixturesBuilder({ globalSettings }?: GlobalSettingsFixturesBuilderParams): Fixtures<GlobalSettingsTestArgs, GlobalSettingsWorkerArgs, PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.globalSettingsFixturesBuilder = globalSettingsFixturesBuilder;
|
|
4
|
+
const actions_1 = require("../../actions");
|
|
5
|
+
function globalSettingsFixturesBuilder({ globalSettings } = { globalSettings: {} }) {
|
|
6
|
+
const initGlobalSettingsFixture = async ({}, use) => {
|
|
7
|
+
(0, actions_1.setGlobalSettings)(globalSettings);
|
|
8
|
+
await use();
|
|
9
|
+
};
|
|
10
|
+
const setGlobalSettingsFixture = async ({}, use) => {
|
|
11
|
+
await use(actions_1.setGlobalSettings);
|
|
12
|
+
};
|
|
13
|
+
const getGlobalSettingsFixture = async ({}, use) => {
|
|
14
|
+
await use(actions_1.getGlobalSettings);
|
|
15
|
+
};
|
|
16
|
+
const fixtures = {
|
|
17
|
+
initGlobalSettings: [initGlobalSettingsFixture, { scope: 'worker', auto: true }],
|
|
18
|
+
setGlobalSettings: [setGlobalSettingsFixture, { scope: 'test' }],
|
|
19
|
+
getGlobalSettings: [getGlobalSettingsFixture, { scope: 'test' }],
|
|
20
|
+
};
|
|
21
|
+
return fixtures;
|
|
22
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.globalSettingsFixturesBuilder = void 0;
|
|
4
|
+
var global_settings_fixture_1 = require("./global-settings-fixture");
|
|
5
|
+
Object.defineProperty(exports, "globalSettingsFixturesBuilder", { enumerable: true, get: function () { return global_settings_fixture_1.globalSettingsFixturesBuilder; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { getGlobalSettings, setGlobalSettings } from '../../actions';
|
|
2
|
+
import type { PartialGlobalSettings } from '../../data/globalSettings';
|
|
3
|
+
export type GlobalSettingsFixturesBuilderParams = {
|
|
4
|
+
/**
|
|
5
|
+
* Global settings that need to be overridden
|
|
6
|
+
*/
|
|
7
|
+
globalSettings: PartialGlobalSettings;
|
|
8
|
+
};
|
|
9
|
+
export type GlobalSettingsWorkerArgs = {
|
|
10
|
+
initGlobalSettings: void;
|
|
11
|
+
};
|
|
12
|
+
export type GlobalSettingsTestArgs = {
|
|
13
|
+
setGlobalSettings: typeof setGlobalSettings;
|
|
14
|
+
getGlobalSettings: typeof getGlobalSettings;
|
|
15
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { TestSlugResult } from './testSlug';
|
|
2
|
+
export { testSlug } from './testSlug';
|
|
3
|
+
export type { MockNetworkFixtureBuilderParams } from './mock-network';
|
|
4
|
+
export { mockNetworkFixtureBuilder } from './mock-network';
|
|
5
|
+
export type { ExpectRequestFn, ExpectRequestTestArgs, ExpectRequestFnMatcher, ExpectRequestFnOptions, } from './expect-request';
|
|
6
|
+
export { expectRequest } from './expect-request';
|
|
7
|
+
export type { ExpectScreenshotFn, ExpectScreenshotTestArgs, ExpectScreenshotFixtureBuilderParams, } from './expect-screenshot';
|
|
8
|
+
export { expectScreenshotFixtureBuilder } from './expect-screenshot';
|
|
9
|
+
export type { GlobalSettingsFixturesBuilderParams, GlobalSettingsTestArgs, GlobalSettingsWorkerArgs, } from './global-settings';
|
|
10
|
+
export { globalSettingsFixturesBuilder } from './global-settings';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.globalSettingsFixturesBuilder = exports.expectScreenshotFixtureBuilder = exports.expectRequest = exports.mockNetworkFixtureBuilder = exports.testSlug = void 0;
|
|
4
|
+
var testSlug_1 = require("./testSlug");
|
|
5
|
+
Object.defineProperty(exports, "testSlug", { enumerable: true, get: function () { return testSlug_1.testSlug; } });
|
|
6
|
+
var mock_network_1 = require("./mock-network");
|
|
7
|
+
Object.defineProperty(exports, "mockNetworkFixtureBuilder", { enumerable: true, get: function () { return mock_network_1.mockNetworkFixtureBuilder; } });
|
|
8
|
+
var expect_request_1 = require("./expect-request");
|
|
9
|
+
Object.defineProperty(exports, "expectRequest", { enumerable: true, get: function () { return expect_request_1.expectRequest; } });
|
|
10
|
+
var expect_screenshot_1 = require("./expect-screenshot");
|
|
11
|
+
Object.defineProperty(exports, "expectScreenshotFixtureBuilder", { enumerable: true, get: function () { return expect_screenshot_1.expectScreenshotFixtureBuilder; } });
|
|
12
|
+
var global_settings_1 = require("./global-settings");
|
|
13
|
+
Object.defineProperty(exports, "globalSettingsFixturesBuilder", { enumerable: true, get: function () { return global_settings_1.globalSettingsFixturesBuilder; } });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MockNetworkFixtureBuilderParams } from './types';
|
|
2
|
+
export type HarPatcherParams = Pick<MockNetworkFixtureBuilderParams, 'headersToRemove' | 'setCookieToRemove' | 'onHarEntryWillRead' | 'onHarEntryWillWrite' | 'onTransformHarLookupParams' | 'onTransformHarLookupResult'> & {
|
|
3
|
+
/**
|
|
4
|
+
* Base url of the test
|
|
5
|
+
*/
|
|
6
|
+
baseURL: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function harPatcher({ baseURL, headersToRemove: additionalHeadersToRemove, setCookieToRemove: additionalSetCookieToRemove, onHarEntryWillWrite, onHarEntryWillRead, onTransformHarLookupParams, onTransformHarLookupResult, }: HarPatcherParams): void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.harPatcher = harPatcher;
|
|
4
|
+
const har_1 = require("../../har");
|
|
5
|
+
const DEFAULT_REMOVE_HEADERS = new Set([
|
|
6
|
+
'cookie',
|
|
7
|
+
'x-csrf-token',
|
|
8
|
+
'content-security-policy',
|
|
9
|
+
'Session_id',
|
|
10
|
+
]);
|
|
11
|
+
const DEFAULT_REMOVE_SET_COOKIE_FOR = new Set(['CSRF-TOKEN']);
|
|
12
|
+
const baseUrlPLaceholder = 'https://base.url.placeholder';
|
|
13
|
+
function harPatcher({ baseURL, headersToRemove: additionalHeadersToRemove = [], setCookieToRemove: additionalSetCookieToRemove = [], onHarEntryWillWrite, onHarEntryWillRead, onTransformHarLookupParams, onTransformHarLookupResult, }) {
|
|
14
|
+
const headersToRemove = new Set([...DEFAULT_REMOVE_HEADERS, ...additionalHeadersToRemove]);
|
|
15
|
+
const setCookieToRemove = new Set([
|
|
16
|
+
...DEFAULT_REMOVE_SET_COOKIE_FOR,
|
|
17
|
+
...additionalSetCookieToRemove,
|
|
18
|
+
]);
|
|
19
|
+
(0, har_1.addHarRecorderTransform)((entry) => {
|
|
20
|
+
// eslint-disable-next-line no-param-reassign
|
|
21
|
+
entry.request.headers = (0, har_1.clearHeaders)(entry.request.headers, {
|
|
22
|
+
removeHeaders: headersToRemove,
|
|
23
|
+
});
|
|
24
|
+
// eslint-disable-next-line no-param-reassign
|
|
25
|
+
entry.response.headers = (0, har_1.clearHeaders)(entry.response.headers, {
|
|
26
|
+
removeHeaders: headersToRemove,
|
|
27
|
+
removeSetCookieFor: setCookieToRemove,
|
|
28
|
+
});
|
|
29
|
+
(0, har_1.replaceBaseUrlInEntry)(entry, baseURL, baseUrlPLaceholder);
|
|
30
|
+
onHarEntryWillWrite?.(entry);
|
|
31
|
+
});
|
|
32
|
+
(0, har_1.addHarOpenTransform)((harFile) => {
|
|
33
|
+
const entries = harFile.log.entries;
|
|
34
|
+
for (const entry of entries) {
|
|
35
|
+
(0, har_1.replaceBaseUrlInEntry)(entry, baseUrlPLaceholder, baseURL);
|
|
36
|
+
onHarEntryWillRead?.(entry);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
(0, har_1.addHarLookupTransform)(onTransformHarLookupParams, onTransformHarLookupResult);
|
|
40
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mockNetworkFixtureBuilder = void 0;
|
|
4
|
+
var mock_network_fixture_1 = require("./mock-network-fixture");
|
|
5
|
+
Object.defineProperty(exports, "mockNetworkFixtureBuilder", { enumerable: true, get: function () { return mock_network_fixture_1.mockNetworkFixtureBuilder; } });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PlaywrightTestArgs, PlaywrightTestOptions, TestFixture } from '@playwright/test';
|
|
2
|
+
import type { MockNetworkFixtureBuilderParams } from './types';
|
|
3
|
+
export declare function mockNetworkFixtureBuilder({ shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip, url: urlMatcherBuilder, dumpsPath, dumpsFilePath, ...harPatcherParams }: MockNetworkFixtureBuilderParams): [TestFixture<boolean, PlaywrightTestArgs & PlaywrightTestOptions>, {
|
|
4
|
+
auto: boolean;
|
|
5
|
+
scope: "test";
|
|
6
|
+
}];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mockNetworkFixtureBuilder = mockNetworkFixtureBuilder;
|
|
4
|
+
const har_1 = require("../../har");
|
|
5
|
+
const har_patcher_1 = require("./har-patcher");
|
|
6
|
+
function mockNetworkFixtureBuilder({ shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip = true, url: urlMatcherBuilder, dumpsPath, dumpsFilePath, ...harPatcherParams }) {
|
|
7
|
+
const mockNetworkFixture = async ({ baseURL: rawBaseURL, page }, use, testInfo) => {
|
|
8
|
+
if (!rawBaseURL) {
|
|
9
|
+
throw new Error('baseURL should be specified in playwright config');
|
|
10
|
+
}
|
|
11
|
+
const baseURL = rawBaseURL.replace(/\/+$/, '');
|
|
12
|
+
(0, har_patcher_1.harPatcher)({
|
|
13
|
+
baseURL,
|
|
14
|
+
...harPatcherParams,
|
|
15
|
+
});
|
|
16
|
+
const update = Boolean(shouldUpdate);
|
|
17
|
+
const url = urlMatcherBuilder(baseURL);
|
|
18
|
+
await (0, har_1.initDumps)(page, testInfo, {
|
|
19
|
+
dumpsPath,
|
|
20
|
+
dumpsFilePath,
|
|
21
|
+
forceUpdateIfHarMissing,
|
|
22
|
+
updateTimeout,
|
|
23
|
+
update,
|
|
24
|
+
url,
|
|
25
|
+
zip,
|
|
26
|
+
});
|
|
27
|
+
await use(!update);
|
|
28
|
+
};
|
|
29
|
+
const fixtureOptions = {
|
|
30
|
+
auto: true,
|
|
31
|
+
scope: 'test',
|
|
32
|
+
};
|
|
33
|
+
const mockNetwork = [
|
|
34
|
+
mockNetworkFixture,
|
|
35
|
+
fixtureOptions,
|
|
36
|
+
];
|
|
37
|
+
return mockNetwork;
|
|
38
|
+
}
|