diff --git a/test/playwright/tests/helpers/ensure-build.ts b/test/playwright/tests/helpers/ensure-build.ts new file mode 100644 index 00000000..15691867 --- /dev/null +++ b/test/playwright/tests/helpers/ensure-build.ts @@ -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; +}; +