diff --git a/tests/charts_visual.spec.ts b/tests/charts_visual.spec.ts index f42a3b6..17fec6d 100644 --- a/tests/charts_visual.spec.ts +++ b/tests/charts_visual.spec.ts @@ -1,11 +1,10 @@ import {expect, test} from '@playwright/test'; -import {setupGedcomRoute, waitForFonts} from './helpers'; +import {setupGedcomRoute, setupHermeticEnvironment} from './helpers'; test.describe('Core SVG Canvas Layouts @visual', () => { - test.beforeEach(async ({page, context}) => { + test.beforeEach(async ({context}) => { + await setupHermeticEnvironment(context); await setupGedcomRoute(context); - await page.goto('/'); - await waitForFonts(page); }); const layouts = [ diff --git a/tests/charts_visual.spec.ts-snapshots/chart-hourglass-visual-linux.png b/tests/charts_visual.spec.ts-snapshots/chart-hourglass-visual-linux.png index 340d9bf..6e13fce 100644 Binary files a/tests/charts_visual.spec.ts-snapshots/chart-hourglass-visual-linux.png and b/tests/charts_visual.spec.ts-snapshots/chart-hourglass-visual-linux.png differ diff --git a/tests/charts_visual.spec.ts-snapshots/chart-relatives-visual-linux.png b/tests/charts_visual.spec.ts-snapshots/chart-relatives-visual-linux.png index 0bfc5eb..9c99200 100644 Binary files a/tests/charts_visual.spec.ts-snapshots/chart-relatives-visual-linux.png and b/tests/charts_visual.spec.ts-snapshots/chart-relatives-visual-linux.png differ diff --git a/tests/config_visual.spec.ts b/tests/config_visual.spec.ts index 5882c2d..7751473 100644 --- a/tests/config_visual.spec.ts +++ b/tests/config_visual.spec.ts @@ -1,11 +1,10 @@ import {expect, test} from '@playwright/test'; -import {setupGedcomRoute, waitForFonts} from './helpers'; +import {setupGedcomRoute, setupHermeticEnvironment} from './helpers'; test.describe('Configurations Integration @visual', () => { test.beforeEach(async ({page, context}) => { + await setupHermeticEnvironment(context); await setupGedcomRoute(context); - await page.goto('/'); - await waitForFonts(page); await page.goto('/#/view?url=https://example.org/family.ged'); diff --git a/tests/details_visual.spec.ts b/tests/details_visual.spec.ts index deee425..c2e182d 100644 --- a/tests/details_visual.spec.ts +++ b/tests/details_visual.spec.ts @@ -1,13 +1,11 @@ import {expect, test} from '@playwright/test'; import dedent from 'dedent'; import * as fs from 'fs'; -import {mockGedcomResponse, setupHermeticEnvironment, waitForFonts} from './helpers'; +import {mockGedcomResponse, setupHermeticEnvironment} from './helpers'; test.describe('Details panel visual validation @visual', () => { - test.beforeEach(async ({page, context}) => { + test.beforeEach(async ({context}) => { await setupHermeticEnvironment(context); - await page.goto('/'); - await waitForFonts(page); }); test('Complex Names Test', async ({page, context}) => { diff --git a/tests/fixtures/Montserrat-Bold.woff2 b/tests/fixtures/Montserrat-Bold.woff2 new file mode 100644 index 0000000..dab8f33 Binary files /dev/null and b/tests/fixtures/Montserrat-Bold.woff2 differ diff --git a/tests/fixtures/Montserrat-Regular.woff2 b/tests/fixtures/Montserrat-Regular.woff2 new file mode 100644 index 0000000..e96845a Binary files /dev/null and b/tests/fixtures/Montserrat-Regular.woff2 differ diff --git a/tests/fixtures/montserrat.woff2 b/tests/fixtures/montserrat.woff2 deleted file mode 100644 index 3b2eaa9..0000000 Binary files a/tests/fixtures/montserrat.woff2 and /dev/null differ diff --git a/tests/helpers.ts b/tests/helpers.ts index 9e75fcf..43b1dfa 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -1,43 +1,68 @@ -import {BrowserContext, Page} from '@playwright/test'; +import {BrowserContext} from '@playwright/test'; import * as fs from 'fs'; /** * Sets up a hermetic test environment by blocking external tracking services - * and intercepting Google Fonts to serve static embedded fonts locally. + * and intercepting index.html to serve static embedded fonts locally. */ -export async function setupHermeticEnvironment(context: BrowserContext): Promise { +export async function setupHermeticEnvironment( + context: BrowserContext, +): Promise { await context.route('**/*google-analytics.com/**', (route) => route.abort()); await context.route('**/*googletagmanager.com/**', (route) => route.abort()); - // Intercept Google Fonts stylesheet requests to serve a deterministically embedded local font. - await context.route('**/fonts.googleapis.com/css2**', async (route) => { - const cssContent = ` + // Intercept index.html to serve preloaded local fonts deterministically. + await context.route( + (url) => url.pathname === '/', + async (route) => { + const response = await route.fetch(); + let body = await response.text(); + body = body.replace( + /^.*Montserrat.*$/m, + ` + + `, + ); + await route.fulfill({ + response, + body, + }); + }, + ); + + // Intercept requests for the locally embedded test fonts and serve the static binaries. + await context.route('**/Montserrat-Regular.woff2', async (route) => { + const fontBuffer = fs.readFileSync( + 'tests/fixtures/Montserrat-Regular.woff2', + ); await route.fulfill({ status: 200, - contentType: 'text/css', + contentType: 'font/woff2', headers: {'Access-Control-Allow-Origin': '*'}, - body: cssContent, + body: fontBuffer, }); }); - // Intercept requests for the locally embedded test font and serve the static binary. - await context.route('**/test-fonts/montserrat.woff2', async (route) => { - const fontBuffer = fs.readFileSync('tests/fixtures/montserrat.woff2'); + await context.route('**/Montserrat-Bold.woff2', async (route) => { + const fontBuffer = fs.readFileSync('tests/fixtures/Montserrat-Bold.woff2'); await route.fulfill({ status: 200, contentType: 'font/woff2', @@ -75,12 +100,4 @@ export async function setupGedcomRoute(context: BrowserContext): Promise { ); await mockGedcomResponse(context, gedcomContent); - await setupHermeticEnvironment(context); -} - -/** - * Ensures all custom web fonts are fully loaded and rendered. - */ -export async function waitForFonts(page: Page): Promise { - await page.evaluate(() => document.fonts.ready); } diff --git a/tests/intro_visual.spec.ts b/tests/intro_visual.spec.ts index 1bb622f..30bfa90 100644 --- a/tests/intro_visual.spec.ts +++ b/tests/intro_visual.spec.ts @@ -1,11 +1,10 @@ import {expect, test} from '@playwright/test'; -import {setupHermeticEnvironment, waitForFonts} from './helpers'; +import {setupHermeticEnvironment} from './helpers'; test.describe('Intro page visual validation @visual', () => { test.beforeEach(async ({page, context}) => { await setupHermeticEnvironment(context); await page.goto('/'); - await waitForFonts(page); }); test('intro-page', async ({page}) => {