From d4c4b71c2bf11fa6b9787d7c1455297686fb71a9 Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Wed, 6 Sep 2023 00:41:54 +0900 Subject: [PATCH] feat(vitest): add @suspensive/vitest generating named config automatically by packageJson.name (#131) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(vitest): add @suspensive/vitest generating named config automatically by packageJson.name * Update packages/react/vitest.config.ts Co-authored-by: 박찬혁 * ci(.github/workflows): update * Create dry-phones-applaud.md --------- Co-authored-by: 박찬혁 --- .changeset/dry-phones-applaud.md | 6 ++++++ .github/workflows/ci.yml | 2 +- .github/workflows/code-coverage.yml | 1 + configs/eslint-config-js/package.json | 4 ++-- configs/vitest/.eslintrc.cjs | 6 ++++++ configs/vitest/package.json | 13 +++++++++++++ configs/vitest/src/index.ts | 25 +++++++++++++++++++++++++ configs/vitest/tsconfig.json | 7 +++++++ packages/react-query/package.json | 1 + packages/react-query/vitest.config.ts | 13 ++----------- packages/react/package.json | 1 + packages/react/vitest.config.ts | 13 ++----------- pnpm-lock.yaml | 8 ++++++++ 13 files changed, 75 insertions(+), 25 deletions(-) create mode 100644 .changeset/dry-phones-applaud.md create mode 100644 configs/vitest/.eslintrc.cjs create mode 100644 configs/vitest/package.json create mode 100644 configs/vitest/src/index.ts create mode 100644 configs/vitest/tsconfig.json diff --git a/.changeset/dry-phones-applaud.md b/.changeset/dry-phones-applaud.md new file mode 100644 index 000000000..063d9c9b6 --- /dev/null +++ b/.changeset/dry-phones-applaud.md @@ -0,0 +1,6 @@ +--- +"@suspensive/react-query": patch +"@suspensive/react": patch +--- + +feat(vitest): add @suspensive/vitest generating named config automatically by packageJson.name diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3da300282..aefc99ce0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index 7aae27c65..d551fea54 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -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 diff --git a/configs/eslint-config-js/package.json b/configs/eslint-config-js/package.json index aa334e5d4..6f2d326fa 100644 --- a/configs/eslint-config-js/package.json +++ b/configs/eslint-config-js/package.json @@ -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" diff --git a/configs/vitest/.eslintrc.cjs b/configs/vitest/.eslintrc.cjs new file mode 100644 index 000000000..1c8a0da6e --- /dev/null +++ b/configs/vitest/.eslintrc.cjs @@ -0,0 +1,6 @@ +/** @type {import('eslint').Linter.Config} */ +module.exports = { + root: true, + extends: ['@suspensive/eslint-config-ts'], + ignorePatterns: ['*.js*', 'dist', 'coverage'], +} diff --git a/configs/vitest/package.json b/configs/vitest/package.json new file mode 100644 index 000000000..29f165e16 --- /dev/null +++ b/configs/vitest/package.json @@ -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" + } +} diff --git a/configs/vitest/src/index.ts b/configs/vitest/src/index.ts new file mode 100644 index 000000000..441f53998 --- /dev/null +++ b/configs/vitest/src/index.ts @@ -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, + }, + } +} diff --git a/configs/vitest/tsconfig.json b/configs/vitest/tsconfig.json new file mode 100644 index 000000000..393dd191d --- /dev/null +++ b/configs/vitest/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "@suspensive/tsconfig/base.json", + "include": ["./src"], + "compilerOptions": { + "outDir": "dist" + } +} diff --git a/packages/react-query/package.json b/packages/react-query/package.json index 91fbe0f11..1dd956836 100644 --- a/packages/react-query/package.json +++ b/packages/react-query/package.json @@ -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", diff --git a/packages/react-query/vitest.config.ts b/packages/react-query/vitest.config.ts index a4fd818c4..fc20065cc 100644 --- a/packages/react-query/vitest.config.ts +++ b/packages/react-query/vitest.config.ts @@ -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()) diff --git a/packages/react/package.json b/packages/react/package.json index 56ca0fb3a..571b1ca36 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -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", diff --git a/packages/react/vitest.config.ts b/packages/react/vitest.config.ts index 7b44bb027..fc20065cc 100644 --- a/packages/react/vitest.config.ts +++ b/packages/react/vitest.config.ts @@ -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()) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 12096e720..a8f787d52 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -154,11 +154,16 @@ importers: specifier: ^7.1.0 version: 7.1.0(ts-node@10.9.1)(typescript@5.1.6) + configs/vitest: {} + packages/react: devDependencies: '@suspensive/tsup': specifier: workspace:* version: link:../../configs/tsup + '@suspensive/vitest': + specifier: workspace:* + version: link:../../configs/vitest '@types/node': specifier: ^18.16.2 version: 18.16.2 @@ -186,6 +191,9 @@ importers: '@suspensive/tsup': specifier: workspace:* version: link:../../configs/tsup + '@suspensive/vitest': + specifier: workspace:* + version: link:../../configs/vitest '@tanstack/react-query': specifier: ^4.29.5 version: 4.29.5(react-dom@18.2.0)(react@18.2.0)