Skip to content

Commit

Permalink
💚 coverage and one describe
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Aug 21, 2024
1 parent a32d8ae commit bfb9d52
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ jobs:
env:
NUXT_UI_PRO_LICENSE: ${{ secrets.NUXT_UI_PRO_LICENSE }}
NODE_ENV: test
run: pnpm run test
run: pnpm run test:coverage
if: always()
uses: davelosert/vitest-coverage-report-action@v2
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ logs
!.env.example
!.env.test
!.env.test-action


# Coverage
app/coverage
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"test:dev": "DEVRUN=true vitest run",
"test:reset": "pnpm run db:test:reset; vitest run",
"db:test:reset": "dotenv -e .env.test -- npx prisma migrate reset --force",
"test:coverage": "vitest run --coverage.enabled true",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"lint:action": "pnpm run lint -f @jamesacarr/github-actions"
Expand All @@ -32,6 +33,7 @@
"@prisma/client": "^5.18.0",
"@prisma/nuxt": "^0.0.35",
"@types/ua-parser-js": "^0.7.39",
"@vitest/coverage-v8": "^2.0.5",
"dotenv-cli": "^7.4.2",
"happy-dom": "^14.12.3",
"nuxt": "^3.12.4",
Expand Down
97 changes: 97 additions & 0 deletions pnpm-lock.yaml

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

16 changes: 5 additions & 11 deletions test/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@ const users = [
},
]

beforeAll(async () => {
await setupUsers()
})
beforeAll(setupUsers)

async function setupDev() {
function setupConfig() {
if (process.env.DEVRUN === 'true' && !process.env.CI)
await setup({ host: 'http://localhost:3000' })

return { host: 'http://localhost:3000' }
else
await setup()
return {}
}

async function setupUsers() {
Expand All @@ -59,7 +56,7 @@ async function actingAs(email: string) {
}

describe('/api/me', async () => {
await setupDev()
await setup(setupConfig())
it('should 401', async () => {
try { await $fetch('/api/me') }
catch (error: any) {
Expand All @@ -72,10 +69,7 @@ describe('/api/me', async () => {
const response = await get('/api/me') as MetapiResponse<User>
expect(response.data.email).toEqual(users[0]?.session.email)
})
})

describe('/api/user', async () => {
await setupDev()
it ('should 404 if a non-admin accesses it', async () => {
try {
await (await actingAs('[email protected]')).get('/api/user')
Expand Down
4 changes: 4 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ export default defineVitestConfig({
},
},
},
coverage: {
reporter: ['text', 'json-summary', 'json'],
reportOnFailure: true,
},
},
})

0 comments on commit bfb9d52

Please sign in to comment.