Skip to content

Commit

Permalink
test: Update and improve e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmilton committed Feb 11, 2024
1 parent d37b3c1 commit 0727e28
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
5 changes: 5 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from '@playwright/test';

export default defineConfig({
testMatch: 'test/e2e/*.spec.ts',
forbidOnly: !!process.env.CI,
webServer: {
command: 'bun run serve',
port: 3000,
Expand All @@ -10,5 +11,9 @@ export default defineConfig({
},
use: {
baseURL: 'http://localhost:3000',
acceptDownloads: false,
contextOptions: {
strictSelectors: true,
},
},
});
70 changes: 68 additions & 2 deletions test/e2e/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,72 @@
import { expect, test } from '@playwright/test';
import { expect, test, type ConsoleMessage } from '@playwright/test';

test('temporary placeholder', async ({ page }) => {
// TODO: Write tests to verify each feature of the app works:
// - source code in vs output
// - on-screen virtual console
// - "Auto compile on input"
// - "Compile" button
// - "Clear Output" button
// - editor text is correct default text
// - editor has line numbers
// - editor works as expected
// - view looks correct on desktop screen size
// - view looks correct on mobile screen size
// - view looks correct on tablet screen size
// - headings are visible

test.beforeEach(async ({ context }) => {
// Mock trackx script with empty file
await context.route(/^https:\/\/cdn\.jsdelivr\.net\/npm\/trackx/, (route) =>
route.fulfill({ status: 200 }),
);
});

test('repl app', async ({ page }) => {
await page.goto('/');

await expect(page).toHaveTitle('ekscss REPL');
await expect(page).toHaveURL('http://localhost:3000/'); // didn't redirect

await expect(page.locator('#alert')).toBeAttached();
await expect(page.locator('#app')).toBeAttached();
await expect(page.locator('#nav')).toBeAttached();
await expect(page.locator('#in')).toBeAttached();
await expect(page.locator('#out')).toBeAttached();
await expect(page.locator('#con')).toBeAttached();
await expect(page.locator('#foot')).toBeAttached();
await expect(page.locator('a[href="https://ekscss.js.org"]')).toBeAttached(); // link to the ekscss docs

// TODO: Footer contains ekscss version
// TODO: Footer contains REPL version
// TODO: Footer contains link to maxmilton.com
// TODO: Footer contains link to ekscss repo
// TODO: Footer contains link to ekscss repl repo
// TODO: Footer contains link to report bug
});

test('matches screenshot', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveScreenshot('repl.png', {
fullPage: true,
mask: [
page.locator('#con .console>div'), // mask compile time log entry
page.locator('#foot'), // mask footer which contains version numbers
],
});
});

test('has no console calls (except 2 known calls) or unhandled errors', async ({ page }) => {
const unhandledErrors: Error[] = [];
const consoleMessages: ConsoleMessage[] = [];
page.on('pageerror', (err) => unhandledErrors.push(err));
page.on('console', (msg) => consoleMessages.push(msg));
await page.goto('/');

expect(unhandledErrors).toHaveLength(0);
expect(consoleMessages).toHaveLength(2);
expect(consoleMessages[0].type()).toBe('log');
expect(consoleMessages[0].text()).toMatch(/^AST: \[.*]$/);

expect(consoleMessages[1].type()).toBe('log');
expect(consoleMessages[1].text()).toMatch(/^Compile time: \d+\.\d\dms$/);
});
Binary file added test/e2e/index.spec.ts-snapshots/repl-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0727e28

Please sign in to comment.