-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wp-scripts: add support for Playwright (#53108)
* wp-scripts: add support for Playwright * Fix lock file * Lint fixes * Downgrade Playwright * Fix config arg & browser install * Use relative path for testDir * Fix config inheritance * Update npm scripts * Fix e2e config too * Suppress eslint errors * Fix lock file * Move `ASSETS_PATH` definition * Fix typo * Update readme & changelogs * Move changelog entries * Add missing dependency
- Loading branch information
1 parent
ed22bf9
commit e2941e9
Showing
20 changed files
with
285 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: [ 'plugin:playwright/recommended' ], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
const path = require( 'path' ); | ||
const { fileURLToPath } = require( 'url' ); | ||
const { defineConfig, devices } = require( '@playwright/test' ); | ||
|
||
process.env.WP_ARTIFACTS_PATH ??= path.join( process.cwd(), 'artifacts' ); | ||
process.env.STORAGE_STATE_PATH ??= path.join( | ||
process.env.WP_ARTIFACTS_PATH, | ||
'storage-states/admin.json' | ||
); | ||
|
||
const config = defineConfig( { | ||
reporter: process.env.CI ? [ [ 'github' ] ] : [ [ 'list' ] ], | ||
forbidOnly: !! process.env.CI, | ||
// fullyParallel: false, | ||
workers: 1, | ||
retries: process.env.CI ? 2 : 0, | ||
timeout: parseInt( process.env.TIMEOUT || '', 10 ) || 100_000, // Defaults to 100 seconds. | ||
// Don't report slow test "files", as we will be running our tests in serial. | ||
reportSlowTests: null, | ||
testDir: './specs', | ||
outputDir: path.join( process.env.WP_ARTIFACTS_PATH, 'test-results' ), | ||
snapshotPathTemplate: | ||
'{testDir}/{testFileDir}/__snapshots__/{arg}-{projectName}{ext}', | ||
globalSetup: fileURLToPath( | ||
new URL( './playwright/global-setup.ts', 'file:' + __filename ).href | ||
), | ||
use: { | ||
baseURL: process.env.WP_BASE_URL || 'http://localhost:8889', | ||
headless: true, | ||
viewport: { | ||
width: 960, | ||
height: 700, | ||
}, | ||
ignoreHTTPSErrors: true, | ||
locale: 'en-US', | ||
contextOptions: { | ||
reducedMotion: 'reduce', | ||
strictSelectors: true, | ||
}, | ||
storageState: process.env.STORAGE_STATE_PATH, | ||
actionTimeout: 10_000, // 10 seconds. | ||
trace: 'retain-on-failure', | ||
screenshot: 'only-on-failure', | ||
video: 'on-first-retry', | ||
}, | ||
webServer: { | ||
command: 'npm run wp-env start', | ||
port: 8889, | ||
timeout: 120_000, // 120 seconds. | ||
reuseExistingServer: true, | ||
}, | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices[ 'Desktop Chrome' ] }, | ||
}, | ||
], | ||
} ); | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { request } from '@playwright/test'; | ||
import type { FullConfig } from '@playwright/test'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { RequestUtils } from '@wordpress/e2e-test-utils-playwright'; | ||
|
||
async function globalSetup( config: FullConfig ) { | ||
const { storageState, baseURL } = config.projects[ 0 ].use; | ||
const storageStatePath = | ||
typeof storageState === 'string' ? storageState : undefined; | ||
|
||
const requestContext = await request.newContext( { | ||
baseURL, | ||
} ); | ||
|
||
const requestUtils = new RequestUtils( requestContext, { | ||
storageStatePath, | ||
} ); | ||
|
||
// Authenticate and save the storageState to disk. | ||
await requestUtils.setupRest(); | ||
|
||
await requestContext.dispose(); | ||
} | ||
|
||
export default globalSetup; |
Oops, something went wrong.