Skip to content

Commit

Permalink
chore: make tests os agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeiscontent committed May 8, 2024
1 parent 4aab4cb commit 639cd33
Show file tree
Hide file tree
Showing 29 changed files with 14,801 additions and 12,581 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Playwright Tests
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Enable Corepack
run: corepack enable
- name: Install dependencies
run: pnpm i
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
- name: Run Playwright tests
run: pnpm exec playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
48 changes: 7 additions & 41 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,17 @@ on:
- next
- v1
jobs:
unit:
name: API Tests
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Download deps
- run: corepack enable
- name: Install dependencies
run: pnpm i
- name: Build packages
run: pnpm run build
- name: Run tests
- name: Run Vitest tests
run: pnpm exec vitest
- name: Typecheck
- name: Run Typecheck
run: pnpm -r run typecheck

e2e:
name: E2E Tests
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 20
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Download deps
run: pnpm i
- name: Install Playwright
run: pnpm exec playwright install --with-deps
- name: Run tests
run: pnpm exec playwright test
- name: Upload test result
uses: actions/upload-artifact@v2
if: always()
with:
name: test-results
path: test-results/
retention-days: 30
17 changes: 8 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Logs
logs
*.log
logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
Expand All @@ -9,20 +9,20 @@ yarn-error.log*
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock
*.seed
pids

# Build result
/packages/*/*.js
!/packages/*/rollup.config.js
/packages/*/_virtual
/packages/*/*.cjs
/packages/*/*.mjs
/packages/*/*.d.ts
/packages/*/README
/packages/*/*.js
/packages/*/*.mjs
/packages/*/LICENSE
/packages/*/_virtual
/packages/*/README

# Anything built
build/
Expand All @@ -41,10 +41,9 @@ node_modules/

# Output of 'npm pack'
*.tgz
/test-results/
/playwright-report/
/playwright/.cache/
/test-results/

# DS Store
.DS_Store
**/.DS_Store
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, type Locator, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground, selectAll } from './helpers';

