@wordpress/e2e-test-utils-playwright
Version:
End-To-End (E2E) test utils for WordPress.
8 lines (7 loc) • 8.07 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../src/test.ts"],
"sourcesContent": ["/**\n * External dependencies\n */\nimport * as path from 'path';\nimport { test as base, expect, chromium } from '@playwright/test';\nimport type { ConsoleMessage } from '@playwright/test';\nimport getPort from 'get-port';\n\n/**\n * Internal dependencies\n */\nimport {\n\tAdmin,\n\tEditor,\n\tPageUtils,\n\tRequestUtils,\n\tMetrics,\n\tLighthouse,\n} from './index';\n\nconst STORAGE_STATE_PATH =\n\tprocess.env.STORAGE_STATE_PATH ||\n\tpath.join( process.cwd(), 'artifacts/storage-states/admin.json' );\n\n/**\n * Set of console logging types observed to protect against unexpected yet\n * handled (i.e. not catastrophic) errors or warnings. Each key corresponds\n * to the Playwright ConsoleMessage type, its value the corresponding function\n * on the console global object.\n */\nconst OBSERVED_CONSOLE_MESSAGE_TYPES = [ 'warn', 'error' ] as const;\n\n/**\n * Adds a page event handler to emit uncaught exception to process if one of\n * the observed console logging types is encountered.\n *\n * @param message The console message.\n */\nfunction observeConsoleLogging( message: ConsoleMessage ) {\n\tconst type = message.type();\n\tif (\n\t\t! OBSERVED_CONSOLE_MESSAGE_TYPES.includes(\n\t\t\ttype as ( typeof OBSERVED_CONSOLE_MESSAGE_TYPES )[ number ]\n\t\t)\n\t) {\n\t\treturn;\n\t}\n\n\tconst text = message.text();\n\n\t// An exception is made for _blanket_ deprecation warnings: Those\n\t// which log regardless of whether a deprecated feature is in use.\n\tif ( text.includes( 'This is a global warning' ) ) {\n\t\treturn;\n\t}\n\n\t// A chrome advisory warning about SameSite cookies is informational\n\t// about future changes, tracked separately for improvement in core.\n\t//\n\t// See: https://core.trac.wordpress.org/ticket/37000\n\t// See: https://www.chromestatus.com/feature/5088147346030592\n\t// See: https://www.chromestatus.com/feature/5633521622188032\n\tif (\n\t\ttext.includes( 'A cookie associated with a cross-site resource' ) ||\n\t\ttext.includes(\n\t\t\t'https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite'\n\t\t)\n\t) {\n\t\treturn;\n\t}\n\n\t// Viewing posts on the front end can result in this error, which\n\t// has nothing to do with Gutenberg.\n\tif ( text.includes( 'net::ERR_UNKNOWN_URL_SCHEME' ) ) {\n\t\treturn;\n\t}\n\n\t// TODO: Not implemented yet.\n\t// Network errors are ignored only if we are intentionally testing\n\t// offline mode.\n\t// if (\n\t// \ttext.includes( 'net::ERR_INTERNET_DISCONNECTED' ) &&\n\t// \tisOfflineMode()\n\t// ) {\n\t// \treturn;\n\t// }\n\n\t// As of WordPress 5.3.2 in Chrome 79, navigating to the block editor\n\t// (Posts > Add New) will display a console warning about\n\t// non - unique IDs.\n\t// See: https://core.trac.wordpress.org/ticket/23165\n\tif ( text.includes( 'elements with non-unique id #_wpnonce' ) ) {\n\t\treturn;\n\t}\n\n\t// Ignore all JQMIGRATE (jQuery migrate) deprecation warnings.\n\tif ( text.includes( 'JQMIGRATE' ) ) {\n\t\treturn;\n\t}\n\n\t// https://bugzilla.mozilla.org/show_bug.cgi?id=1404468\n\tif (\n\t\ttext.includes( 'Layout was forced before the page was fully loaded' )\n\t) {\n\t\treturn;\n\t}\n\n\t// Deprecated warnings coming from the third-party libraries.\n\tif ( text.includes( 'MouseEvent.moz' ) ) {\n\t\treturn;\n\t}\n\n\tconst logFunction =\n\t\ttype as ( typeof OBSERVED_CONSOLE_MESSAGE_TYPES )[ number ];\n\n\t// Disable reason: We intentionally bubble up the console message\n\t// which, unless the test explicitly anticipates the logging via\n\t// @wordpress/jest-console matchers, will cause the intended test\n\t// failure.\n\t// eslint-disable-next-line no-console\n\tconsole[ logFunction ]( text );\n}\n\nconst test = base.extend<\n\t{\n\t\tadmin: Admin;\n\t\teditor: Editor;\n\t\tpageUtils: PageUtils;\n\t\tsnapshotConfig: void;\n\t\tmetrics: Metrics;\n\t\tlighthouse: Lighthouse;\n\t},\n\t{\n\t\trequestUtils: RequestUtils;\n\t\tlighthousePort: number;\n\t}\n>( {\n\tadmin: async ( { page, pageUtils, editor }, use ) => {\n\t\tawait use( new Admin( { page, pageUtils, editor } ) );\n\t},\n\teditor: async ( { page }, use ) => {\n\t\tawait use( new Editor( { page } ) );\n\t},\n\tpage: async ( { page }, use ) => {\n\t\tpage.on( 'console', observeConsoleLogging );\n\n\t\tawait use( page );\n\n\t\t// Clear local storage after each test.\n\t\t// This needs to be wrapped with a try/catch because it can fail when\n\t\t// the test is skipped (e.g. via fixme).\n\t\ttry {\n\t\t\tawait page.evaluate( () => {\n\t\t\t\twindow.localStorage.clear();\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\t// noop.\n\t\t}\n\n\t\tawait page.close();\n\t},\n\tpageUtils: async ( { page, browserName }, use ) => {\n\t\tawait use( new PageUtils( { page, browserName } ) );\n\t},\n\trequestUtils: [\n\t\tasync ( {}, use, workerInfo ) => {\n\t\t\tconst requestUtils = await RequestUtils.setup( {\n\t\t\t\tbaseURL: workerInfo.project.use.baseURL,\n\t\t\t\tstorageStatePath: STORAGE_STATE_PATH,\n\t\t\t} );\n\n\t\t\tawait use( requestUtils );\n\t\t},\n\t\t{ scope: 'worker', auto: true },\n\t],\n\t// Spins up a new browser for use by the Lighthouse fixture\n\t// so that Lighthouse can connect to the debugging port.\n\t// As a worker-scoped fixture, this will only launch 1\n\t// instance for the whole test worker, so multiple tests\n\t// will share the same instance with the same port.\n\tlighthousePort: [\n\t\tasync ( {}, use ) => {\n\t\t\tconst port = await getPort();\n\t\t\tconst browser = await chromium.launch( {\n\t\t\t\targs: [ `--remote-debugging-port=${ port }` ],\n\t\t\t} );\n\n\t\t\tawait use( port );\n\n\t\t\tawait browser.close();\n\t\t},\n\t\t{ scope: 'worker' },\n\t],\n\tlighthouse: async ( { page, lighthousePort }, use ) => {\n\t\tawait use( new Lighthouse( { page, port: lighthousePort } ) );\n\t},\n\tmetrics: async ( { page }, use ) => {\n\t\tawait use( new Metrics( { page } ) );\n\t},\n} );\n\nexport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