@gravity-ui/playwright-tools 0.9.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
A library of additional utilities for writing tests using Playwright Test.
|
|
4
4
|
|
|
5
5
|
```
|
|
6
|
-
npm i -D playwright-tools
|
|
6
|
+
npm i -D @gravity-ui/playwright-tools
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
The package contains several subdirectories with utilities for different purposes. You should import from these subdirectories, for example:
|
|
@@ -27,16 +27,20 @@ function harPatcher({ baseURL, headersToRemove: additionalHeadersToRemove = [],
|
|
|
27
27
|
removeSetCookieFor: setCookieToRemove,
|
|
28
28
|
});
|
|
29
29
|
(0, har_1.replaceBaseUrlInEntry)(entry, baseURL, baseUrlPLaceholder);
|
|
30
|
-
onHarEntryWillWrite?.(entry);
|
|
30
|
+
onHarEntryWillWrite?.(entry, baseURL);
|
|
31
31
|
});
|
|
32
32
|
(0, har_1.addHarOpenTransform)((harFile) => {
|
|
33
33
|
const entries = harFile.log.entries;
|
|
34
34
|
for (const entry of entries) {
|
|
35
35
|
(0, har_1.replaceBaseUrlInEntry)(entry, baseUrlPLaceholder, baseURL);
|
|
36
|
-
onHarEntryWillRead?.(entry);
|
|
36
|
+
onHarEntryWillRead?.(entry, baseURL);
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
|
-
(0, har_1.addHarLookupTransform)(onTransformHarLookupParams
|
|
39
|
+
(0, har_1.addHarLookupTransform)(onTransformHarLookupParams
|
|
40
|
+
? (params) => onTransformHarLookupParams(params, baseURL)
|
|
41
|
+
: undefined, onTransformHarLookupResult
|
|
42
|
+
? (result, params) => onTransformHarLookupResult(result, params, baseURL)
|
|
43
|
+
: undefined);
|
|
40
44
|
// Filter out canceled requests before writing to har file
|
|
41
45
|
(0, har_1.addFlushTransform)((entries) => entries.filter((entry) => entry.time !== -1));
|
|
42
46
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PlaywrightTestArgs, PlaywrightTestOptions, TestFixture } from '@playwright/test';
|
|
2
2
|
import type { MockNetworkFixtureBuilderParams } from './types';
|
|
3
|
-
export declare function mockNetworkFixtureBuilder({ shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip, url: urlMatcherBuilder, dumpsFilePath, ...harPatcherParams }: MockNetworkFixtureBuilderParams): [TestFixture<boolean,
|
|
3
|
+
export declare function mockNetworkFixtureBuilder<TestArgs extends PlaywrightTestArgs & PlaywrightTestOptions = PlaywrightTestArgs & PlaywrightTestOptions>({ shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip, url: urlMatcherBuilder, dumpsFilePath, enabled, ...harPatcherParams }: MockNetworkFixtureBuilderParams<TestArgs>): [TestFixture<boolean, TestArgs>, {
|
|
4
4
|
auto: boolean;
|
|
5
5
|
scope: "test";
|
|
6
6
|
}];
|
|
@@ -3,8 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mockNetworkFixtureBuilder = mockNetworkFixtureBuilder;
|
|
4
4
|
const har_1 = require("../../har");
|
|
5
5
|
const har_patcher_1 = require("./har-patcher");
|
|
6
|
-
function mockNetworkFixtureBuilder({ shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip = true, url: urlMatcherBuilder, dumpsFilePath, ...harPatcherParams }) {
|
|
7
|
-
const mockNetworkFixture = async (
|
|
6
|
+
function mockNetworkFixtureBuilder({ shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip = true, url: urlMatcherBuilder, dumpsFilePath, enabled, ...harPatcherParams }) {
|
|
7
|
+
const mockNetworkFixture = async (options, use, testInfo) => {
|
|
8
|
+
const { baseURL: rawBaseURL, page } = options;
|
|
9
|
+
if (enabled && !enabled(options)) {
|
|
10
|
+
await use(false);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
8
13
|
if (!rawBaseURL) {
|
|
9
14
|
throw new Error('baseURL should be specified in playwright config');
|
|
10
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { TestInfo } from '@playwright/test';
|
|
1
|
+
import type { PlaywrightTestArgs, PlaywrightTestOptions, TestInfo } from '@playwright/test';
|
|
2
2
|
import type { Entry, HarLookupParamsTransformFunction, HarLookupResultTransformFunction } from '../../har';
|
|
3
|
-
export type MockNetworkFixtureBuilderParams = {
|
|
3
|
+
export type MockNetworkFixtureBuilderParams<TestArgs extends PlaywrightTestArgs & PlaywrightTestOptions = PlaywrightTestArgs & PlaywrightTestOptions> = {
|
|
4
4
|
/**
|
|
5
5
|
* Update dumps or not
|
|
6
6
|
* @defaultValue `false`
|
|
@@ -53,21 +53,34 @@ export type MockNetworkFixtureBuilderParams = {
|
|
|
53
53
|
* Callback for processing requests and responses by saving to .har. Useful for various post-processing of requests: cleaning, changing format, etc.
|
|
54
54
|
* By default, sensitive headers are removed + the base url of the request is changed to a stub
|
|
55
55
|
* @param entry The entry in .har that will be written
|
|
56
|
+
* @param baseURL The base URL of the test
|
|
56
57
|
*/
|
|
57
|
-
onHarEntryWillWrite?: (entry: Entry) => void;
|
|
58
|
+
onHarEntryWillWrite?: (entry: Entry, baseURL: string) => void;
|
|
58
59
|
/**
|
|
59
60
|
* Callback to process requests and responses written in .har before they are used
|
|
60
61
|
* Useful for reverting changes made in onHarEntryWillWrite
|
|
61
62
|
* By default, the base url templates are replaced with the actual baseUrl of the test
|
|
62
63
|
* @param entry The entry in .har that will be used
|
|
64
|
+
* @param baseURL The base URL of the test
|
|
63
65
|
*/
|
|
64
|
-
onHarEntryWillRead?: (entry: Entry) => void;
|
|
66
|
+
onHarEntryWillRead?: (entry: Entry, baseURL: string) => void;
|
|
65
67
|
/**
|
|
66
68
|
* Callback for changing search parameters of queries in .har
|
|
69
|
+
* @param params The lookup parameters
|
|
70
|
+
* @param baseURL The base URL of the test
|
|
67
71
|
*/
|
|
68
|
-
onTransformHarLookupParams?: HarLookupParamsTransformFunction
|
|
72
|
+
onTransformHarLookupParams?: (params: Parameters<HarLookupParamsTransformFunction>[0], baseURL: string) => ReturnType<HarLookupParamsTransformFunction>;
|
|
69
73
|
/**
|
|
70
74
|
* Callback for transforming the search query result into .har
|
|
75
|
+
* @param result The lookup result
|
|
76
|
+
* @param params The lookup parameters
|
|
77
|
+
* @param baseURL The base URL of the test
|
|
71
78
|
*/
|
|
72
|
-
onTransformHarLookupResult?: HarLookupResultTransformFunction
|
|
79
|
+
onTransformHarLookupResult?: (result: Parameters<HarLookupResultTransformFunction>[0], params: Parameters<HarLookupResultTransformFunction>[1], baseURL: string) => ReturnType<HarLookupResultTransformFunction>;
|
|
80
|
+
/**
|
|
81
|
+
* Function to conditionally enable or disable the mock network fixture
|
|
82
|
+
* @param options Test fixture arguments and options (includes custom test args if extended)
|
|
83
|
+
* @returns `true` to enable the fixture, `false` to disable it
|
|
84
|
+
*/
|
|
85
|
+
enabled?: (options: TestArgs) => boolean;
|
|
73
86
|
};
|