diff --git a/playwright.config.ts b/playwright.config.ts index 558f6b3f..86348c64 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,14 +1,18 @@ import { defineConfig, devices } from '@playwright/test' +const isCI = !!process.env.CI + export default defineConfig({ - testDir: './e2e', + testDir: './tests/e2e', fullyParallel: true, - forbidOnly: !!process.env.CI, - retries: process.env.CI ? 2 : 0, - workers: process.env.CI ? 1 : undefined, - reporter: [['html', { open: 'always' }]], + forbidOnly: isCI, + retries: isCI ? 2 : 0, + workers: isCI ? 1 : undefined, + reporter: 'html', + // Use OS-independent snapshot names (HTML content is the same across platforms) + snapshotPathTemplate: '{testDir}/{testFileDir}/{testFileName}-snapshots/{arg}{ext}', use: { - baseURL: 'http://localhost:4173', + baseURL: isCI ? 'http://localhost:4173' : 'http://localhost:5173', trace: 'on-first-retry', // Fixed viewport to ensure consistent map rendering viewport: { width: 1280, height: 720 }, @@ -20,9 +24,11 @@ export default defineConfig({ }, ], webServer: { - command: 'npm run build && npm run preview', - url: 'http://localhost:4173', - reuseExistingServer: !process.env.CI, + // In CI: build and preview for production-like testing + // In dev: use vite dev server (faster, no rebuild needed) + command: isCI ? 'npm run build && npm run preview' : 'npm run dev', + url: isCI ? 'http://localhost:4173' : 'http://localhost:5173', + reuseExistingServer: !isCI, timeout: 120000, }, }) diff --git a/public/main.js b/public/main.js index 6da462d5..31a6506f 100644 --- a/public/main.js +++ b/public/main.js @@ -1227,8 +1227,12 @@ function showStatistics() { Cultures: ${pack.cultures.length - 1}`; mapId = Date.now(); // unique map id is it's creation date number + window.mapId = mapId; // expose for test automation mapHistory.push({seed, width: graphWidth, height: graphHeight, template: heightmap, created: mapId}); INFO && console.info(stats); + + // Dispatch event for test automation and external integrations + window.dispatchEvent(new CustomEvent('map:generated', { detail: { seed, mapId } })); } const regenerateMap = debounce(async function (options) { diff --git a/e2e/layers.spec.ts b/tests/e2e/layers.spec.ts similarity index 91% rename from e2e/layers.spec.ts rename to tests/e2e/layers.spec.ts index 8c29df88..b6a270bf 100644 --- a/e2e/layers.spec.ts +++ b/tests/e2e/layers.spec.ts @@ -10,24 +10,19 @@ test.describe('map layers', () => { localStorage.clear() sessionStorage.clear() }) - - // Navigate with seed parameter + + // Navigate with seed parameter and wait for full load // NOTE: // - We use a fixed seed ("test-seed") to make map generation deterministic for snapshot tests. - // - The resulting snapshots are platform-specific (Playwright stores them with suffixes such as - // "-darwin", "-linux", "-win32"). - // - Currently, only macOS ("-darwin") snapshots may be present in the repository. On other - // platforms (Linux/Windows), you must generate/update the corresponding snapshots for the - // tests to pass, or configure Playwright to use per-platform snapshot directories. + // - Snapshots are OS-independent (configured in playwright.config.ts). await page.goto('/?seed=test-seed') - - const mapElement = page.locator('#map') - await expect(mapElement).toBeVisible() - - // Wait for map generation to complete - await expect(mapElement.locator('#terrs')).toBeAttached({ timeout: 30000 }) - await expect(mapElement.locator('#labels')).toBeAttached() - await expect(page.locator('#loading')).toBeHidden({ timeout: 30000 }) + + // Wait for map generation to complete by checking window.mapId + // mapId is exposed on window at the very end of showStatistics() + await page.waitForFunction(() => (window as any).mapId !== undefined, { timeout: 60000 }) + + // Additional wait for any rendering/animations to settle + await page.waitForTimeout(500) }) // Ocean and water layers diff --git a/e2e/layers.spec.ts-snapshots/anchors-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/anchors.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/anchors-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/anchors.html diff --git a/e2e/layers.spec.ts-snapshots/armies-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/armies.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/armies-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/armies.html diff --git a/e2e/layers.spec.ts-snapshots/biomes-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/biomes.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/biomes-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/biomes.html diff --git a/e2e/layers.spec.ts-snapshots/borders-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/borders.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/borders-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/borders.html diff --git a/e2e/layers.spec.ts-snapshots/cells-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/cells.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/cells-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/cells.html diff --git a/e2e/layers.spec.ts-snapshots/coastline-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/coastline.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/coastline-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/coastline.html diff --git a/e2e/layers.spec.ts-snapshots/compass-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/compass.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/compass-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/compass.html diff --git a/e2e/layers.spec.ts-snapshots/coordinates-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/coordinates.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/coordinates-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/coordinates.html diff --git a/e2e/layers.spec.ts-snapshots/cultures-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/cultures.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/cultures-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/cultures.html diff --git a/e2e/layers.spec.ts-snapshots/emblems-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/emblems.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/emblems-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/emblems.html diff --git a/e2e/layers.spec.ts-snapshots/ice-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/ice.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/ice-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/ice.html diff --git a/e2e/layers.spec.ts-snapshots/icons-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/icons.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/icons-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/icons.html diff --git a/e2e/layers.spec.ts-snapshots/labels-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/labels.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/labels-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/labels.html diff --git a/e2e/layers.spec.ts-snapshots/lakes-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/lakes.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/lakes-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/lakes.html diff --git a/e2e/layers.spec.ts-snapshots/landmass-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/landmass.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/landmass-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/landmass.html diff --git a/e2e/layers.spec.ts-snapshots/markers-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/markers.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/markers-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/markers.html diff --git a/e2e/layers.spec.ts-snapshots/ocean-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/ocean.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/ocean-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/ocean.html diff --git a/e2e/layers.spec.ts-snapshots/population-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/population.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/population-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/population.html diff --git a/e2e/layers.spec.ts-snapshots/precipitation-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/precipitation.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/precipitation-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/precipitation.html diff --git a/e2e/layers.spec.ts-snapshots/provinces-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/provinces.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/provinces-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/provinces.html diff --git a/e2e/layers.spec.ts-snapshots/regions-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/regions.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/regions-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/regions.html diff --git a/e2e/layers.spec.ts-snapshots/relief-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/relief.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/relief-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/relief.html diff --git a/e2e/layers.spec.ts-snapshots/religions-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/religions.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/religions-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/religions.html diff --git a/e2e/layers.spec.ts-snapshots/rivers-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/rivers.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/rivers-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/rivers.html diff --git a/e2e/layers.spec.ts-snapshots/routes-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/routes.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/routes-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/routes.html diff --git a/e2e/layers.spec.ts-snapshots/ruler-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/ruler.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/ruler-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/ruler.html diff --git a/e2e/layers.spec.ts-snapshots/scaleBar-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/scaleBar.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/scaleBar-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/scaleBar.html diff --git a/e2e/layers.spec.ts-snapshots/temperature-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/temperature.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/temperature-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/temperature.html diff --git a/e2e/layers.spec.ts-snapshots/terrain-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/terrain.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/terrain-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/terrain.html diff --git a/e2e/layers.spec.ts-snapshots/vignette-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/vignette.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/vignette-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/vignette.html diff --git a/e2e/layers.spec.ts-snapshots/zones-chromium-darwin.html b/tests/e2e/layers.spec.ts-snapshots/zones.html similarity index 100% rename from e2e/layers.spec.ts-snapshots/zones-chromium-darwin.html rename to tests/e2e/layers.spec.ts-snapshots/zones.html