Skip to content

Commit

Permalink
chore/config-e2e-tests (#873)
Browse files Browse the repository at this point in the history
* chore: config e2e tests

* moving to exclude

---------

Co-authored-by: David Boyne <boyneyy123@gmail.com>
  • Loading branch information
carlosallexandre and boyney123 authored Oct 16, 2024
1 parent 4c13852 commit 0988f2f
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 6 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests e2e
on:
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: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Build catalog
shell: bash
run: |
cp $PROJECT_DIR/eventcatalog.config.js $CATALOG_DIR/eventcatalog.config.js
cp $PROJECT_DIR/eventcatalog.styles.css $CATALOG_DIR/eventcatalog.styles.css
npm run build
env:
PROJECT_DIR: ./examples/default/
CATALOG_DIR: ./
NODE_ENV: CI # Skip analytics
- name: Run tests
run: npm run test:e2e
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ eventcatalog.styles.css

.vscode/*

git-push.sh
git-push.sh

/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ __tests__/

Dockerfile
.dockerignore

# e2e
e2e/
playwright.config.ts
6 changes: 6 additions & 0 deletions e2e/home.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { test, expect } from '@playwright/test';

test('has title', async ({ page }) => {
await page.goto('/');
await expect(page.getByRole('heading', { name: 'Welcome to EventCatalog' })).toBeVisible();
});
69 changes: 66 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"prepublishOnly": "npm run build:bin",
"test": "vitest --config vitest.config.ts",
"test:ci": "node scripts/ci/test.js",
"test:e2e": "playwright test",
"start": "astro dev",
"build": "npm run scripts:hydrate-content && node scripts/analytics/log-build.js && astro build",
"build:cd": "node scripts/build-ci.js",
Expand Down Expand Up @@ -52,6 +53,7 @@
"@types/diff": "^5.2.2",
"@types/lodash.merge": "4.6.9",
"@types/node": "^20.14.2",
"@types/semver": "^7.5.8",
"astro": "^4.16.5",
"astro-expressive-code": "^0.36.1",
"astro-pagefind": "^1.6.0",
Expand All @@ -77,11 +79,11 @@
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5",
"unist-util-visit": "^5.0.0",
"uuid": "^10.0.0",
"@types/semver": "^7.5.8"
"uuid": "^10.0.0"
},
"devDependencies": {
"@changesets/cli": "^2.27.5",
"@playwright/test": "^1.48.1",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"prettier": "^3.3.3",
Expand Down
39 changes: 39 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './e2e',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* 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',
/* 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://localhost:3000', // TODO: get the port defined on eventcatalog.config.js

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
webServer: {
command: 'npm run preview',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
});
2 changes: 2 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/// <reference types="vitest" />
import { getViteConfig } from 'astro/config';
import { defaultExclude } from 'vitest/config';
import tsConfigPaths from 'vite-tsconfig-paths';

export default getViteConfig({
plugins: [tsConfigPaths()],
test: {
globals: true,
exclude: [...defaultExclude, 'e2e/**'],
},
});

0 comments on commit 0988f2f

Please sign in to comment.