function getFieldset(form: Locator) {
return {
Expand Down Expand Up @@ -74,7 +74,7 @@ async function runTest(page: Page, javaScriptEnabled: boolean) {
'Title is required',
]);

await fieldset.email.press('Control+a');
await selectAll(fieldset.email);
await fieldset.email.press('ArrowRight');
await fieldset.email.type('u');
if (!javaScriptEnabled) {
Expand All @@ -86,7 +86,7 @@ async function runTest(page: Page, javaScriptEnabled: boolean) {
'Title is required',
]);

await fieldset.email.press('Control+a');
await selectAll(fieldset.email);
await fieldset.email.press('ArrowRight');
await fieldset.email.type('i');
if (!javaScriptEnabled) {
Expand All @@ -98,7 +98,7 @@ async function runTest(page: Page, javaScriptEnabled: boolean) {
'Title is required',
]);

await fieldset.email.press('Control+a');
await selectAll(fieldset.email);
await fieldset.email.press('ArrowRight');
await fieldset.email.type('d');
if (!javaScriptEnabled) {
Expand All @@ -117,7 +117,7 @@ async function runTest(page: Page, javaScriptEnabled: boolean) {

await expect(playground.error).toHaveText(['Email is already used', '']);

await fieldset.email.press('Control+a');
await selectAll(fieldset.email);
await fieldset.email.press('ArrowRight');
await fieldset.email.type('e');
await playground.submit.click();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground } from './helpers';

async function runTest(
page: Page,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground } from './helpers';

async function setupField(page: Page, constraint: object, secret?: any) {
const playground = getPlayground(page);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground } from './helpers';

async function runTest(page: Page) {
const playground = getPlayground(page);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, type Locator, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground } from './helpers';

function getFieldset(form: Locator) {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, type Locator, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground } from './helpers';

function getFieldset(form: Locator) {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Locator, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground } from './helpers';

function getFieldset(form: Locator) {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, type Locator, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground } from './helpers';

function getFieldset(form: Locator) {
return {
Expand Down
46 changes: 46 additions & 0 deletions e2e/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Locator, Page } from '@playwright/test';

export function getPlayground(page: Page) {
const container = page.locator('body');
const submission = container.locator('pre');

return {
container,
form: container.locator('form'),
submit: container.locator('footer button[type="submit"]'),
reset: container.locator('footer button[type="reset"]'),
submission,
result: () => submission.innerText().then(JSON.parse),
error: container.locator('main p'),
};
}

export async function selectAll(locator: Locator) {
switch (process.platform) {
case 'darwin':
await locator.press('Meta+a');
break;
default:
await locator.press('Control+a');
}
}

export async function cut(locator: Locator) {
switch (process.platform) {
case 'darwin':
await locator.press('Meta+x');
break;
default:
await locator.press('Control+x');
}
}

export async function paste(locator: Locator) {
switch (process.platform) {
case 'darwin':
await locator.press('Meta+v');
break;
default:
await locator.press('Control+v');
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Locator, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground } from './helpers';

function getFieldset(form: Locator) {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Page, test, expect } from '@playwright/test';
import { cut, paste, selectAll } from './helpers';

async function getForm(
page: Page,
Expand Down Expand Up @@ -125,7 +126,7 @@ test('works with keyboard events', async ({ page }) => {
];

// Cut out 'c'
await form.nativeInput.press('Control+x');
await cut(form.nativeInput);
await expect(form.nativeLogs).toHaveText(logs2);
await expect(form.baseLogs).toHaveText(logs2);

Expand All @@ -145,7 +146,7 @@ test('works with keyboard events', async ({ page }) => {
];

// Paste the 'c' back
await form.nativeInput.press('Control+v');
await paste(form.nativeInput);
await expect(form.nativeLogs).toHaveText(logs3);
await expect(form.baseLogs).toHaveText(logs3);

Expand All @@ -164,8 +165,7 @@ test('works with keyboard events', async ({ page }) => {
createLog('change', 3),
];

// Select all text
await form.nativeInput.press('Control+a');
await selectAll(form.nativeInput);
await expect(form.nativeLogs).toHaveText(logs4);
await expect(form.baseLogs).toHaveText(logs4);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, type Locator, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground } from './helpers';

function getFieldset(form: Locator) {
const list = form.locator('fieldset');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, type Locator, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground } from './helpers';

function getFieldset(form: Locator) {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, type Locator, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground, selectAll } from './helpers';

function getUsernameInput(container: Locator) {
return container.locator('[name="username"]');
Expand All @@ -22,7 +22,7 @@ async function runTest(page: Page) {
'At least 1 number',
]);

await username.press('Control+a');
await selectAll(username);
await username.press('ArrowRight');
await username.type('C');

Expand All @@ -33,7 +33,7 @@ async function runTest(page: Page) {
'At least 1 number',
]);

await username.press('Control+a');
await selectAll(username);
await username.press('ArrowRight');
await username.type('on');
await playground.submit.click();
Expand All @@ -42,13 +42,13 @@ async function runTest(page: Page) {
'At least 1 number',
]);

await username.press('Control+a');
await selectAll(username);
await username.press('ArrowRight');
await username.type('form');
await playground.submit.click();
await expect(playground.error).toHaveText(['At least 1 number']);

await username.press('Control+a');
await selectAll(username);
await username.press('ArrowRight');
await username.type('2023');
await playground.submit.click();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, type Locator, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground } from './helpers';

function getFieldset(form: Locator) {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, type Locator, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground } from './helpers';

function getFieldset(form: Locator) {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, type Locator, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground } from './helpers';

function getFieldset(form: Locator) {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Page, type Locator, test, expect } from '@playwright/test';
import { getPlayground } from '../helpers';
import { getPlayground } from './helpers';

function getFieldset(form: Locator) {
return {
Expand Down

0 comments on commit 639cd33

Please sign in to comment.