@gravity-ui/playwright-tools 0.8.4 → 0.9.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/fixtures/mock-network/mock-network-fixture.d.ts +1 -1
- package/fixtures/mock-network/mock-network-fixture.js +1 -2
- package/fixtures/mock-network/types.d.ts +0 -13
- package/har/dumpsFilePathBulders.d.ts +9 -0
- package/har/dumpsFilePathBulders.js +19 -0
- package/har/index.d.ts +1 -0
- package/har/index.js +4 -1
- package/har/initDumps.d.ts +1 -14
- package/har/initDumps.js +3 -22
- package/package.json +1 -1
|
@@ -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,
|
|
3
|
+
export declare function mockNetworkFixtureBuilder({ shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip, url: urlMatcherBuilder, dumpsFilePath, ...harPatcherParams }: MockNetworkFixtureBuilderParams): [TestFixture<boolean, PlaywrightTestArgs & PlaywrightTestOptions>, {
|
|
4
4
|
auto: boolean;
|
|
5
5
|
scope: "test";
|
|
6
6
|
}];
|
|
@@ -3,7 +3,7 @@ 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,
|
|
6
|
+
function mockNetworkFixtureBuilder({ shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip = true, url: urlMatcherBuilder, dumpsFilePath, ...harPatcherParams }) {
|
|
7
7
|
const mockNetworkFixture = async ({ baseURL: rawBaseURL, page }, use, testInfo) => {
|
|
8
8
|
if (!rawBaseURL) {
|
|
9
9
|
throw new Error('baseURL should be specified in playwright config');
|
|
@@ -16,7 +16,6 @@ function mockNetworkFixtureBuilder({ shouldUpdate, forceUpdateIfHarMissing, upda
|
|
|
16
16
|
const update = Boolean(shouldUpdate);
|
|
17
17
|
const url = urlMatcherBuilder(baseURL);
|
|
18
18
|
await (0, har_1.initDumps)(page, testInfo, {
|
|
19
|
-
dumpsPath,
|
|
20
19
|
dumpsFilePath,
|
|
21
20
|
forceUpdateIfHarMissing,
|
|
22
21
|
updateTimeout,
|
|
@@ -27,29 +27,16 @@ export type MockNetworkFixtureBuilderParams = {
|
|
|
27
27
|
* @returns string | RegExp Regular expression prepared template; Glob or RegExp.
|
|
28
28
|
*/
|
|
29
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
30
|
/**
|
|
42
31
|
* Custom path to the dump file. Overrides the path generated by dumpsPath.
|
|
43
32
|
* @param params Parameters for constructing a path:
|
|
44
33
|
* @param params.testInfo TestInfo information about the current test
|
|
45
|
-
* @param params.slug test slug
|
|
46
34
|
* @param params.zip Flag to use zip archive for .har
|
|
47
35
|
*
|
|
48
36
|
* @returns string path to dump file
|
|
49
37
|
*/
|
|
50
38
|
dumpsFilePath?: (params: {
|
|
51
39
|
testInfo: TestInfo;
|
|
52
|
-
slug: string;
|
|
53
40
|
zip: boolean;
|
|
54
41
|
}) => string;
|
|
55
42
|
/**
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TestInfo } from '@playwright/test';
|
|
2
|
+
export declare function defaultDumpsFilePathBuilder({ testInfo, zip, }: {
|
|
3
|
+
testInfo: TestInfo;
|
|
4
|
+
zip: boolean;
|
|
5
|
+
}): string;
|
|
6
|
+
export declare function dumpsPathBuldeWithSlugBuilder({ testInfo, zip, }: {
|
|
7
|
+
testInfo: TestInfo;
|
|
8
|
+
zip: boolean;
|
|
9
|
+
}): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultDumpsFilePathBuilder = defaultDumpsFilePathBuilder;
|
|
4
|
+
exports.dumpsPathBuldeWithSlugBuilder = dumpsPathBuldeWithSlugBuilder;
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
function defaultDumpsFilePathBuilder({ testInfo, zip, }) {
|
|
7
|
+
const filePath = testInfo.snapshotPath(testInfo.titlePath
|
|
8
|
+
.slice(1)
|
|
9
|
+
.join('-')
|
|
10
|
+
.replace(/ /g, '-')
|
|
11
|
+
.replace(/[^a-zA-Z0-9\-_]/g, ''));
|
|
12
|
+
return zip ? `${filePath}.zip` : `${filePath}.har`;
|
|
13
|
+
}
|
|
14
|
+
// previous implementation, includes slug in the path
|
|
15
|
+
function dumpsPathBuldeWithSlugBuilder({ testInfo, zip, }) {
|
|
16
|
+
const slug = (0, utils_1.extractTestSlug)(testInfo.title, true);
|
|
17
|
+
const filePath = testInfo.snapshotPath('').replace(/-snapshots\/[^/]+$/, '-data/' + slug);
|
|
18
|
+
return zip ? `${filePath}.zip` : `${filePath}.har`;
|
|
19
|
+
}
|
package/har/index.d.ts
CHANGED
|
@@ -11,3 +11,4 @@ export { initDumps } from './initDumps';
|
|
|
11
11
|
export { replaceBaseUrlInEntry } from './replaceBaseUrlInEntry';
|
|
12
12
|
export { setExtraHash } from './setExtraHash';
|
|
13
13
|
export type { HARFile, Entry } from './types';
|
|
14
|
+
export { defaultDumpsFilePathBuilder, dumpsPathBuldeWithSlugBuilder } from './dumpsFilePathBulders';
|
package/har/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setExtraHash = exports.replaceBaseUrlInEntry = exports.initDumps = exports.clearHeaders = exports.addFlushTransform = exports.addHarRecorderTransform = exports.addHarOpenTransform = exports.addHarLookupTransform = void 0;
|
|
3
|
+
exports.dumpsPathBuldeWithSlugBuilder = exports.defaultDumpsFilePathBuilder = exports.setExtraHash = exports.replaceBaseUrlInEntry = exports.initDumps = exports.clearHeaders = exports.addFlushTransform = exports.addHarRecorderTransform = exports.addHarOpenTransform = exports.addHarLookupTransform = void 0;
|
|
4
4
|
var addHarLookupTransform_1 = require("./addHarLookupTransform");
|
|
5
5
|
Object.defineProperty(exports, "addHarLookupTransform", { enumerable: true, get: function () { return addHarLookupTransform_1.addHarLookupTransform; } });
|
|
6
6
|
var addHarOpenTransform_1 = require("./addHarOpenTransform");
|
|
@@ -17,3 +17,6 @@ var replaceBaseUrlInEntry_1 = require("./replaceBaseUrlInEntry");
|
|
|
17
17
|
Object.defineProperty(exports, "replaceBaseUrlInEntry", { enumerable: true, get: function () { return replaceBaseUrlInEntry_1.replaceBaseUrlInEntry; } });
|
|
18
18
|
var setExtraHash_1 = require("./setExtraHash");
|
|
19
19
|
Object.defineProperty(exports, "setExtraHash", { enumerable: true, get: function () { return setExtraHash_1.setExtraHash; } });
|
|
20
|
+
var dumpsFilePathBulders_1 = require("./dumpsFilePathBulders");
|
|
21
|
+
Object.defineProperty(exports, "defaultDumpsFilePathBuilder", { enumerable: true, get: function () { return dumpsFilePathBulders_1.defaultDumpsFilePathBuilder; } });
|
|
22
|
+
Object.defineProperty(exports, "dumpsPathBuldeWithSlugBuilder", { enumerable: true, get: function () { return dumpsFilePathBulders_1.dumpsPathBuldeWithSlugBuilder; } });
|
package/har/initDumps.d.ts
CHANGED
|
@@ -34,33 +34,20 @@ export type InitDumpsOptions = {
|
|
|
34
34
|
* @defaultValue `true`
|
|
35
35
|
*/
|
|
36
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
37
|
/**
|
|
49
38
|
* Custom path to the dump file. Overrides the path generated by dumpsPath.
|
|
50
39
|
* @param params Parameters for constructing a path:
|
|
51
40
|
* @param params.testInfo TestInfo information about the current test
|
|
52
|
-
* @param params.slug test slug
|
|
53
41
|
* @param params.zip Flag to use zip archive for .har
|
|
54
42
|
*
|
|
55
43
|
* @returns string path to dump file
|
|
56
44
|
*/
|
|
57
45
|
dumpsFilePath?: (params: {
|
|
58
46
|
testInfo: TestInfo;
|
|
59
|
-
slug: string;
|
|
60
47
|
zip: boolean;
|
|
61
48
|
}) => string;
|
|
62
49
|
};
|
|
63
50
|
/**
|
|
64
51
|
* Makes the necessary preparations for saving query dumps
|
|
65
52
|
*/
|
|
66
|
-
export declare function initDumps(page: Page, testInfo: TestInfo, {
|
|
53
|
+
export declare function initDumps(page: Page, testInfo: TestInfo, { dumpsFilePath: dumpsFilePathBuilder, rootPath, forceUpdateIfHarMissing, updateTimeout, notFound, url, zip, update, }?: InitDumpsOptions): Promise<void>;
|
package/har/initDumps.js
CHANGED
|
@@ -3,29 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.initDumps = initDumps;
|
|
4
4
|
const promises_1 = require("node:fs/promises");
|
|
5
5
|
const node_path_1 = require("node:path");
|
|
6
|
-
const
|
|
7
|
-
const extractTestSlug_1 = require("../utils/extractTestSlug");
|
|
6
|
+
const dumpsFilePathBulders_1 = require("./dumpsFilePathBulders");
|
|
8
7
|
/**
|
|
9
8
|
* Makes the necessary preparations for saving query dumps
|
|
10
9
|
*/
|
|
11
|
-
async function initDumps(page, testInfo, {
|
|
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
|
-
}
|
|
10
|
+
async function initDumps(page, testInfo, { dumpsFilePath: dumpsFilePathBuilder = dumpsFilePathBulders_1.defaultDumpsFilePathBuilder, rootPath, forceUpdateIfHarMissing = false, updateTimeout, notFound = 'abort', url, zip = true, update = false, } = {}) {
|
|
21
11
|
let harPath;
|
|
22
|
-
|
|
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
|
-
}
|
|
12
|
+
harPath = dumpsFilePathBuilder({ testInfo, zip });
|
|
29
13
|
if (rootPath) {
|
|
30
14
|
harPath = (0, node_path_1.relative)(rootPath, harPath);
|
|
31
15
|
}
|
|
@@ -49,6 +33,3 @@ async function initDumps(page, testInfo, { dumpsPath: dumpsPathBuilder = default
|
|
|
49
33
|
url,
|
|
50
34
|
});
|
|
51
35
|
}
|
|
52
|
-
function defaultPathBuilder(testInfo, slug) {
|
|
53
|
-
return testInfo.snapshotPath('').replace(/-snapshots\/[^/]+$/, '-data/' + slug);
|
|
54
|
-
}
|