@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 YANDEX LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BrowserContext } from '@playwright/test';
|
|
2
|
+
/**
|
|
3
|
+
* Add header to internal extraHttpHeaders list and extra HTTP headers in browser context
|
|
4
|
+
*/
|
|
5
|
+
export declare function addExtraHttpHeader(browserContext: BrowserContext, headerName: string, headerValue: string): Promise<void>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addExtraHttpHeader = addExtraHttpHeader;
|
|
4
|
+
const extraHttpHeaders_1 = require("../data/extraHttpHeaders");
|
|
5
|
+
/**
|
|
6
|
+
* Add header to internal extraHttpHeaders list and extra HTTP headers in browser context
|
|
7
|
+
*/
|
|
8
|
+
async function addExtraHttpHeader(browserContext, headerName, headerValue) {
|
|
9
|
+
if (!extraHttpHeaders_1.extraHttpHeaders.has(browserContext)) {
|
|
10
|
+
extraHttpHeaders_1.extraHttpHeaders.set(browserContext, new Map());
|
|
11
|
+
}
|
|
12
|
+
const headers = extraHttpHeaders_1.extraHttpHeaders.get(browserContext);
|
|
13
|
+
headers.set(headerName.toLowerCase(), headerValue);
|
|
14
|
+
await browserContext.setExtraHTTPHeaders(Object.fromEntries(headers.entries()));
|
|
15
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BrowserContext } from '@playwright/test';
|
|
2
|
+
/**
|
|
3
|
+
* Add headers to internal extraHttpHeaders list and extra HTTP headers in browser context
|
|
4
|
+
*/
|
|
5
|
+
export declare function addExtraHttpHeaders(browserContext: BrowserContext, additionalHeaders: Record<string, string>): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addExtraHttpHeaders = addExtraHttpHeaders;
|
|
4
|
+
const extraHttpHeaders_1 = require("../data/extraHttpHeaders");
|
|
5
|
+
/**
|
|
6
|
+
* Add headers to internal extraHttpHeaders list and extra HTTP headers in browser context
|
|
7
|
+
*/
|
|
8
|
+
async function addExtraHttpHeaders(browserContext, additionalHeaders) {
|
|
9
|
+
if (!extraHttpHeaders_1.extraHttpHeaders.has(browserContext)) {
|
|
10
|
+
extraHttpHeaders_1.extraHttpHeaders.set(browserContext, new Map());
|
|
11
|
+
}
|
|
12
|
+
const headers = extraHttpHeaders_1.extraHttpHeaders.get(browserContext);
|
|
13
|
+
for (const [headerName, headerValue] of Object.entries(additionalHeaders)) {
|
|
14
|
+
headers.set(headerName.toLowerCase(), headerValue);
|
|
15
|
+
}
|
|
16
|
+
await browserContext.setExtraHTTPHeaders(Object.fromEntries(headers.entries()));
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Locator } from '@playwright/test';
|
|
2
|
+
/**
|
|
3
|
+
* Waits for all elements matching the locator to hide
|
|
4
|
+
*
|
|
5
|
+
* Optionally checks that the element was initially visible (wait for it to appear).
|
|
6
|
+
* If the element has not become visible after the timeout (300 ms by default),
|
|
7
|
+
* then it is considered that it managed to hide before that, this does not cause an error.
|
|
8
|
+
*
|
|
9
|
+
* @param locator Locator of elements that should hide
|
|
10
|
+
* @param waitForVisible Enable checking that it is initially present
|
|
11
|
+
* (if `true` - with the default timeout, if a number - with the specified one)
|
|
12
|
+
*/
|
|
13
|
+
export declare function assertElementsHidden(locator: Locator, waitForVisible?: boolean | number): Promise<void>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertElementsHidden = assertElementsHidden;
|
|
4
|
+
const test_1 = require("@playwright/test");
|
|
5
|
+
const globalSettings_1 = require("../data/globalSettings");
|
|
6
|
+
/**
|
|
7
|
+
* Waits for all elements matching the locator to hide
|
|
8
|
+
*
|
|
9
|
+
* Optionally checks that the element was initially visible (wait for it to appear).
|
|
10
|
+
* If the element has not become visible after the timeout (300 ms by default),
|
|
11
|
+
* then it is considered that it managed to hide before that, this does not cause an error.
|
|
12
|
+
*
|
|
13
|
+
* @param locator Locator of elements that should hide
|
|
14
|
+
* @param waitForVisible Enable checking that it is initially present
|
|
15
|
+
* (if `true` - with the default timeout, if a number - with the specified one)
|
|
16
|
+
*/
|
|
17
|
+
async function assertElementsHidden(locator, waitForVisible = false) {
|
|
18
|
+
if (waitForVisible !== false) {
|
|
19
|
+
await locator
|
|
20
|
+
.first()
|
|
21
|
+
.waitFor({
|
|
22
|
+
state: 'visible',
|
|
23
|
+
timeout: typeof waitForVisible === 'number'
|
|
24
|
+
? waitForVisible
|
|
25
|
+
: globalSettings_1.globalSettings.assertElementsHidden.defaultWaitForVisibleTimeout,
|
|
26
|
+
})
|
|
27
|
+
.catch(() => { });
|
|
28
|
+
}
|
|
29
|
+
const itemsCount = await locator.count();
|
|
30
|
+
for (let i = 0; i < itemsCount; i++) {
|
|
31
|
+
await (0, test_1.expect)(locator.nth(i)).toBeHidden();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clearExtraHttpHeaders = clearExtraHttpHeaders;
|
|
4
|
+
const extraHttpHeaders_1 = require("../data/extraHttpHeaders");
|
|
5
|
+
/**
|
|
6
|
+
* Clear internal extraHttpHeaders list and extra HTTP headers in browser context
|
|
7
|
+
*/
|
|
8
|
+
async function clearExtraHttpHeaders(browserContext) {
|
|
9
|
+
if (!extraHttpHeaders_1.extraHttpHeaders.has(browserContext)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const headers = extraHttpHeaders_1.extraHttpHeaders.get(browserContext);
|
|
13
|
+
headers.clear();
|
|
14
|
+
await browserContext.setExtraHTTPHeaders({});
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Page } from '@playwright/test';
|
|
2
|
+
import type { Config, ExpectedMessage, ResponseFailure } from './types';
|
|
3
|
+
export declare function collectPageActivity(page: Page, config: Config): {
|
|
4
|
+
unsubscribe: () => void;
|
|
5
|
+
results: {
|
|
6
|
+
uncaughtErrors: Error[];
|
|
7
|
+
pageCrashes: Page[];
|
|
8
|
+
unexpectedMessages: ExpectedMessage[];
|
|
9
|
+
failedResponses: ResponseFailure[];
|
|
10
|
+
};
|
|
11
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectPageActivity = collectPageActivity;
|
|
4
|
+
const globalSettings_1 = require("../../data/globalSettings");
|
|
5
|
+
const isSameMessage_1 = require("./isSameMessage");
|
|
6
|
+
const isSameResponse_1 = require("./isSameResponse");
|
|
7
|
+
const STUB_HOSTNAME = 'https://stub';
|
|
8
|
+
function collectPageActivity(page, config) {
|
|
9
|
+
const { ignoredMessageTypes = globalSettings_1.globalSettings.collectPageActivity.ignoredMessageTypes, expectedMessages = globalSettings_1.globalSettings.collectPageActivity.expectedMessages, ignoredResponseStatuses = globalSettings_1.globalSettings.collectPageActivity.ignoredResponseStatuses, expectedResponses = globalSettings_1.globalSettings.collectPageActivity.expectedResponses, requestIdHeader = globalSettings_1.globalSettings.collectPageActivity.requestIdHeader, } = config;
|
|
10
|
+
const uncaughtErrors = [];
|
|
11
|
+
const pageCrashes = [];
|
|
12
|
+
const unexpectedMessages = [];
|
|
13
|
+
const failedResponses = [];
|
|
14
|
+
const handlePageError = (error) => uncaughtErrors.push(error);
|
|
15
|
+
page.on('pageerror', handlePageError);
|
|
16
|
+
const handleCrash = (error) => pageCrashes.push(error);
|
|
17
|
+
page.on('crash', handleCrash);
|
|
18
|
+
const handleConsole = (message) => {
|
|
19
|
+
const type = message.type();
|
|
20
|
+
const text = message.text();
|
|
21
|
+
if (!ignoredMessageTypes.includes(type) &&
|
|
22
|
+
!expectedMessages.some((0, isSameMessage_1.isSameMessage)(type, text))) {
|
|
23
|
+
unexpectedMessages.push({ text, type });
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
page.on('console', handleConsole);
|
|
27
|
+
const handleResponse = (response) => {
|
|
28
|
+
const status = response.status();
|
|
29
|
+
const url = response.url();
|
|
30
|
+
let redirect = response.headers()['location'];
|
|
31
|
+
// If the request has a relative location,
|
|
32
|
+
// then we substitute the origin of the original request for it.
|
|
33
|
+
// For example, on the example.com page, the request https://example.com/watch/123456?...,
|
|
34
|
+
// with location = /watch/654321?...,
|
|
35
|
+
// will be compared as https://example.com/watch/654321?...
|
|
36
|
+
if (redirect) {
|
|
37
|
+
const { origin: redirectOrigin } = new URL(redirect, STUB_HOSTNAME);
|
|
38
|
+
if (redirectOrigin === STUB_HOSTNAME) {
|
|
39
|
+
const { origin: currentOrigin } = new URL(url);
|
|
40
|
+
const { href: newRedirect } = new URL(redirect, currentOrigin);
|
|
41
|
+
redirect = newRedirect;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const resultUrl = redirect || url;
|
|
45
|
+
if (!ignoredResponseStatuses.includes(status) &&
|
|
46
|
+
!expectedResponses.some((0, isSameResponse_1.isSameResponse)(status, resultUrl, config.baseUrl))) {
|
|
47
|
+
const result = { status, url: resultUrl };
|
|
48
|
+
if (redirect) {
|
|
49
|
+
result.originalUrl = url;
|
|
50
|
+
}
|
|
51
|
+
const requestId = response.headers()[requestIdHeader];
|
|
52
|
+
if (requestId) {
|
|
53
|
+
result.requestId = requestId;
|
|
54
|
+
}
|
|
55
|
+
failedResponses.push(result);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
page.on('response', handleResponse);
|
|
59
|
+
const unsubscribe = () => {
|
|
60
|
+
page.off('pageerror', handlePageError);
|
|
61
|
+
page.off('crash', handleCrash);
|
|
62
|
+
page.off('console', handleConsole);
|
|
63
|
+
page.off('response', handleResponse);
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
unsubscribe,
|
|
67
|
+
results: {
|
|
68
|
+
uncaughtErrors,
|
|
69
|
+
pageCrashes,
|
|
70
|
+
unexpectedMessages,
|
|
71
|
+
failedResponses,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultIgnoredResponseStatuses = exports.defaultIgnoredMessageTypes = void 0;
|
|
4
|
+
exports.defaultIgnoredMessageTypes = [
|
|
5
|
+
'dir',
|
|
6
|
+
'dirxml',
|
|
7
|
+
'table',
|
|
8
|
+
'clear',
|
|
9
|
+
'startGroup',
|
|
10
|
+
'startGroupCollapsed',
|
|
11
|
+
'endGroup',
|
|
12
|
+
'profile',
|
|
13
|
+
'profileEnd',
|
|
14
|
+
'count',
|
|
15
|
+
'timeEnd',
|
|
16
|
+
];
|
|
17
|
+
exports.defaultIgnoredResponseStatuses = [200];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectPageActivity = void 0;
|
|
4
|
+
var collectPageActivity_1 = require("./collectPageActivity");
|
|
5
|
+
Object.defineProperty(exports, "collectPageActivity", { enumerable: true, get: function () { return collectPageActivity_1.collectPageActivity; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSameMessage = void 0;
|
|
4
|
+
const isSameMessage = (type, text) => {
|
|
5
|
+
return (message) => {
|
|
6
|
+
const isSameText = message.text instanceof RegExp ? message.text.test(text) : message.text === text;
|
|
7
|
+
return message.type === type && isSameText;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
exports.isSameMessage = isSameMessage;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSameResponse = isSameResponse;
|
|
4
|
+
const normalizePathname_1 = require("./normalizePathname");
|
|
5
|
+
const EMPTY_PATHNAME = '/';
|
|
6
|
+
function isSameResponse(status, url, baseUrl) {
|
|
7
|
+
return (expectedResponse) => {
|
|
8
|
+
const expectedUrl = new URL(expectedResponse.url, baseUrl);
|
|
9
|
+
const failedUrl = new URL(url);
|
|
10
|
+
let result = expectedResponse.status === status && expectedUrl.origin === failedUrl.origin;
|
|
11
|
+
if (result && expectedUrl.pathname !== EMPTY_PATHNAME) {
|
|
12
|
+
result =
|
|
13
|
+
(0, normalizePathname_1.normalizePathname)(expectedUrl.pathname) === (0, normalizePathname_1.normalizePathname)(failedUrl.pathname);
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const normalizePathname: (pathname: string) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// remove the last '/'
|
|
3
|
+
// for the case if pathname was not specified in the URL, since by default it is equal to '/'
|
|
4
|
+
// for the case if '/search' is compared with '/search/'
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.normalizePathname = void 0;
|
|
7
|
+
const normalizePathname = (pathname) => pathname.replace(/\/$/, '');
|
|
8
|
+
exports.normalizePathname = normalizePathname;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type ResponseFailure = {
|
|
2
|
+
status: number;
|
|
3
|
+
url: string;
|
|
4
|
+
originalUrl?: string;
|
|
5
|
+
requestId?: string;
|
|
6
|
+
};
|
|
7
|
+
export type ExpectedMessage = {
|
|
8
|
+
type: string;
|
|
9
|
+
text: string | RegExp;
|
|
10
|
+
};
|
|
11
|
+
export type ExpectedResponse = {
|
|
12
|
+
status: number;
|
|
13
|
+
url: string;
|
|
14
|
+
};
|
|
15
|
+
export type Config = {
|
|
16
|
+
/** Url where app is available */
|
|
17
|
+
baseUrl: string;
|
|
18
|
+
expectedMessages?: ExpectedMessage[];
|
|
19
|
+
ignoredMessageTypes?: string[];
|
|
20
|
+
expectedResponses?: ExpectedResponse[];
|
|
21
|
+
ignoredResponseStatuses?: number[];
|
|
22
|
+
requestIdHeader?: string;
|
|
23
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Page } from '@playwright/test';
|
|
2
|
+
/**
|
|
3
|
+
* Disables animation in CSS
|
|
4
|
+
*
|
|
5
|
+
* @param page
|
|
6
|
+
* @param allowFor CSS selectors for elements to enable animation for
|
|
7
|
+
*/
|
|
8
|
+
export declare function disableAnimations(page: Page, allowFor?: string[]): Promise<void>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.disableAnimations = disableAnimations;
|
|
4
|
+
const styleForDisableAnimation = /* css */ `{
|
|
5
|
+
transition-duration: 1ms !important;
|
|
6
|
+
transition-delay: 0s !important;
|
|
7
|
+
animation-duration: 1ms !important;
|
|
8
|
+
animation-delay: 0s !important;
|
|
9
|
+
animation-iteration-count: 1 !important;
|
|
10
|
+
}`;
|
|
11
|
+
/**
|
|
12
|
+
* Disables animation in CSS
|
|
13
|
+
*
|
|
14
|
+
* @param page
|
|
15
|
+
* @param allowFor CSS selectors for elements to enable animation for
|
|
16
|
+
*/
|
|
17
|
+
function disableAnimations(page, allowFor) {
|
|
18
|
+
const selector = allowFor && allowFor.length !== 0 ? `:not(${allowFor.join(',')})` : '*';
|
|
19
|
+
return page.addInitScript(({ selector, styleForDisableAnimation, }) => {
|
|
20
|
+
function injectStyles() {
|
|
21
|
+
const style = document.createElement('style');
|
|
22
|
+
style.textContent = selector + styleForDisableAnimation;
|
|
23
|
+
document.head.appendChild(style);
|
|
24
|
+
}
|
|
25
|
+
// Script added via addInitScript runs before DOM is built
|
|
26
|
+
if (document.readyState === 'complete') {
|
|
27
|
+
injectStyles();
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
31
|
+
injectStyles();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}, { selector, styleForDisableAnimation });
|
|
35
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Request } from '@playwright/test';
|
|
2
|
+
import type { ExpectRequestFnMatcher, ExpectRequestFnOptions } from './types';
|
|
3
|
+
export declare function expectRequest(requests: Map<string, Request>, url: string | RegExp, matcher?: ExpectRequestFnMatcher, options?: ExpectRequestFnOptions): Promise<void>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expectRequest = expectRequest;
|
|
4
|
+
const match_body_1 = require("./matchers/match-body");
|
|
5
|
+
const match_method_1 = require("./matchers/match-method");
|
|
6
|
+
const match_query_1 = require("./matchers/match-query");
|
|
7
|
+
const match_url_1 = require("./matchers/match-url");
|
|
8
|
+
const poll_with_timeout_1 = require("./poll-with-timeout");
|
|
9
|
+
async function expectRequest(requests, url, matcher = {}, options = {}) {
|
|
10
|
+
const { method, query, body } = matcher;
|
|
11
|
+
const { timeout, exact = false } = options;
|
|
12
|
+
let methodDiff = null;
|
|
13
|
+
let bodyDiff = null;
|
|
14
|
+
let queryDiff = null;
|
|
15
|
+
let isRequestMade = false;
|
|
16
|
+
await (0, poll_with_timeout_1.pollWithTimeout)({
|
|
17
|
+
callbackFn: async () => {
|
|
18
|
+
for (const [requestUrl, request] of requests.entries()) {
|
|
19
|
+
if (!(0, match_url_1.matchUrl)(requestUrl, url)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
isRequestMade = true;
|
|
23
|
+
methodDiff = (0, match_method_1.matchMethod)(request, method);
|
|
24
|
+
bodyDiff = (0, match_body_1.matchBody)(request, body, { exact });
|
|
25
|
+
queryDiff = (0, match_query_1.matchQuery)(request, query, { exact });
|
|
26
|
+
if (!(methodDiff || bodyDiff || queryDiff)) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
},
|
|
32
|
+
condition: (result) => result,
|
|
33
|
+
timeout,
|
|
34
|
+
onTimeout: ({ resolve }) => {
|
|
35
|
+
resolve(true);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
if (!isRequestMade) {
|
|
39
|
+
throw new Error('Asserted request was not made.');
|
|
40
|
+
}
|
|
41
|
+
const diffMessage = makeDiffMessage({ methodDiff, queryDiff, bodyDiff });
|
|
42
|
+
if (diffMessage) {
|
|
43
|
+
throw new Error(diffMessage);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function makeDiffMessage(params) {
|
|
47
|
+
const { methodDiff, queryDiff, bodyDiff } = params;
|
|
48
|
+
if (!(methodDiff || queryDiff || bodyDiff)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const message = ['\n\n- Expected\n+ Received'];
|
|
52
|
+
if (methodDiff) {
|
|
53
|
+
message.push(`Request method match:\n\n${methodDiff}`);
|
|
54
|
+
}
|
|
55
|
+
if (queryDiff) {
|
|
56
|
+
message.push(`Request query match:\n\n${queryDiff}`);
|
|
57
|
+
}
|
|
58
|
+
if (bodyDiff) {
|
|
59
|
+
message.push(`Request body match:\n\n${bodyDiff}`);
|
|
60
|
+
}
|
|
61
|
+
return message.join('\n\n\n');
|
|
62
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expectRequest = void 0;
|
|
4
|
+
var expect_request_1 = require("./expect-request");
|
|
5
|
+
Object.defineProperty(exports, "expectRequest", { enumerable: true, get: function () { return expect_request_1.expectRequest; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DiffContextItem, DiffItemBase, DiffLog } from './types';
|
|
2
|
+
export declare class DiffLogger {
|
|
3
|
+
private context;
|
|
4
|
+
private _diffLog;
|
|
5
|
+
get diffLog(): DiffLog;
|
|
6
|
+
addDiffItem(diffItem: DiffItemBase): void;
|
|
7
|
+
addContext(context: DiffContextItem): void;
|
|
8
|
+
removeContext(): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DiffLogger = void 0;
|
|
4
|
+
class DiffLogger {
|
|
5
|
+
context = [];
|
|
6
|
+
_diffLog = [];
|
|
7
|
+
get diffLog() {
|
|
8
|
+
return this._diffLog;
|
|
9
|
+
}
|
|
10
|
+
addDiffItem(diffItem) {
|
|
11
|
+
this.diffLog.push({ ...diffItem, context: [...this.context] });
|
|
12
|
+
}
|
|
13
|
+
addContext(context) {
|
|
14
|
+
this.context.push(context);
|
|
15
|
+
}
|
|
16
|
+
removeContext() {
|
|
17
|
+
this.context.pop();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.DiffLogger = DiffLogger;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Json } from '../../types';
|
|
2
|
+
interface DiffPrinterParams {
|
|
3
|
+
left: Json;
|
|
4
|
+
right: Json;
|
|
5
|
+
}
|
|
6
|
+
export declare class DiffPrinter {
|
|
7
|
+
private left;
|
|
8
|
+
private right;
|
|
9
|
+
constructor({ left, right }: DiffPrinterParams);
|
|
10
|
+
printDiff(params: {
|
|
11
|
+
side: 'left' | 'right';
|
|
12
|
+
exact?: boolean;
|
|
13
|
+
}): string;
|
|
14
|
+
private makePathFromContext;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DiffPrinter = void 0;
|
|
4
|
+
const compare_1 = require("./compare");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const print_json_diff_1 = require("./print-json-diff");
|
|
7
|
+
class DiffPrinter {
|
|
8
|
+
left;
|
|
9
|
+
right;
|
|
10
|
+
constructor({ left, right }) {
|
|
11
|
+
this.left = left;
|
|
12
|
+
this.right = right;
|
|
13
|
+
}
|
|
14
|
+
printDiff(params) {
|
|
15
|
+
const { side, exact } = params;
|
|
16
|
+
const diffLog = (0, compare_1.compare)({ left: this.left, right: this.right, exactArrays: exact });
|
|
17
|
+
const filteredLog = diffLog.reduce((acc, logItem) => {
|
|
18
|
+
if (logItem.side === side) {
|
|
19
|
+
acc.push(logItem);
|
|
20
|
+
}
|
|
21
|
+
else if (exact && logItem.type === constants_1.DiffType.ObjectMissingProperty) {
|
|
22
|
+
acc.push({
|
|
23
|
+
type: constants_1.DiffType.ValueMismatch,
|
|
24
|
+
received: logItem.expected.value,
|
|
25
|
+
side,
|
|
26
|
+
context: [...logItem.context, { objectField: logItem.expected.key }],
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return acc;
|
|
30
|
+
}, []);
|
|
31
|
+
if (!filteredLog.length) {
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
const pathAnnotations = filteredLog.reduce((acc, logItem) => {
|
|
35
|
+
const { context, type } = logItem;
|
|
36
|
+
const path = this.makePathFromContext(context);
|
|
37
|
+
if (!acc[path]) {
|
|
38
|
+
/* eslint-disable no-return-assign, no-param-reassign */
|
|
39
|
+
acc[path] = [];
|
|
40
|
+
}
|
|
41
|
+
if (type === constants_1.DiffType.ValueMismatch) {
|
|
42
|
+
if (logItem.expected === undefined && logItem.received !== undefined) {
|
|
43
|
+
acc[path].push({ type: constants_1.PathAnnotationType.ObjectExtraProperty });
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
acc[path].push({
|
|
47
|
+
type: constants_1.PathAnnotationType.ValueMismatch,
|
|
48
|
+
expected: logItem.expected,
|
|
49
|
+
received: logItem.received,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (type === constants_1.DiffType.ObjectMissingProperty) {
|
|
54
|
+
acc[path].push({
|
|
55
|
+
type: constants_1.PathAnnotationType.ObjectMissingProperty,
|
|
56
|
+
expected: logItem.expected,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else if (type === constants_1.DiffType.ArrayMissingValue) {
|
|
60
|
+
acc[path].push({
|
|
61
|
+
type: constants_1.PathAnnotationType.ArrayMissingValue,
|
|
62
|
+
expected: logItem.expected,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return acc;
|
|
66
|
+
}, {});
|
|
67
|
+
return (0, print_json_diff_1.printJsonDiff)({ json: side === 'left' ? this.left : this.right, pathAnnotations });
|
|
68
|
+
}
|
|
69
|
+
makePathFromContext(context) {
|
|
70
|
+
return context
|
|
71
|
+
.map(({ objectField, arrayIndex }) => {
|
|
72
|
+
if (arrayIndex !== undefined) {
|
|
73
|
+
return `[${arrayIndex}]`;
|
|
74
|
+
}
|
|
75
|
+
return `${objectField}`;
|
|
76
|
+
})
|
|
77
|
+
.join('.');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.DiffPrinter = DiffPrinter;
|