Skip to content

Commit

Permalink
Cleanup + improve accuracy of e2e tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
alantreadway committed Jun 17, 2024
1 parent 511485f commit 0c79d24
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
Expand Down
18 changes: 14 additions & 4 deletions packages/ag-charts-website/e2e/examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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());
});

Expand Down Expand Up @@ -92,15 +97,20 @@ test.describe('examples', () => {
// Wait for synchronous JS execution to complete before we start waiting
// for <canvas/> 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/);
});
Expand Down

0 comments on commit 0c79d24

Please sign in to comment.