@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,86 @@
|
|
|
1
|
+
import type { TestInfo } from '@playwright/test';
|
|
2
|
+
import type { Entry, HarLookupParamsTransformFunction, HarLookupResultTransformFunction } from '../../har';
|
|
3
|
+
export type MockNetworkFixtureBuilderParams = {
|
|
4
|
+
/**
|
|
5
|
+
* Update dumps or not
|
|
6
|
+
* @defaultValue `false`
|
|
7
|
+
*/
|
|
8
|
+
shouldUpdate: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Always update dumps if they are missing
|
|
11
|
+
* @defaultValue `false`
|
|
12
|
+
*/
|
|
13
|
+
forceUpdateIfHarMissing?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Custom timeout for updating tests. Milliseconds.
|
|
16
|
+
* Useful for long updates
|
|
17
|
+
*/
|
|
18
|
+
updateTimeout?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Archive dumps
|
|
21
|
+
* @defaultValue true
|
|
22
|
+
*/
|
|
23
|
+
zip?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
*The address pattern of requests that will be written to .har. Inappropriate requests will be skipped.
|
|
26
|
+
* @param baseURL string The base address of the page.
|
|
27
|
+
* @returns string | RegExp Regular expression prepared template; Glob or RegExp.
|
|
28
|
+
*/
|
|
29
|
+
url: (baseURL: string) => string | RegExp;
|
|
30
|
+
/**
|
|
31
|
+
* User path to the directory with dumps. By default, the path is calculated as
|
|
32
|
+
* testInfo.snapshotPath('').replace(/-snapshots\/[^/]+$/, '-data/' + slug)
|
|
33
|
+
* @param testInfo TestInfo information about the current test
|
|
34
|
+
* @param slug Test slug
|
|
35
|
+
*
|
|
36
|
+
* @returns string path to the directory with dumps
|
|
37
|
+
*
|
|
38
|
+
* @deprecated use dumpsFilePath.
|
|
39
|
+
*/
|
|
40
|
+
dumpsPath?: (testInfo: TestInfo, slug: string) => string;
|
|
41
|
+
/**
|
|
42
|
+
* Custom path to the dump file. Overrides the path generated by dumpsPath.
|
|
43
|
+
* @param params Parameters for constructing a path:
|
|
44
|
+
* @param params.testInfo TestInfo information about the current test
|
|
45
|
+
* @param params.slug test slug
|
|
46
|
+
* @param params.zip Flag to use zip archive for .har
|
|
47
|
+
*
|
|
48
|
+
* @returns string path to dump file
|
|
49
|
+
*/
|
|
50
|
+
dumpsFilePath?: (params: {
|
|
51
|
+
testInfo: TestInfo;
|
|
52
|
+
slug: string;
|
|
53
|
+
zip: boolean;
|
|
54
|
+
}) => string;
|
|
55
|
+
/**
|
|
56
|
+
* Additional headers that will be removed before writing the request to .har
|
|
57
|
+
* By default, the following headers are removed: `cookie`, `x-csrf-token`, `content-security-policy`, `Session_id`
|
|
58
|
+
*/
|
|
59
|
+
headersToRemove?: string[];
|
|
60
|
+
/**
|
|
61
|
+
* Additional set-cookie values for which set-cookie headers will be removed
|
|
62
|
+
* By default, set-cookies are removed for the following values: with`CSRF-TOKEN`
|
|
63
|
+
*/
|
|
64
|
+
setCookieToRemove?: string[];
|
|
65
|
+
/**
|
|
66
|
+
* Callback for processing requests and responses by saving to .har. Useful for various post-processing of requests: cleaning, changing format, etc.
|
|
67
|
+
* By default, sensitive headers are removed + the base url of the request is changed to a stub
|
|
68
|
+
* @param entry The entry in .har that will be written
|
|
69
|
+
*/
|
|
70
|
+
onHarEntryWillWrite?: (entry: Entry) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Callback to process requests and responses written in .har before they are used
|
|
73
|
+
* Useful for reverting changes made in onHarEntryWillWrite
|
|
74
|
+
* By default, the base url templates are replaced with the actual baseUrl of the test
|
|
75
|
+
* @param entry The entry in .har that will be used
|
|
76
|
+
*/
|
|
77
|
+
onHarEntryWillRead?: (entry: Entry) => void;
|
|
78
|
+
/**
|
|
79
|
+
* Callback for changing search parameters of queries in .har
|
|
80
|
+
*/
|
|
81
|
+
onTransformHarLookupParams?: HarLookupParamsTransformFunction;
|
|
82
|
+
/**
|
|
83
|
+
* Callback for transforming the search query result into .har
|
|
84
|
+
*/
|
|
85
|
+
onTransformHarLookupResult?: HarLookupResultTransformFunction;
|
|
86
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TestFixture } from '@playwright/test';
|
|
2
|
+
import type { PlaywrightTestArgsBase } from './types';
|
|
3
|
+
export type TestSlugResult = string;
|
|
4
|
+
declare const testSlugValue: TestFixture<TestSlugResult, PlaywrightTestArgsBase>;
|
|
5
|
+
declare const fixtureOptions: {
|
|
6
|
+
auto: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Automatically sets and adds the current slug value for the test to the test fixtures
|
|
10
|
+
*/
|
|
11
|
+
export declare const testSlug: [typeof testSlugValue, typeof fixtureOptions];
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testSlug = void 0;
|
|
4
|
+
const actions_1 = require("../actions");
|
|
5
|
+
const testSlugValue = async ({ page }, use, testInfo) => {
|
|
6
|
+
(0, actions_1.setTestSlug)(page, testInfo.title, true);
|
|
7
|
+
const slug = (0, actions_1.getTestSlug)(page);
|
|
8
|
+
await use(slug);
|
|
9
|
+
};
|
|
10
|
+
const fixtureOptions = {
|
|
11
|
+
auto: true,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Automatically sets and adds the current slug value for the test to the test fixtures
|
|
15
|
+
*/
|
|
16
|
+
exports.testSlug = [
|
|
17
|
+
testSlugValue,
|
|
18
|
+
fixtureOptions,
|
|
19
|
+
];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions } from '@playwright/test';
|
|
2
|
+
export type AllPlaywrightTestFixtures = PlaywrightTestArgs & PlaywrightTestOptions;
|
|
3
|
+
export type AllPlaywrightWorkerFixtures = PlaywrightWorkerArgs & PlaywrightWorkerOptions;
|
|
4
|
+
export type PlaywrightTestArgsBase = AllPlaywrightTestFixtures & AllPlaywrightWorkerFixtures;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LocalUtilsHarLookupParams, LocalUtilsHarLookupResult } from './types';
|
|
2
|
+
export type HarLookupParamsTransformFunction = (params: LocalUtilsHarLookupParams) => LocalUtilsHarLookupParams;
|
|
3
|
+
export type HarLookupResultTransformFunction = (result: LocalUtilsHarLookupResult, params: LocalUtilsHarLookupParams) => LocalUtilsHarLookupResult | Promise<LocalUtilsHarLookupResult>;
|
|
4
|
+
/**
|
|
5
|
+
* Allows you to make modifications at the stage of searching for a record in the dump that matches the request
|
|
6
|
+
* @param transformParams Function for changing the parameters on the basis of which the search will be performed
|
|
7
|
+
* @param transformResult Function for changing the search result (here you can change the parameters of the found answer, for example its body)
|
|
8
|
+
*/
|
|
9
|
+
export declare function addHarLookupTransform(transformParams?: HarLookupParamsTransformFunction, transformResult?: HarLookupResultTransformFunction): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addHarLookupTransform = addHarLookupTransform;
|
|
4
|
+
const getPlaywrightCoreModule_1 = require("./getPlaywrightCoreModule");
|
|
5
|
+
function wrapLocalUtilsDispatcherMethods(
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
LocalUtilsDispatcher, transformParams, transformResult) {
|
|
8
|
+
const originalHarLookup = LocalUtilsDispatcher.prototype.harLookup;
|
|
9
|
+
if (originalHarLookup) {
|
|
10
|
+
// eslint-disable-next-line no-param-reassign
|
|
11
|
+
LocalUtilsDispatcher.prototype.harLookup = async function harLookup(params, metadata, ...rest) {
|
|
12
|
+
if (transformParams) {
|
|
13
|
+
// eslint-disable-next-line no-param-reassign
|
|
14
|
+
params = transformParams(params);
|
|
15
|
+
}
|
|
16
|
+
let result = await originalHarLookup.call(this, params, metadata, ...rest);
|
|
17
|
+
if (transformResult) {
|
|
18
|
+
result = transformResult(result, params);
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error('Can\'t find "harLookup" method in "LocalUtilsDispatcher" class.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
let patchInited = false;
|
|
28
|
+
function initLocalUtilsDispatcherPatch(transformParams, transformResult) {
|
|
29
|
+
patchInited = true;
|
|
30
|
+
const modules = (0, getPlaywrightCoreModule_1.getPlaywrightCoreModule)('lib/server/dispatchers/localUtilsDispatcher');
|
|
31
|
+
for (const module of modules) {
|
|
32
|
+
wrapLocalUtilsDispatcherMethods(module.LocalUtilsDispatcher, transformParams, transformResult);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Allows you to make modifications at the stage of searching for a record in the dump that matches the request
|
|
37
|
+
* @param transformParams Function for changing the parameters on the basis of which the search will be performed
|
|
38
|
+
* @param transformResult Function for changing the search result (here you can change the parameters of the found answer, for example its body)
|
|
39
|
+
*/
|
|
40
|
+
function addHarLookupTransform(transformParams, transformResult) {
|
|
41
|
+
if (!patchInited) {
|
|
42
|
+
initLocalUtilsDispatcherPatch(transformParams, transformResult);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HARFile } from './types';
|
|
2
|
+
export type HarTransformFunction = (harFile: HARFile) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Allows you to make changes to the JSON read from an open HAR file
|
|
5
|
+
*/
|
|
6
|
+
export declare function addHarOpenTransform(transform: HarTransformFunction): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addHarOpenTransform = addHarOpenTransform;
|
|
4
|
+
const getPlaywrightCoreModule_1 = require("./getPlaywrightCoreModule");
|
|
5
|
+
function wrapLocalUtilsDispatcherMethods(
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
LocalUtilsDispatcher, transform) {
|
|
8
|
+
const originalHarOpen = LocalUtilsDispatcher.prototype.harOpen;
|
|
9
|
+
if (originalHarOpen) {
|
|
10
|
+
// eslint-disable-next-line no-param-reassign
|
|
11
|
+
LocalUtilsDispatcher.prototype.harOpen = async function harOpen(...rest) {
|
|
12
|
+
const result = await originalHarOpen.apply(this, rest);
|
|
13
|
+
const harBackends = this._harBackends || this._harBakends;
|
|
14
|
+
const harBackend = harBackends.get(result.harId);
|
|
15
|
+
const harFile = harBackend._harFile;
|
|
16
|
+
if (harFile) {
|
|
17
|
+
transform(harFile);
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new Error('Can\'t find "harOpen" method in "LocalUtilsDispatcher" class.');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
let patchInited = false;
|
|
27
|
+
function initLocalUtilsDispatcherPatch(transform) {
|
|
28
|
+
patchInited = true;
|
|
29
|
+
const modules = (0, getPlaywrightCoreModule_1.getPlaywrightCoreModule)('lib/server/dispatchers/localUtilsDispatcher');
|
|
30
|
+
for (const module of modules) {
|
|
31
|
+
wrapLocalUtilsDispatcherMethods(module.LocalUtilsDispatcher, transform);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Allows you to make changes to the JSON read from an open HAR file
|
|
36
|
+
*/
|
|
37
|
+
function addHarOpenTransform(transform) {
|
|
38
|
+
if (!patchInited) {
|
|
39
|
+
initLocalUtilsDispatcherPatch(transform);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Entry } from './types';
|
|
2
|
+
export type EntryTransformFunction = (entry: Entry) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Allows you to make changes to the JSON that will be written to the HAR file
|
|
5
|
+
*/
|
|
6
|
+
export declare function addHarRecorderTransform(transform: EntryTransformFunction): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addHarRecorderTransform = addHarRecorderTransform;
|
|
4
|
+
const getPlaywrightCoreModule_1 = require("./getPlaywrightCoreModule");
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
function wrapHarRecorderMethods(HarRecorder, transform) {
|
|
7
|
+
const originalOnEntryFinished = HarRecorder.prototype.onEntryFinished;
|
|
8
|
+
if (originalOnEntryFinished) {
|
|
9
|
+
// eslint-disable-next-line no-param-reassign
|
|
10
|
+
HarRecorder.prototype.onEntryFinished = function onEntryFinished(entry, ...rest) {
|
|
11
|
+
if (entry) {
|
|
12
|
+
transform(entry);
|
|
13
|
+
}
|
|
14
|
+
return originalOnEntryFinished(entry, rest);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
throw new Error('Can\'t find "onEntryFinished" method in "HarRecorder" class.');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
let patchInited = false;
|
|
22
|
+
function initHarRecorderPatch(transform) {
|
|
23
|
+
patchInited = true;
|
|
24
|
+
const modules = (0, getPlaywrightCoreModule_1.getPlaywrightCoreModule)('lib/server/har/harRecorder');
|
|
25
|
+
for (const module of modules) {
|
|
26
|
+
wrapHarRecorderMethods(module.HarRecorder, transform);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Allows you to make changes to the JSON that will be written to the HAR file
|
|
31
|
+
*/
|
|
32
|
+
function addHarRecorderTransform(transform) {
|
|
33
|
+
if (!patchInited) {
|
|
34
|
+
initHarRecorderPatch(transform);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Header } from './types';
|
|
2
|
+
export type ClearHeadersOptions = {
|
|
3
|
+
removeHeaders?: Set<string>;
|
|
4
|
+
removeSetCookieFor?: Set<string>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Cleans the specified headers
|
|
8
|
+
*
|
|
9
|
+
* Convenient to use in `addHarRecorderTransform` to remove private headers and cookies.
|
|
10
|
+
*/
|
|
11
|
+
export declare function clearHeaders(headers: Header[], { removeHeaders, removeSetCookieFor }: ClearHeadersOptions): Header[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clearHeaders = clearHeaders;
|
|
4
|
+
/**
|
|
5
|
+
* Cleans the specified headers
|
|
6
|
+
*
|
|
7
|
+
* Convenient to use in `addHarRecorderTransform` to remove private headers and cookies.
|
|
8
|
+
*/
|
|
9
|
+
function clearHeaders(headers, { removeHeaders, removeSetCookieFor }) {
|
|
10
|
+
const nextHeaders = [];
|
|
11
|
+
for (const header of headers) {
|
|
12
|
+
const name = header.name.toLowerCase();
|
|
13
|
+
if (removeHeaders?.has(name)) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (name === 'set-cookie' && removeSetCookieFor) {
|
|
17
|
+
const cookieName = header.value.split('=', 1)[0];
|
|
18
|
+
if (cookieName && removeSetCookieFor.has(cookieName)) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
nextHeaders.push(header);
|
|
23
|
+
}
|
|
24
|
+
return nextHeaders;
|
|
25
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPlaywrightCoreModule = getPlaywrightCoreModule;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
/**
|
|
6
|
+
* Finds the location of the internal playwright-core module for patching
|
|
7
|
+
*/
|
|
8
|
+
function getPlaywrightCoreModule(path) {
|
|
9
|
+
let globalModule;
|
|
10
|
+
try {
|
|
11
|
+
const globalModulePath = (0, path_1.dirname)(require.resolve('playwright-core'));
|
|
12
|
+
globalModule = require((0, path_1.resolve)(globalModulePath, path));
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// Do nothing
|
|
16
|
+
}
|
|
17
|
+
let internalModule;
|
|
18
|
+
try {
|
|
19
|
+
const playwrightTestsPath = (0, path_1.dirname)(require.resolve('@playwright/test'));
|
|
20
|
+
const harRecorderPath = (0, path_1.resolve)(playwrightTestsPath, 'node_modules/playwright-core/' + path);
|
|
21
|
+
internalModule = require(harRecorderPath);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// Do nothing
|
|
25
|
+
}
|
|
26
|
+
if (!globalModule && !internalModule) {
|
|
27
|
+
throw new Error(`Can't find "playwright-core/${path}" module.`);
|
|
28
|
+
}
|
|
29
|
+
if (globalModule === internalModule) {
|
|
30
|
+
return [globalModule];
|
|
31
|
+
}
|
|
32
|
+
return [globalModule, internalModule].filter((item) => item !== undefined);
|
|
33
|
+
}
|
package/har/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type { HarLookupParamsTransformFunction, HarLookupResultTransformFunction, } from './addHarLookupTransform';
|
|
2
|
+
export { addHarLookupTransform } from './addHarLookupTransform';
|
|
3
|
+
export type { HarTransformFunction } from './addHarOpenTransform';
|
|
4
|
+
export { addHarOpenTransform } from './addHarOpenTransform';
|
|
5
|
+
export type { EntryTransformFunction } from './addHarRecorderTransform';
|
|
6
|
+
export { addHarRecorderTransform } from './addHarRecorderTransform';
|
|
7
|
+
export { clearHeaders } from './clearHeaders';
|
|
8
|
+
export { initDumps } from './initDumps';
|
|
9
|
+
export { replaceBaseUrlInEntry } from './replaceBaseUrlInEntry';
|
|
10
|
+
export { setExtraHash } from './setExtraHash';
|
|
11
|
+
export type { HARFile, Entry } from './types';
|
package/har/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setExtraHash = exports.replaceBaseUrlInEntry = exports.initDumps = exports.clearHeaders = exports.addHarRecorderTransform = exports.addHarOpenTransform = exports.addHarLookupTransform = void 0;
|
|
4
|
+
var addHarLookupTransform_1 = require("./addHarLookupTransform");
|
|
5
|
+
Object.defineProperty(exports, "addHarLookupTransform", { enumerable: true, get: function () { return addHarLookupTransform_1.addHarLookupTransform; } });
|
|
6
|
+
var addHarOpenTransform_1 = require("./addHarOpenTransform");
|
|
7
|
+
Object.defineProperty(exports, "addHarOpenTransform", { enumerable: true, get: function () { return addHarOpenTransform_1.addHarOpenTransform; } });
|
|
8
|
+
var addHarRecorderTransform_1 = require("./addHarRecorderTransform");
|
|
9
|
+
Object.defineProperty(exports, "addHarRecorderTransform", { enumerable: true, get: function () { return addHarRecorderTransform_1.addHarRecorderTransform; } });
|
|
10
|
+
var clearHeaders_1 = require("./clearHeaders");
|
|
11
|
+
Object.defineProperty(exports, "clearHeaders", { enumerable: true, get: function () { return clearHeaders_1.clearHeaders; } });
|
|
12
|
+
var initDumps_1 = require("./initDumps");
|
|
13
|
+
Object.defineProperty(exports, "initDumps", { enumerable: true, get: function () { return initDumps_1.initDumps; } });
|
|
14
|
+
var replaceBaseUrlInEntry_1 = require("./replaceBaseUrlInEntry");
|
|
15
|
+
Object.defineProperty(exports, "replaceBaseUrlInEntry", { enumerable: true, get: function () { return replaceBaseUrlInEntry_1.replaceBaseUrlInEntry; } });
|
|
16
|
+
var setExtraHash_1 = require("./setExtraHash");
|
|
17
|
+
Object.defineProperty(exports, "setExtraHash", { enumerable: true, get: function () { return setExtraHash_1.setExtraHash; } });
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Page, TestInfo } from '@playwright/test';
|
|
2
|
+
export type InitDumpsOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Path to the root directory of the project, relative to which the calculation will be made
|
|
5
|
+
* path to the dump directory (if not specified, the path is absolute)
|
|
6
|
+
*/
|
|
7
|
+
rootPath?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Mode of writing requests to a file instead of reading from it
|
|
10
|
+
* @defaultValue `false`
|
|
11
|
+
*/
|
|
12
|
+
update?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Always update dumps if they are missing
|
|
15
|
+
* @defaultValue `false`
|
|
16
|
+
*/
|
|
17
|
+
forceUpdateIfHarMissing?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Custom timeout for updating tests. Milliseconds.
|
|
20
|
+
* Useful for long updates
|
|
21
|
+
*/
|
|
22
|
+
updateTimeout?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Operating mode for requests not found in the archive
|
|
25
|
+
* @defaultValue `'abort'`
|
|
26
|
+
*/
|
|
27
|
+
notFound?: 'abort' | 'fallback';
|
|
28
|
+
/**
|
|
29
|
+
* The address template of the requests to be processed
|
|
30
|
+
*/
|
|
31
|
+
url?: string | RegExp;
|
|
32
|
+
/**
|
|
33
|
+
* Pack the result into an archive
|
|
34
|
+
* @defaultValue `true`
|
|
35
|
+
*/
|
|
36
|
+
zip?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* User path to the directory with dumps. By default, the path is calculated as
|
|
39
|
+
* testInfo.snapshotPath('').replace(/-snapshots\/[^/]+$/, '-data/' + slug)
|
|
40
|
+
* @param testInfo TestInfo information about the current test
|
|
41
|
+
* @param slug test slug
|
|
42
|
+
*
|
|
43
|
+
* @returns string path to the directory with dumps
|
|
44
|
+
*
|
|
45
|
+
* @deprecated use dumpsFilePath.
|
|
46
|
+
*/
|
|
47
|
+
dumpsPath?: (testInfo: TestInfo, slug: string) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Custom path to the dump file. Overrides the path generated by dumpsPath.
|
|
50
|
+
* @param params Parameters for constructing a path:
|
|
51
|
+
* @param params.testInfo TestInfo information about the current test
|
|
52
|
+
* @param params.slug test slug
|
|
53
|
+
* @param params.zip Flag to use zip archive for .har
|
|
54
|
+
*
|
|
55
|
+
* @returns string path to dump file
|
|
56
|
+
*/
|
|
57
|
+
dumpsFilePath?: (params: {
|
|
58
|
+
testInfo: TestInfo;
|
|
59
|
+
slug: string;
|
|
60
|
+
zip: boolean;
|
|
61
|
+
}) => string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Makes the necessary preparations for saving query dumps
|
|
65
|
+
*/
|
|
66
|
+
export declare function initDumps(page: Page, testInfo: TestInfo, { dumpsPath: dumpsPathBuilder, dumpsFilePath: dumpsFilePathBuilder, rootPath, forceUpdateIfHarMissing, updateTimeout, notFound, url, zip, update, }?: InitDumpsOptions): Promise<void>;
|
package/har/initDumps.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initDumps = initDumps;
|
|
4
|
+
const promises_1 = require("node:fs/promises");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const actions_1 = require("../actions");
|
|
7
|
+
const extractTestSlug_1 = require("../utils/extractTestSlug");
|
|
8
|
+
/**
|
|
9
|
+
* Makes the necessary preparations for saving query dumps
|
|
10
|
+
*/
|
|
11
|
+
async function initDumps(page, testInfo, { dumpsPath: dumpsPathBuilder = defaultPathBuilder, dumpsFilePath: dumpsFilePathBuilder, rootPath, forceUpdateIfHarMissing = false, updateTimeout, notFound = 'abort', url, zip = true, update = false, } = {}) {
|
|
12
|
+
let slug;
|
|
13
|
+
try {
|
|
14
|
+
slug = (0, actions_1.getTestSlug)(page);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
console.warn(error);
|
|
18
|
+
// Backward compatibility
|
|
19
|
+
slug = (0, extractTestSlug_1.extractTestSlug)(testInfo.title, true);
|
|
20
|
+
}
|
|
21
|
+
let harPath;
|
|
22
|
+
if (dumpsFilePathBuilder) {
|
|
23
|
+
harPath = dumpsFilePathBuilder({ testInfo, slug, zip });
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const dumpsPath = dumpsPathBuilder(testInfo, slug);
|
|
27
|
+
harPath = (0, node_path_1.join)(dumpsPath, zip ? 'har.zip' : 'har.har');
|
|
28
|
+
}
|
|
29
|
+
if (rootPath) {
|
|
30
|
+
harPath = (0, node_path_1.relative)(rootPath, harPath);
|
|
31
|
+
}
|
|
32
|
+
harPath = (0, node_path_1.resolve)(harPath);
|
|
33
|
+
if (forceUpdateIfHarMissing) {
|
|
34
|
+
try {
|
|
35
|
+
await (0, promises_1.access)(harPath);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// eslint-disable-next-line no-param-reassign
|
|
39
|
+
update = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (update && updateTimeout) {
|
|
43
|
+
testInfo.setTimeout(updateTimeout);
|
|
44
|
+
}
|
|
45
|
+
console.info(update ? 'Write requests to' : 'Read requests from', harPath);
|
|
46
|
+
await page.context().routeFromHAR(harPath, {
|
|
47
|
+
update,
|
|
48
|
+
notFound,
|
|
49
|
+
url,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function defaultPathBuilder(testInfo, slug) {
|
|
53
|
+
return testInfo.snapshotPath('').replace(/-snapshots\/[^/]+$/, '-data/' + slug);
|
|
54
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Entry } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Replaces the base URL in the HAR file request entry
|
|
4
|
+
*
|
|
5
|
+
* @param entry ЗRecording from HAR file
|
|
6
|
+
* @param fromUrl URL to replace
|
|
7
|
+
* @param toUrl URL to replace with
|
|
8
|
+
*/
|
|
9
|
+
export declare function replaceBaseUrlInEntry(entry: Entry, fromUrl: string, toUrl: string): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.replaceBaseUrlInEntry = replaceBaseUrlInEntry;
|
|
7
|
+
const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
|
|
8
|
+
/**
|
|
9
|
+
* Replaces the base URL in the HAR file request entry
|
|
10
|
+
*
|
|
11
|
+
* @param entry ЗRecording from HAR file
|
|
12
|
+
* @param fromUrl URL to replace
|
|
13
|
+
* @param toUrl URL to replace with
|
|
14
|
+
*/
|
|
15
|
+
function replaceBaseUrlInEntry(entry, fromUrl, toUrl) {
|
|
16
|
+
const fromUrlRegExp = new RegExp((0, escape_string_regexp_1.default)(fromUrl), 'g');
|
|
17
|
+
// eslint-disable-next-line no-param-reassign
|
|
18
|
+
entry.request.url = entry.request.url.replace(fromUrl, toUrl);
|
|
19
|
+
if (entry.response.redirectURL) {
|
|
20
|
+
entry.response.redirectURL.replace(fromUrl, toUrl);
|
|
21
|
+
}
|
|
22
|
+
const replaceBaseUrlInHeaders = (headers) => {
|
|
23
|
+
for (const header of headers) {
|
|
24
|
+
header.value = header.value.replace(fromUrlRegExp, toUrl);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
replaceBaseUrlInHeaders(entry.request.headers);
|
|
28
|
+
replaceBaseUrlInHeaders(entry.response.headers);
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setExtraHash = setExtraHash;
|
|
4
|
+
const addExtraHttpHeader_1 = require("../actions/addExtraHttpHeader");
|
|
5
|
+
const removeExtraHttpHeader_1 = require("../actions/removeExtraHttpHeader");
|
|
6
|
+
const HEADER_NAME = 'x-tests-extra-hash';
|
|
7
|
+
/**
|
|
8
|
+
* Sets a header that can help differentiate requests with the same parameters.
|
|
9
|
+
*/
|
|
10
|
+
async function setExtraHash(page, value) {
|
|
11
|
+
const context = page.context();
|
|
12
|
+
if (value === null) {
|
|
13
|
+
await (0, removeExtraHttpHeader_1.removeExtraHttpHeader)(context, HEADER_NAME);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
await (0, addExtraHttpHeader_1.addExtraHttpHeader)(context, HEADER_NAME, value);
|
|
17
|
+
}
|
|
18
|
+
}
|