global-setup.ts
45 lines
| 1 | /** |
| 2 | * External dependencies |
| 3 | */ |
| 4 | import { request } from '@playwright/test'; |
| 5 | import type { FullConfig } from '@playwright/test'; |
| 6 | |
| 7 | /** |
| 8 | * WordPress dependencies |
| 9 | */ |
| 10 | import { RequestUtils } from '@wordpress/e2e-test-utils-playwright'; |
| 11 | |
| 12 | async function globalSetup( config: FullConfig ) { |
| 13 | const { storageState, baseURL } = config.projects[ 0 ].use; |
| 14 | const storageStatePath = |
| 15 | typeof storageState === 'string' ? storageState : undefined; |
| 16 | |
| 17 | const requestContext = await request.newContext( { |
| 18 | baseURL, |
| 19 | } ); |
| 20 | |
| 21 | const requestUtils = new RequestUtils( requestContext, { |
| 22 | storageStatePath, |
| 23 | } ); |
| 24 | |
| 25 | // Authenticate and save the storageState to disk. |
| 26 | await requestUtils.setupRest(); |
| 27 | |
| 28 | // Reset the test environment before running the tests. |
| 29 | await Promise.all( [ |
| 30 | // requestUtils.activateTheme( 'twentytwentyone' ), |
| 31 | // // Disable this test plugin as it's conflicting with some of the tests. |
| 32 | // // We already have reduced motion enabled and Playwright will wait for most of the animations anyway. |
| 33 | // requestUtils.deactivatePlugin( |
| 34 | // 'gutenberg-test-plugin-disables-the-css-animations' |
| 35 | // ), |
| 36 | requestUtils.deleteAllPosts(), |
| 37 | requestUtils.deleteAllBlocks(), |
| 38 | requestUtils.resetPreferences(), |
| 39 | ] ); |
| 40 | |
| 41 | await requestContext.dispose(); |
| 42 | } |
| 43 | |
| 44 | export default globalSetup; |
| 45 |