From 0c79d247864b0c42b6160a711a8bbc04b63de224 Mon Sep 17 00:00:00 2001 From: Alan Treadway Date: Mon, 17 Jun 2024 11:18:10 +0100 Subject: [PATCH] Cleanup + improve accuracy of e2e tests. --- package.json | 1 + .../ag-charts-website/e2e/examples.spec.ts | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index fa84f37499..6f655ee87e 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "postinstall": "npx run-s postinstall:*", "postinstall:patch": "patch-package", "postinstall:verify-canvas-binary-present": "test -f node_modules/canvas/build/Release/canvas.node", + "postinstall:playwright": "npx playwright install", "postinstall:nx-daemon-prebuild-restart": "(test -e .nx/cache/d/server-process.json && nx daemon --stop) || echo \"Nx Daemon not running\"", "postinstall:nx-plugin-build": "nx run-many -p ag-charts-generate-chart-thumbnail,ag-charts-generate-code-reference-files,ag-charts-generate-example-files,ag-charts-task-autogen -t build", "postinstall:nx-daemon-restart": "(test -e .nx/cache/d/server-process.json && nx daemon --stop) || echo \"Nx Daemon not running\"" diff --git a/packages/ag-charts-website/e2e/examples.spec.ts b/packages/ag-charts-website/e2e/examples.spec.ts index 0242a8837b..be554361ce 100644 --- a/packages/ag-charts-website/e2e/examples.spec.ts +++ b/packages/ag-charts-website/e2e/examples.spec.ts @@ -52,9 +52,11 @@ function toPageUrls(path: string) { test.describe('examples', () => { let consoleWarnOrErrors: string[]; + let ignore404s = false; test.beforeEach(({ page }) => { consoleWarnOrErrors = []; + ignore404s = false; page.on('console', (msg) => { // We only care about warnings/errors. @@ -63,6 +65,9 @@ test.describe('examples', () => { // We don't care about the AG Charts license error message. if (msg.text().startsWith('*')) return; + // Ignore 404s when expected + if (/the server responded with a status of 404 \(Not Found\)/.test(msg.text()) && ignore404s) return; + consoleWarnOrErrors.push(msg.text()); }); @@ -92,15 +97,20 @@ test.describe('examples', () => { // Wait for synchronous JS execution to complete before we start waiting // for to appear. await page.evaluate(() => 1); - await expect(page.locator('canvas')).toBeVisible({ timeout: 10_000 }); - await expect(page.locator('.ag-charts-wrapper')).toHaveAttribute('data-scene-renders', { - timeout: 5_000, - }); + await expect(page.locator('canvas').first()).toBeVisible({ timeout: 10_000 }); + for (const elements of await page.locator('canvas').all()) { + await expect(elements).toBeVisible(); + } + await expect(page.locator('.ag-charts-wrapper').first()).toBeVisible({ timeout: 5_000 }); + for (const elements of await page.locator('.ag-charts-wrapper').all()) { + await expect(elements).toHaveAttribute('data-scene-renders'); + } }); } if (status === '404') { test(`should 404 on ${url}`, async ({ page }) => { + ignore404s = true; await page.goto(url); expect(await page.title()).toMatch(/Page Not Found/); });