test: make sure that E2E tests always run with the latest changes

This commit is contained in:
JackUait 2025-11-10 17:15:45 +03:00
commit fb2329811f

View file

@ -0,0 +1,34 @@
import { spawnSync } from 'node:child_process';
import path from 'node:path';
let didBuild = false;
/**
* Ensure the Editor.js bundle is freshly built before running Playwright tests.
*
* Necessary because the Playwright fixtures load the UMD bundle directly from the dist folder.
* Without rebuilding we might exercise stale code that doesn't match the current TypeScript sources.
*/
export const ensureEditorBundleBuilt = (): void => {
if (didBuild) {
return;
}
const projectRoot = path.resolve(__dirname, '../../../..');
const result = spawnSync('yarn', [ 'build:test' ], {
cwd: projectRoot,
stdio: 'inherit',
shell: process.platform === 'win32',
});
if (result.error) {
throw result.error;
}
if (result.status !== 0) {
throw new Error(`Building Editor.js for Playwright failed with exit code ${result.status ?? 'unknown'}.`);
}
didBuild = true;
};