Skip to content

Commit

Permalink
Refactor test configuration and structure:
Browse files Browse the repository at this point in the history
- Updated ESLint configuration to include e2e tests.
- Changed Playwright test directory from './tests' to './e2e'.
- Adjusted TypeScript configuration to include e2e files.
- Removed obsolete test files: example.spec.ts and wallet.spec.ts.

Closes #243
  • Loading branch information
tombeckenham committed Dec 11, 2024
1 parent cd399ca commit e96e175
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 75 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Test

on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]

jobs:
test:
runs-on: ubuntu-latest

services:
flow-emulator:
image: gcr.io/flow-container-registry/emulator:latest
ports:
- 3569:3569
options: >-
--health-cmd "curl -f http://localhost:3569/v1/blocks/latest"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'

- uses: pnpm/action-setup@v2
with:
version: '9'

- name: Install dependencies
run: pnpm install

- name: Build test version
run: pnpm run build:test
env:
NODE_ENV: test

- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps chromium

- name: Run Playwright tests
run: pnpm run test:e2e
env:
NODE_ENV: test

- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30

lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'

- uses: pnpm/action-setup@v2
with:
version: '9'

- name: Install dependencies
run: pnpm install

- name: Run ESLint
run: pnpm run lint

- name: Check formatting
run: pnpm run format
33 changes: 33 additions & 0 deletions e2e/wallet.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import path from 'path';

import { test, expect, chromium } from '@playwright/test';

test('Load extension', async () => {

Check failure on line 5 in e2e/wallet.test.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

e2e/wallet.test.ts

Error: Playwright Test did not expect test() to be called here. Most common reasons include: - You are calling test() in a configuration file. - You are calling test() in a file that is imported by the configuration file. - You have two different versions of @playwright/test. This usually happens when one of the dependencies in your package.json depends on @playwright/test. ❯ TestTypeImpl._currentSuite node_modules/playwright/lib/common/testType.js:72:13 ❯ TestTypeImpl._createTest node_modules/playwright/lib/common/testType.js:78:24 ❯ Module.<anonymous> node_modules/playwright/lib/transform/transform.js:288:12 ❯ e2e/wallet.test.ts:5:1
// Get path to extension
const pathToExtension = path.join(__dirname, '../dist');

// Launch browser with extension
const context = await chromium.launchPersistentContext('/tmp/test-user-data-dir', {
headless: false,
args: [`--disable-extensions-except=${pathToExtension}`, `--load-extension=${pathToExtension}`],
});

// for manifest v3:
let [background] = context.serviceWorkers();
if (!background) background = await context.waitForEvent('serviceworker');

// Get extension ID from service worker URL
const extensionId = background.url().split('/')[2];

// Create a new page and navigate to extension
const page = await context.newPage();

// Navigate and wait for network to be idle
await page.goto(`chrome-extension://${extensionId}/index.html#/welcome`);

// Wait for the welcome page to be fully loaded
await page.waitForSelector('.welcomeBox', { state: 'visible' });

// Cleanup
await context.close();
});
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default [

// Test files specific config
{
files: ['**/*.test.{js,jsx,ts,tsx}', '**/*.spec.{js,jsx,ts,tsx}', 'playwright.config.ts'],
files: ['e2e/**/*', 'playwright.config.ts'],
languageOptions: {
parserOptions: {
project: './tsconfig.test.json',
Expand Down
22 changes: 10 additions & 12 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,29 @@ export default defineConfig({
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
reporter: process.env.CI ? 'github' : 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
video: process.env.CI ? 'on-first-retry' : 'off',
screenshot: process.env.CI ? 'only-on-failure' : 'off',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
use: {
...devices['Desktop Chrome'],
// Chrome extension testing configuration
contextOptions: {
extensionPath: './dist',
},
},
},

/* Test against mobile viewports. */
Expand Down
18 changes: 0 additions & 18 deletions tests/example.spec.ts

This file was deleted.

43 changes: 0 additions & 43 deletions tests/wallet.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "./tsconfig.json",
"include": ["tests/**/*", "playwright.config.ts"],
"include": ["e2e/**/*", "playwright.config.ts"],
"compilerOptions": {
"types": ["@playwright/test"]
}
Expand Down

0 comments on commit e96e175

Please sign in to comment.