Skip to content

Commit

Permalink
feat(vitest): add @suspensive/vitest generating named config automati…
Browse files Browse the repository at this point in the history
…cally by packageJson.name (#131)

* feat(vitest): add @suspensive/vitest generating named config automatically by packageJson.name

* Update packages/react/vitest.config.ts

Co-authored-by: 박찬혁 <[email protected]>

* ci(.github/workflows): update

* Create dry-phones-applaud.md

---------

Co-authored-by: 박찬혁 <[email protected]>
  • Loading branch information
manudeli and okinawaa authored Sep 5, 2023
1 parent cee6b41 commit d4c4b71
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 25 deletions.
6 changes: 6 additions & 0 deletions .changeset/dry-phones-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@suspensive/react-query": patch
"@suspensive/react": patch
---

feat(vitest): add @suspensive/vitest generating named config automatically by packageJson.name
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ jobs:
cache-dependency-path: 'pnpm-lock.yaml'
node-version-file: '.nvmrc'
- run: pnpm install --frozen-lockfile
- run: pnpm build --filter=@suspensive/react --filter=@suspensive/react-query
- run: pnpm prepack
- name: Run commands
run: ${{ matrix.command }}
1 change: 1 addition & 0 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
cache-dependency-path: 'pnpm-lock.yaml'
node-version-file: '.nvmrc'
- run: pnpm install --frozen-lockfile
- run: pnpm prepack
- run: pnpm test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
Expand Down
4 changes: 2 additions & 2 deletions configs/eslint-config-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"dependencies": {
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-vitest": "0.3.1",
"eslint-plugin-prettier": "^4.2.1"
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vitest": "0.3.1"
},
"peerDependencies": {
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
Expand Down
6 changes: 6 additions & 0 deletions configs/vitest/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
extends: ['@suspensive/eslint-config-ts'],
ignorePatterns: ['*.js*', 'dist', 'coverage'],
}
13 changes: 13 additions & 0 deletions configs/vitest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@suspensive/vitest",
"version": "0.0.0",
"private": true,
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"lint": "eslint .",
"prepack": "pnpm build",
"type:check": "tsc --noEmit"
}
}
25 changes: 25 additions & 0 deletions configs/vitest/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import fs from 'fs'
import path, { dirname } from 'path'
import { UserConfig } from 'vitest/config'

export const forPackage = (userConfig?: UserConfig): UserConfig => {
const packageJsonPath = path.resolve(dirname('.'), 'package.json')
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))

return {
...userConfig,
test: {
name: packageJson.name,
dir: './src',
watch: false,
environment: 'jsdom',
globals: true,
setupFiles: './test.setup.ts',
coverage: {
provider: 'v8',
...userConfig?.test?.coverage,
},
...userConfig?.test,
},
}
}
7 changes: 7 additions & 0 deletions configs/vitest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@suspensive/tsconfig/base.json",
"include": ["./src"],
"compilerOptions": {
"outDir": "dist"
}
}
1 change: 1 addition & 0 deletions packages/react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"devDependencies": {
"@suspensive/react": "workspace:*",
"@suspensive/tsup": "workspace:*",
"@suspensive/vitest": "workspace:*",
"@tanstack/react-query": "^4.29.5",
"@types/node": "^18.16.2",
"@types/react": "^18.2.0",
Expand Down
13 changes: 2 additions & 11 deletions packages/react-query/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import { forPackage } from '@suspensive/vitest'
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
name: '@suspensive/react-query',
dir: './src',
watch: false,
environment: 'jsdom',
globals: true,
setupFiles: './test.setup.ts',
coverage: { provider: 'v8' },
},
})
export default defineConfig(forPackage())
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
},
"devDependencies": {
"@suspensive/tsup": "workspace:*",
"@suspensive/vitest": "workspace:*",
"@types/node": "^18.16.2",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.1",
Expand Down
13 changes: 2 additions & 11 deletions packages/react/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import { forPackage } from '@suspensive/vitest'
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
name: '@suspensive/react',
dir: './src',
watch: false,
environment: 'jsdom',
globals: true,
setupFiles: './test.setup.ts',
coverage: { provider: 'v8' },
},
})
export default defineConfig(forPackage())
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit d4c4b71

Please sign in to comment.