Files
chrnx-dev-wp/tests/smoke/e2e-harness.test.mjs
T

64 lines
3.6 KiB
JavaScript

import assert from 'node:assert/strict';
import { readFile, readdir } from 'node:fs/promises';
import test from 'node:test';
test( 'Playwright seeds deterministic local fixtures once outside browser workers', async () => {
const config = await readFile( 'playwright.config.mjs', 'utf8' );
const setup = await readFile( 'tests/e2e/global-setup.mjs', 'utf8' );
const seed = await readFile( 'scripts/seed-test-content.php', 'utf8' );
const spec = await readFile( 'tests/e2e/editorial-editor.spec.mjs', 'utf8' );
assert.match( config, /globalSetup:\s*['"]\.\/tests\/e2e\/global-setup\.mjs['"]/ );
assert.match( setup, /execFileSync\(\s*['"]\.\/scripts\/seed-test-content\.sh['"]/s );
assert.equal( setup.match( /seed-test-content\.sh/g )?.length, 1 );
assert.equal( seed.match( /chrnx_seed_editorial_terms\(\);/g )?.length, 1 );
assert.doesNotMatch( spec, /wp-env|execFileSync|beforeAll/ );
} );
test( 'database scenarios run only in a serial Chromium project after all read-only browsers', async () => {
const config = await readFile( 'playwright.config.mjs', 'utf8' );
const files = await readdir( 'tests/e2e' );
const scenario = await readFile( 'tests/e2e/visual-scenarios.spec.mjs', 'utf8' );
for ( const file of files.filter( ( name ) => name.endsWith( '.spec.mjs' ) && name !== 'visual-scenarios.spec.mjs' ) ) {
const source = await readFile( `tests/e2e/${ file }`, 'utf8' );
assert.doesNotMatch( source, /seed-test-content|wp-env|execFileSync/, `${ file } must be DB read-only` );
}
assert.match( config, /name:\s*['"]scenarios['"]/ );
assert.match( config, /testMatch:\s*['"]visual-scenarios\.spec\.mjs['"]/ );
assert.match( config, /dependencies:\s*\[\s*['"]chromium['"],\s*['"]firefox['"],\s*['"]webkit['"]\s*\]/s );
assert.match( config, /fullyParallel:\s*false/ );
assert.match( config, /workers:\s*1/ );
assert.match( scenario, /test\.describe\.configure\(\s*\{\s*mode:\s*['"]serial['"]/s );
assert.match( scenario, /test\.afterAll[\s\S]*seedScenario\(\s*['"]default['"]\s*\)/ );
} );
test( 'the npm integration chain finishes isolated PHP before browser workers', async () => {
const manifest = JSON.parse( await readFile( 'package.json', 'utf8' ) );
assert.equal( manifest.scripts[ 'test:integration' ], undefined );
assert.match( manifest.scripts.test, /npm run test:php && npm run test:e2e/ );
assert.doesNotMatch( JSON.stringify( manifest.scripts ), /seed-state\.sh/ );
} );
test( 'restore lifecycle runs only in isolated PHPUnit and never in shared DB scripts', async () => {
const manifest = JSON.parse( await readFile( 'package.json', 'utf8' ) );
const phpTest = await readFile( 'tests/php/FixtureEnvironmentTest.php', 'utf8' );
const library = await readFile( 'scripts/lib/fixture-environment.php', 'utf8' );
const files = await readdir( 'tests/integration' ).catch( () => [] );
assert.deepEqual( files.filter( ( name ) => /seed-state|harness-preservation/.test( name ) ), [] );
assert.doesNotMatch( JSON.stringify( manifest.scripts ), /tests\/integration|seed-state/ );
assert.match( phpTest, /WP_UnitTestCase/ );
assert.match( phpTest, /chrnx_fixture_environment_snapshot/ );
assert.match( phpTest, /chrnx_fixture_environment_restore/ );
assert.match( library, /raw_base64/ );
} );
test( 'PHPUnit is pinned to the isolated tests-cli database', async () => {
const manifest = JSON.parse( await readFile( 'package.json', 'utf8' ) );
assert.match( manifest.scripts[ 'test:php' ], /wp-env run tests-cli/ );
assert.doesNotMatch( manifest.scripts[ 'test:php' ], /wp-env run cli/ );
assert.doesNotMatch( JSON.stringify( manifest.scripts ), /wp-env run cli[^\n"]*phpunit/ );
} );