From 47d7b46600bf49f016290249192320f154773642 Mon Sep 17 00:00:00 2001 From: carlosallexandre Date: Wed, 16 Oct 2024 11:08:11 -0300 Subject: [PATCH 1/2] chore: config e2e tests --- .github/workflows/test-e2e.yml | 29 ++++++++++++++ .gitignore | 7 +++- .npmignore | 4 ++ e2e/home.spec.ts | 6 +++ package-lock.json | 69 ++++++++++++++++++++++++++++++++-- package.json | 6 ++- playwright.config.ts | 39 +++++++++++++++++++ vitest.config.ts | 1 + 8 files changed, 155 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/test-e2e.yml create mode 100644 e2e/home.spec.ts create mode 100644 playwright.config.ts diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml new file mode 100644 index 00000000..39a67934 --- /dev/null +++ b/.github/workflows/test-e2e.yml @@ -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 diff --git a/.gitignore b/.gitignore index 264f35dd..b5758114 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,9 @@ eventcatalog.styles.css .vscode/* -git-push.sh \ No newline at end of file +git-push.sh + +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ diff --git a/.npmignore b/.npmignore index 9c7e77e5..3c0a73eb 100644 --- a/.npmignore +++ b/.npmignore @@ -21,3 +21,7 @@ __tests__/ Dockerfile .dockerignore + +# e2e +e2e/ +playwright.config.ts \ No newline at end of file diff --git a/e2e/home.spec.ts b/e2e/home.spec.ts new file mode 100644 index 00000000..9490c78d --- /dev/null +++ b/e2e/home.spec.ts @@ -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(); +}); diff --git a/package-lock.json b/package-lock.json index 637fd236..fc18add4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@eventcatalog/core", - "version": "2.8.4", + "version": "2.8.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@eventcatalog/core", - "version": "2.8.4", + "version": "2.8.5", "dependencies": { "@astrojs/check": "^0.9.4", "@astrojs/markdown-remark": "^5.3.0", @@ -58,9 +58,9 @@ }, "devDependencies": { "@changesets/cli": "^2.27.5", + "@playwright/test": "^1.48.1", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", - "@types/semver": "^7.5.8", "prettier": "^3.3.3", "prettier-plugin-astro": "^0.14.1", "rimraf": "^5.0.7", @@ -3190,6 +3190,22 @@ "node": ">=14" } }, + "node_modules/@playwright/test": { + "version": "1.48.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.48.1.tgz", + "integrity": "sha512-s9RtWoxkOLmRJdw3oFvhFbs9OJS0BzrLUc8Hf6l2UdCNd1rqeEyD4BhCJkvzeEoD1FsK4mirsWwGerhVmYKtZg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.48.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/@polka/url": { "version": "1.0.0-next.25", "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.25.tgz", @@ -17405,6 +17421,53 @@ "node": ">=8" } }, + "node_modules/playwright": { + "version": "1.48.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.48.1.tgz", + "integrity": "sha512-j8CiHW/V6HxmbntOfyB4+T/uk08tBy6ph0MpBXwuoofkSnLmlfdYNNkFTYD6ofzzlSqLA1fwH4vwvVFvJgLN0w==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.48.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.48.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.48.1.tgz", + "integrity": "sha512-Yw/t4VAFX/bBr1OzwCuOMZkY1Cnb4z/doAFSwf4huqAGWmf9eMNjmK7NiOljCdLmxeRYcGPPmcDgU0zOlzP0YA==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/playwright/node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/polished": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/polished/-/polished-4.3.1.tgz", diff --git a/package.json b/package.json index f1ce8628..5b32dd41 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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", diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 00000000..5044b800 --- /dev/null +++ b/playwright.config.ts @@ -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, + }, +}); diff --git a/vitest.config.ts b/vitest.config.ts index 07d3b332..1b7ea8d4 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -6,5 +6,6 @@ export default getViteConfig({ plugins: [tsConfigPaths()], test: { globals: true, + include: ['**/__tests__/**/*.{test,spec}.?(c|m)[jt]s?(x)'], }, }); From d22373770afc9fcd472ba03ea45422853dce70e6 Mon Sep 17 00:00:00 2001 From: David Boyne Date: Wed, 16 Oct 2024 18:09:05 +0100 Subject: [PATCH 2/2] moving to exclude --- vitest.config.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vitest.config.ts b/vitest.config.ts index 1b7ea8d4..63fc6d5e 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,11 +1,12 @@ /// import { getViteConfig } from 'astro/config'; +import { defaultExclude } from 'vitest/config'; import tsConfigPaths from 'vite-tsconfig-paths'; export default getViteConfig({ plugins: [tsConfigPaths()], test: { globals: true, - include: ['**/__tests__/**/*.{test,spec}.?(c|m)[jt]s?(x)'], + exclude: [...defaultExclude, 'e2e/**'], }, });