diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index abb90fc65..3846abaee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,26 +20,24 @@ on: jobs: test: - name: Test / OS ${{ matrix.os }} / Node ${{ matrix.node }} + name: Unit + Type Check / Node.js ${{ matrix.node }} + runs-on: ubuntu-latest strategy: matrix: - os: [ubuntu-latest] - node: ['20'] - - runs-on: ${{ matrix.os }} - + node: [20] steps: - uses: actions/checkout@v4 - - - name: Set up Node - uses: actions/setup-node@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - - name: Run tests - run: | - npm clean-install - npm run test:coverage + - run: npm clean-install + + - name: Type Check + run: npm run test:types + + - name: Run Unit Tests + Coverage + run: npm run test:coverage - name: Upload coverage results to Coveralls uses: coverallsapp/github-action@master @@ -47,60 +45,89 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} path-to-lcov: ./test/coverage/lcov.info - integration: - name: Integration / OS ${{ matrix.os }} / Node ${{ matrix.node }} / Deno ${{ matrix.deno }} + deno-tests: + name: Deno Tests / ${{ matrix.deno }} + runs-on: ubuntu-latest strategy: matrix: - os: [ubuntu-latest] - node: ['20'] deno: ['1.x', '2.x'] - - runs-on: ${{ matrix.os }} - steps: - uses: actions/checkout@v4 - - - name: Set up Node - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node }} - - uses: denoland/setup-deno@v2 with: deno-version: ${{ matrix.deno }} - - - name: Setup Supabase - uses: supabase/setup-cli@v1 + - uses: supabase/setup-cli@v1 with: version: latest - name: Start Supabase - run: | - supabase start + run: supabase start - - name: Build + - name: Run Deno Tests run: | npm clean-install npm run build + cd test/deno + npm install + npm test || npm test - - name: Run tests + - name: Run integration and browser tests on Deno 2.x only if: ${{ matrix.deno == '2.x' }} run: | npm run test:integration || npm run test:integration npm run test:integration:browser - - name: Run Deno tests + - name: Stop Supabase + run: supabase stop + + node-integration: + name: Node Integration + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - uses: supabase/setup-cli@v1 + with: + version: latest + + - name: Start Supabase + run: supabase start + + - name: Run integration tests run: | - cd test/deno - npm test || npm test + npm clean-install + npm run build + npm run test:integration || npm run test:integration - - name: Next.js Integration Tests + - name: Stop Supabase + run: supabase stop + + next-integration: + name: Next.js Integration + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - uses: supabase/setup-cli@v1 + with: + version: latest + + - name: Start Supabase + run: supabase start + + - name: Install Playwright browsers and dependencies + run: npx playwright install --with-deps + + - name: Run integration tests run: | cd test/integration/next npm install npx playwright install - npm run test + npm run test - name: Stop Supabase - run: | - supabase stop + run: supabase stop diff --git a/package.json b/package.json index f696f37e8..01365b4b8 100644 --- a/package.json +++ b/package.json @@ -31,13 +31,12 @@ "test": "run-s test:types test:run", "test:all": "run-s test:types test:run test:integration test:integration:browser", "test:run": "jest --runInBand --detectOpenHandles", + "test:unit": "jest --runInBand --detectOpenHandles test/unit", "test:coverage": "jest --runInBand --coverage --testPathIgnorePatterns=\"test/integration.*|test/deno.*\"", "test:integration": "jest --runInBand --detectOpenHandles test/integration.test.ts", "test:integration:browser": "deno test --allow-all test/integration.browser.test.ts", - "test:db": "cd infra/db && docker-compose down && docker-compose up -d && sleep 5", "test:watch": "jest --watch --verbose false --silent false", - "test:clean": "cd infra/db && docker-compose down", - "test:types": "run-s build:module && tsd --files test/*.test-d.ts", + "test:types": "run-s build:module && tsd --files test/types/*.test-d.ts", "docs": "typedoc --entryPoints src/index.ts --out docs/v2 --includes src/**/*.ts", "docs:json": "typedoc --entryPoints src/index.ts --includes src/**/*.ts --json docs/v2/spec.json --excludeExternals", "serve:coverage": "npm run test:coverage && serve test/coverage" diff --git a/test/index.test-d.ts b/test/types/index.test-d.ts similarity index 96% rename from test/index.test-d.ts rename to test/types/index.test-d.ts index 9a648da69..0ae3fc354 100644 --- a/test/index.test-d.ts +++ b/test/types/index.test-d.ts @@ -1,6 +1,6 @@ import { expectError, expectType } from 'tsd' -import { PostgrestSingleResponse, createClient } from '../src/index' -import { Database, Json } from './types' +import { PostgrestSingleResponse, createClient } from '../../src/index' +import { Database, Json } from '../types' const URL = 'http://localhost:3000' const KEY = 'some.fake.key' diff --git a/test/SupabaseAuthClient.test.ts b/test/unit/SupabaseAuthClient.test.ts similarity index 83% rename from test/SupabaseAuthClient.test.ts rename to test/unit/SupabaseAuthClient.test.ts index 2cbee81ab..f6800406f 100644 --- a/test/SupabaseAuthClient.test.ts +++ b/test/unit/SupabaseAuthClient.test.ts @@ -1,6 +1,6 @@ -import { SupabaseAuthClient } from '../src/lib/SupabaseAuthClient' -import SupabaseClient from '../src/SupabaseClient' -import { DEFAULT_HEADERS } from '../src/lib/constants' +import { SupabaseAuthClient } from '../../src/lib/SupabaseAuthClient' +import SupabaseClient from '../../src/SupabaseClient' +import { DEFAULT_HEADERS } from '../../src/lib/constants' const DEFAULT_OPTIONS = { auth: { diff --git a/test/SupabaseClient.test.ts b/test/unit/SupabaseClient.test.ts similarity index 98% rename from test/SupabaseClient.test.ts rename to test/unit/SupabaseClient.test.ts index 5d14fe24b..5e0783e57 100644 --- a/test/SupabaseClient.test.ts +++ b/test/unit/SupabaseClient.test.ts @@ -1,6 +1,6 @@ import { PostgrestClient } from '@supabase/postgrest-js' -import { createClient, SupabaseClient } from '../src/index' -import { Database } from './types' +import { createClient, SupabaseClient } from '../../src/index' +import { Database } from '../types' const URL = 'http://localhost:3000' const KEY = 'some.fake.key' diff --git a/test/constants.test.ts b/test/unit/constants.test.ts similarity index 86% rename from test/constants.test.ts rename to test/unit/constants.test.ts index 57b1ae14b..814c75b87 100644 --- a/test/constants.test.ts +++ b/test/unit/constants.test.ts @@ -1,5 +1,5 @@ -import { DEFAULT_HEADERS } from '../src/lib/constants' -import { version } from '../src/lib/version' +import { DEFAULT_HEADERS } from '../../src/lib/constants' +import { version } from '../../src/lib/version' test('it has the correct type of returning with the correct value', () => { let JS_ENV = '' diff --git a/test/helper.test.ts b/test/unit/helper.test.ts similarity index 93% rename from test/helper.test.ts rename to test/unit/helper.test.ts index f4c8c3843..6e3ba431c 100644 --- a/test/helper.test.ts +++ b/test/unit/helper.test.ts @@ -1,4 +1,4 @@ -import { ensureTrailingSlash } from '../src/lib/helpers' +import { ensureTrailingSlash } from '../../src/lib/helpers' test('Adds trailing slash to URL if missing', () => { const input = 'http://localhost:3000' diff --git a/test/helpers.test.ts b/test/unit/helpers.test.ts similarity index 91% rename from test/helpers.test.ts rename to test/unit/helpers.test.ts index dd983f531..9f72bd9ed 100644 --- a/test/helpers.test.ts +++ b/test/unit/helpers.test.ts @@ -1,5 +1,5 @@ -import * as helpers from '../src/lib/helpers' -import { DEFAULT_HEADERS } from '../src/lib/constants' +import * as helpers from '../../src/lib/helpers' +import { DEFAULT_HEADERS } from '../../src/lib/constants' test('uuid', async () => { expect(helpers.uuid()).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)