This repository has been archived by the owner on Aug 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.ts
56 lines (50 loc) · 1.8 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { test as base, expect } from '@playwright/test';
// We only require what's essential from the WordPress E2E test utils package.
import {
Admin,
Editor,
PageUtils,
RequestUtils,
} from '@wordpress/e2e-test-utils-playwright';
// We could also import utils from other packages.
// import { StoreApiUtils } from '@woocommerce/e2e-utils';
// This is a project-specific util.
import { WpGuestBar } from './wp-guest-bar';
// We are extending the functionalities of Playwright by adding and bootstrapping the custom utils.
// https://playwright.dev/docs/test-fixtures#creating-a-fixture
//
// We have a minimal setup compared to more involved ones.
// https://github.com/WordPress/gutenberg/blob/trunk/packages/e2e-test-utils-playwright/src/test.ts
// https://github.com/woocommerce/woocommerce-blocks/blob/trunk/tests/e2e/playwright-utils/test.ts
const test = base.extend<{
admin: Admin;
editor: Editor;
pageUtils: PageUtils;
requestUtils: RequestUtils;
wpGuestBar: WpGuestBar;
}>({
async admin({ page, pageUtils, editor }, use) {
await use(new Admin({ page, pageUtils, editor }));
},
async editor({ page }, use) {
await use(new Editor({ page }));
},
async pageUtils({ page }, use) {
await use(new PageUtils({ page }));
},
async requestUtils({}, use) {
// We want to make all REST API calls as authenticated users.
const requestUtils = await RequestUtils.setup({
baseURL: process.env.WP_BASE_URL,
user: {
username: process.env.WP_USERNAME,
password: process.env.WP_PASSWORD,
},
});
await use(requestUtils);
},
async wpGuestBar({ requestUtils }, use) {
await use(new WpGuestBar(requestUtils));
},
});
export { test, expect };