Skip to content

Commit

Permalink
Add coverage report and tests (#12)
Browse files Browse the repository at this point in the history
* feat: add coverage

* feat: add more tests

* fix: CI setup
  • Loading branch information
bonyuta0204 authored Dec 10, 2023
1 parent 3c456c5 commit 2ec29c1
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ jobs:
- name: Install deps
run: yarn install

- name: Run Codegen for GraphQL
run: yarn run compile

- name: Test
run: yarn test
55 changes: 55 additions & 0 deletions __tests__/run.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { run } from '../src/run'

import { vi, describe, it, expect } from 'vitest'

describe('run', () => {
vi.mock('@apollo/client/index.js', () => {
class InMemoryCache {
constructor() {}
}

class AppolloClient {
constructor() {}

query() {
return {
data: {
repository: {
pullRequests: {
pageInfo: {
hasNextPage: false,
endCursor: 'endCursor'
},
edges: [
{
node: {
id: 'id'
}
}
]
}
}
}
}
}
}

return {
ApolloClient: AppolloClient,
InMemoryCache: InMemoryCache
}
})

vi.stubEnv('GITHUB_TOKEN', 'dummy-token')

it('should run', async () => {
/** we just want to ensure that `run` does not throw any errors */
expect(
await run({
owner: 'owner',
repo: 'repo',
limit: 100
})
).toBeUndefined()
})
})
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "GitHub Exporter written in typescript",
"main": "./dist/index.cjs",
"scripts": {
"prepublishOnly": "pnpm run build",
"prepublishOnly": "yarn run build",
"format:write": "prettier --write **/*.ts",
"format:check": "prettier --check **/*.ts",
"lint": "eslint .",
Expand All @@ -15,7 +15,7 @@
"compile": "graphql-codegen",
"watch": "graphql-codegen -w",
"test": "vitest",
"publish": "bumpp && pnpm publish --access=public",
"publish": "bumpp && yarn publish --access=public",
"prepare": "husky install"
},
"lint-staged": {
Expand Down Expand Up @@ -64,6 +64,8 @@
"@types/node": "^20.10.2",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"@vitest/coverage-v8": "^1.0.2",
"@vitest/ui": "^1.0.2",
"bumpp": "^9.2.0",
"eslint": "^8.55.0",
"husky": "^8.0.3",
Expand Down
22 changes: 22 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
coverage: {
enabled: true,
exclude: [
'coverage/**',
'codegen.ts',
'**/__generated__/**',
'bin/**',
'dist/**',
'**/[.]**',
'**/*.d.ts',
'**/*{.,-}{test,spec}.?(c|m)[jt]s?(x)',
'**/__tests__/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
'**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}'
]
}
}
})
Loading

0 comments on commit 2ec29c1

Please sign in to comment.