Skip to content

Commit

Permalink
Merge pull request #6 from stagas/coverage
Browse files Browse the repository at this point in the history
test: improve coverage
  • Loading branch information
stagas authored Oct 3, 2024
2 parents c2ccb1e + 41028d2 commit c44c372
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 45 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,30 @@ jobs:
with:
deno-version: v1.x

- name: Install Bun
uses: oven-sh/setup-bun@v1

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
node-version: 22.x

- name: Install step
- name: Install dependencies
run: npm install --ignore-scripts

- name: Build step
run: npm run build
- name: Build
run: bun run build

- name: Generate .env file
uses: SpicyPizza/[email protected]
with:
envkey_DATABASE_URL: ${{ secrets.DATABASE_URL }}

- name: Run migrations
run: npm run kysely -- migrate:latest
run: bun run kysely -- migrate:latest

- name: Run tests
run: npm run test:ci:npm
run: bun run test

- name: Upload coverage deno
uses: codecov/codecov-action@v4
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,30 @@ jobs:
with:
deno-version: v1.x

- name: Install Bun
uses: oven-sh/setup-bun@v1

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
node-version: 22.x

- name: Install modules
- name: Install dependencies
run: npm install --ignore-scripts

- name: Build step
run: npm run build
- name: Build
run: bun run build

- name: Generate .env file
uses: SpicyPizza/[email protected]
with:
envkey_DATABASE_URL: ${{ env.DATABASE_URL }}

- name: Run migrations
run: npm run kysely -- migrate:latest
run: bun run kysely -- migrate:latest

- name: Run tests
run: npm run test:ci:npm
run: bun run test

- name: Upload coverage deno
uses: codecov/codecov-action@v4
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
- [x] Coverage
- [x] Unit
- [ ] Integration
- [ ] E2E
- [x] E2E
- [x] HMR
- [x] RPC
- [x] Admin
Expand Down
4 changes: 0 additions & 4 deletions api/import-map.production.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"fmt": {
"singleQuote": true,
"semiColons": false
},
"imports": {
"kysely": "npm:kysely@^0.27.4",
"pg": "npm:pg",
Expand Down
4 changes: 4 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[test]
preload = "./happydom.ts"
coverageSkipTestFiles = true
coverageReporter = ["text", "lcov"]
3 changes: 3 additions & 0 deletions happydom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { GlobalRegistrator } from "@happy-dom/global-registrator"

GlobalRegistrator.register({ url: 'https://localhost' })
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
"main": "src/client.tsx",
"scripts": {
"build": "vite build",
"test": "pnpm test:api && pnpm test:web",
"test:ci": "pnpm test:api:ci && pnpm test:web",
"test:ci:npm": "npm run test:api:ci && npm run test:web",
"test:watch": "pnpm test:api:watch & pnpm test:web:watch",
"test": "bun run test:api && bun run test:web",
"test:watch": "bun run test:api:watch & bun run test:web:watch",
"test:api": "deno test -A --no-lock api",
"test:api:ci": "deno test -A --no-lock --import-map=./api/import-map.production.json --coverage=coverage/deno api",
"test:api:cov": "deno coverage coverage/deno --lcov --output=coverage/lcov-deno.info",
"test:api:watch": "deno test -A --watch --no-lock api & deno -A --no-lock api/test-watch.ts",
"test:web": "vitest run --coverage",
"test:web:watch": "vitest --coverage",
"dev": "pnpm dev:db & pnpm dev:api & pnpm dev:web",
"test:web": "bun test --coverage src",
"test:web:watch": "bun test --coverage --watch src",
"dev": "bun run dev:db & bun run dev:api & bun run dev:web",
"dev:db": "docker compose up",
"dev:api": "deno --watch --unstable-kv -A api/core/server.ts",
"dev:web": "vite",
Expand All @@ -27,9 +25,10 @@
"postinstall": "link-local || exit 0"
},
"devDependencies": {
"@happy-dom/global-registrator": "^15.7.4",
"@maktouch/kysely-zod-codegen": "^0.5.2",
"@types/bun": "^1.1.10",
"@types/node": "^22.7.4",
"@vitest/coverage-v8": "^2.1.2",
"ambient-dts": "github:stagas/ambient-dts",
"autoprefixer": "^10.4.20",
"jsdom": "^25.0.1",
Expand All @@ -39,8 +38,7 @@
"postcss": "^8.4.47",
"tailwindcss": "^3.4.13",
"utils": "github:stagas/utils",
"vite": "^5.4.8",
"vitest": "^2.1.1"
"vite": "^5.4.8"
},
"dependencies": {
"@types/pg": "^8.11.10",
Expand Down
37 changes: 37 additions & 0 deletions src/test/e2e.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { App } from '../pages/App.tsx'
import { state } from '../state.ts'

// @ts-ignore
globalThis.fetch = () => {
return { json: () => { } }
}

describe('App', () => {
it('works', () => {
const app = <App />
expect(app).toBeInstanceOf(Element)
})

it('routes', async () => {
const app = <App />
expect(app).toBeInstanceOf(Element)
state.url = new URL('/about', location.origin)
state.url = new URL('/verify-email', location.origin)
state.url = new URL('/reset-password', location.origin)
})

it('user', async () => {
const app = <App />
expect(app).toBeInstanceOf(Element)
state.user = null
state.user = {
nick: 'foo',
expires: new Date(),
}
state.user = {
nick: 'foo',
expires: new Date(),
isAdmin: true
}
})
})
18 changes: 0 additions & 18 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="vitest" />

import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
Expand All @@ -19,22 +17,6 @@ export default ({ mode }) => {
} : undefined
return defineConfig({
clearScreen: false,
test: {
globals: true,
dir: 'src',
includeSource: ['src/**/*.{js,jsx,ts,tsx}'],
environment: 'jsdom',
coverage: {
clean: false,
cleanOnRerun: false,
include: ['src'],
reporter: ['lcovonly'],
reportsDirectory: 'coverage'
}
},
define: {
'import.meta.vitest': 'undefined',
},
server: {
host: true,
fs: {
Expand Down

0 comments on commit c44c372

Please sign in to comment.