From 038aaaae295eb28e1eb2c6a554cd39c9a09ad394 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Fri, 16 May 2025 14:05:03 -0600 Subject: [PATCH 1/3] chore: run unit tests over multiple runtimes --- .github/actions/setup-playwright/action.yml | 32 +++++++++++++++++ .github/workflows/tests.yml | 28 +++++++++++++++ packages/pg-parser/package.json | 11 ++++-- packages/pg-parser/vitest.workspace.js | 24 +++++++++++++ pnpm-lock.yaml | 40 ++++++++++++++++++--- 5 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 .github/actions/setup-playwright/action.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/actions/setup-playwright/action.yml b/.github/actions/setup-playwright/action.yml new file mode 100644 index 0000000..9616178 --- /dev/null +++ b/.github/actions/setup-playwright/action.yml @@ -0,0 +1,32 @@ +name: 'Setup and Cache Playwright' +description: 'Installs playwright browsers and caches them.' + +inputs: + version: + description: 'The version of playwright' + required: true + +outputs: + cache-hit: + description: 'Whether the cache was hit or not' + value: ${{ steps.playwright-cache.outputs.cache-hit }} + +runs: + using: 'composite' + steps: + - name: Cache playwright browsers + id: playwright-cache + uses: actions/cache@v4 + with: + key: playwright-browsers-${{ runner.os }}-${{ inputs.version }} + path: ~/.cache/ms-playwright + + - name: Install playwright browsers if they don't exist + shell: bash + run: npx playwright install --with-deps + if: steps.playwright-cache.outputs.cache-hit != 'true' + + - name: Install playwright dependencies if binaries exist + shell: bash + run: npx playwright install-deps + if: steps.playwright-cache.outputs.cache-hit == 'true' diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..aa224f6 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,28 @@ +name: Tests +on: + push: + branches: [main] + pull_request: + branches: [main] +jobs: + test: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + cache: 'npm' + - name: Install dependencies + run: npm ci --ignore-scripts + - name: Build libs + run: npm run build + - name: Get playwright version + run: echo "PLAYWRIGHT_VERSION=$(npm ls @playwright/test | grep @playwright | sed 's/.*@//')" >> $GITHUB_ENV + - name: Setup playwright + uses: ./.github/actions/setup-playwright + with: + version: ${{ env.PLAYWRIGHT_VERSION }} + - name: Tests + run: npm run test diff --git a/packages/pg-parser/package.json b/packages/pg-parser/package.json index 1ba7547..a5bc84d 100644 --- a/packages/pg-parser/package.json +++ b/packages/pg-parser/package.json @@ -18,7 +18,10 @@ "wasm-opt": "docker compose run --rm binaryen wasm-opt -Oz --enable-bulk-memory pg-parser.wasm -o pg-parser.min.wasm", "wasm-objdump": "docker compose run --rm wabt wasm-objdump", "prepublishOnly": "pnpm build", - "test": "vitest" + "test": "vitest", + "test:unit:node": "vitest --project unit:node", + "test:unit:vercel-edge": "vitest --project unit:vercel-edge", + "test:unit:browser": "vitest --project unit:browser" }, "files": [ "dist/**/*" @@ -34,10 +37,12 @@ "@bjorn3/browser_wasi_shim": "^0.4.1" }, "devDependencies": { + "@edge-runtime/vm": "^5.0.0", + "@playwright/test": "^1.52.0", "@total-typescript/tsconfig": "^1.0.4", "@types/common-tags": "^1.8.4", "@types/node": "^22.15.3", - "@vitest/browser": "^3.1.1", + "@vitest/browser": "^3.1.3", "common-tags": "^1.8.2", "mkdirp": "^3.0.1", "pg-proto-parser": "^1.24.0", @@ -46,6 +51,6 @@ "tsup": "^8.3.5", "typescript": "^5.6.3", "vite": "^6.3.2", - "vitest": "^3.1.1" + "vitest": "^3.1.3" } } diff --git a/packages/pg-parser/vitest.workspace.js b/packages/pg-parser/vitest.workspace.js index 4012d90..95b0f71 100644 --- a/packages/pg-parser/vitest.workspace.js +++ b/packages/pg-parser/vitest.workspace.js @@ -8,4 +8,28 @@ export default defineWorkspace([ include: ['src/**/*.{test,spec}.ts'], }, }, + { + test: { + name: 'unit:vercel-edge', + environment: 'edge-runtime', + include: ['src/**/*.{test,spec}.ts'], + }, + }, + { + test: { + name: 'unit:browser', + include: ['src/**/*.{test,spec}.ts'], + browser: { + enabled: true, + provider: 'playwright', + headless: true, + screenshotFailures: false, + instances: [ + { browser: 'chromium' }, + { browser: 'firefox' }, + { browser: 'webkit' }, + ], + }, + }, + }, ]); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e471b1a..70300b2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,12 @@ importers: specifier: ^0.4.1 version: 0.4.1 devDependencies: + '@edge-runtime/vm': + specifier: ^5.0.0 + version: 5.0.0 + '@playwright/test': + specifier: ^1.52.0 + version: 1.52.0 '@total-typescript/tsconfig': specifier: ^1.0.4 version: 1.0.4 @@ -24,7 +30,7 @@ importers: specifier: ^22.15.3 version: 22.15.17 '@vitest/browser': - specifier: ^3.1.1 + specifier: ^3.1.3 version: 3.1.3(playwright@1.52.0)(vite@6.3.5(@types/node@22.15.17))(vitest@3.1.3) common-tags: specifier: ^1.8.2 @@ -51,8 +57,8 @@ importers: specifier: ^6.3.2 version: 6.3.5(@types/node@22.15.17) vitest: - specifier: ^3.1.1 - version: 3.1.3(@types/node@22.15.17)(@vitest/browser@3.1.3) + specifier: ^3.1.3 + version: 3.1.3(@edge-runtime/vm@5.0.0)(@types/node@22.15.17)(@vitest/browser@3.1.3) packages: @@ -116,6 +122,14 @@ packages: '@bjorn3/browser_wasi_shim@0.4.1': resolution: {integrity: sha512-54kpBQX69TZ8I1zyDC8sziv/zPT1zoIadv3CmdIZNZ5WDF1houMjAzRZ3dwWvhXObiEBjOxXyS8Ja7vA0EfGEQ==} + '@edge-runtime/primitives@6.0.0': + resolution: {integrity: sha512-FqoxaBT+prPBHBwE1WXS1ocnu/VLTQyZ6NMUBAdbP7N2hsFTTxMC/jMu2D/8GAlMQfxeuppcPuCUk/HO3fpIvA==} + engines: {node: '>=18'} + + '@edge-runtime/vm@5.0.0': + resolution: {integrity: sha512-NKBGBSIKUG584qrS1tyxVpX/AKJKQw5HgjYEnPLC0QsTw79JrGn+qUr8CXFb955Iy7GUdiiUv1rJ6JBGvaKb6w==} + engines: {node: '>=18'} + '@esbuild/aix-ppc64@0.25.4': resolution: {integrity: sha512-1VCICWypeQKhVbE9oW/sJaAmjLxhVqacdkvPLEjwlttjfwENRSClS8EjBz0KzRyFSCPDIkuXW34Je/vk7zdB7Q==} engines: {node: '>=18'} @@ -296,6 +310,11 @@ packages: resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} + '@playwright/test@1.52.0': + resolution: {integrity: sha512-uh6W7sb55hl7D6vsAeA+V2p5JnlAqzhqFyF0VcJkKZXkgnFcVG9PziERRHQfPLfNGx1C292a4JqbWzhR8L4R1g==} + engines: {node: '>=18'} + hasBin: true + '@polka/url@1.0.0-next.29': resolution: {integrity: sha512-wwQAWhWSuHaag8c4q/KN/vCoeOJYshAIvMQwD4GpSb3OiZklFfvAgmj0VCBBImRpuF/aFgIRzllXlVX93Jevww==} @@ -1227,6 +1246,12 @@ snapshots: '@bjorn3/browser_wasi_shim@0.4.1': {} + '@edge-runtime/primitives@6.0.0': {} + + '@edge-runtime/vm@5.0.0': + dependencies: + '@edge-runtime/primitives': 6.0.0 + '@esbuild/aix-ppc64@0.25.4': optional: true @@ -1346,6 +1371,10 @@ snapshots: '@pkgjs/parseargs@0.11.0': optional: true + '@playwright/test@1.52.0': + dependencies: + playwright: 1.52.0 + '@polka/url@1.0.0-next.29': {} '@protobufjs/aspromise@1.1.2': {} @@ -1467,7 +1496,7 @@ snapshots: magic-string: 0.30.17 sirv: 3.0.1 tinyrainbow: 2.0.0 - vitest: 3.1.3(@types/node@22.15.17)(@vitest/browser@3.1.3) + vitest: 3.1.3(@edge-runtime/vm@5.0.0)(@types/node@22.15.17)(@vitest/browser@3.1.3) ws: 8.18.2 optionalDependencies: playwright: 1.52.0 @@ -2049,7 +2078,7 @@ snapshots: '@types/node': 22.15.17 fsevents: 2.3.3 - vitest@3.1.3(@types/node@22.15.17)(@vitest/browser@3.1.3): + vitest@3.1.3(@edge-runtime/vm@5.0.0)(@types/node@22.15.17)(@vitest/browser@3.1.3): dependencies: '@vitest/expect': 3.1.3 '@vitest/mocker': 3.1.3(vite@6.3.5(@types/node@22.15.17)) @@ -2073,6 +2102,7 @@ snapshots: vite-node: 3.1.3(@types/node@22.15.17) why-is-node-running: 2.3.0 optionalDependencies: + '@edge-runtime/vm': 5.0.0 '@types/node': 22.15.17 '@vitest/browser': 3.1.3(playwright@1.52.0)(vite@6.3.5(@types/node@22.15.17))(vitest@3.1.3) transitivePeerDependencies: From b33280bb056f226c1e516033ce3cef64f14354f6 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Fri, 16 May 2025 14:18:34 -0600 Subject: [PATCH 2/3] fix(ci): replace npm with pnpm --- .github/workflows/tests.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index aa224f6..763f824 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,19 +10,23 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + name: Install pnpm + with: + run_install: false - uses: actions/setup-node@v4 with: node-version: lts/* - cache: 'npm' + cache: 'pnpm' - name: Install dependencies - run: npm ci --ignore-scripts + run: pnpm install - name: Build libs - run: npm run build + run: pnpm run build - name: Get playwright version - run: echo "PLAYWRIGHT_VERSION=$(npm ls @playwright/test | grep @playwright | sed 's/.*@//')" >> $GITHUB_ENV + run: echo "PLAYWRIGHT_VERSION=$(pnpm list @playwright/test | grep @playwright/test | awk '{print $2}')" >> $GITHUB_ENV - name: Setup playwright uses: ./.github/actions/setup-playwright with: version: ${{ env.PLAYWRIGHT_VERSION }} - name: Tests - run: npm run test + run: pnpm run test From d7d672153d3eeb65dd3d40b64943658038e1fa5a Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Fri, 16 May 2025 14:24:53 -0600 Subject: [PATCH 3/3] fix: set pnpm in packageManager field --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 28abc1d..1869ff0 100644 --- a/package.json +++ b/package.json @@ -2,5 +2,6 @@ "scripts": { "build": "pnpm --filter @supabase/pg-parser build", "test": "pnpm --filter @supabase/pg-parser test" - } + }, + "packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977" }