Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/easy-experts-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cleeviox/biome": patch
---

Update biome docs.
5 changes: 5 additions & 0 deletions .changeset/rich-socks-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cleeviox/vitest": minor
---

Initial release of @cleeviox/vitest package. Includes configuration for several types of projects.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
| [@cleeviox/biome](./packages/biome/README.md) | Biome configurations for linting and formatting |
| [@cleeviox/tsconfig](./packages/tsconfig/README.md) | TypeScript configurations for various project types |
| [@cleeviox/lint-staged](./packages/lint-staged/README.md) | Lint-staged configurations for pre-commit hooks |
| [@cleeviox/vitest](./packages/vitest/README.md) | Vitest configurations for testing |

## Getting Started

Expand Down
1 change: 0 additions & 1 deletion biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
}
}
],

"vcs": {
"clientKind": "git",
"enabled": true,
Expand Down
428 changes: 427 additions & 1 deletion bun.lock

Large diffs are not rendered by default.

48 changes: 28 additions & 20 deletions packages/biome/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,38 @@ bun biome check --write .

First install the official VSCode extension.

It is recommended to install `biome` globally for seamless integration with `biome`'s LSP.

```bash
brew install biome
```

Add the following settings to your `settings.json` file:

```json
{
"editor.codeActionsOnSave": {
"source.action.useSortedKeys.biome": "explicit",
"source.fixAll.biome": "explicit"
},
"editor.defaultFormatter": "biomejs.biome",
"[github-actions-workflow]": {
"editor.defaultFormatter": "redhat.vscode-yaml"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[jsonc]": {
"editor.defaultFormatter": "biomejs.biome"
}
{
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnSave": true,
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[javascriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[jsonc]": {
"editor.defaultFormatter": "biomejs.biome"
}
}
}
```

Expand Down
100 changes: 100 additions & 0 deletions packages/vitest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<div align="center">

<a href="https://github.com/cleevio/cleeviox-toolkit">
<img alt="CleevioX Logo" src="https://media.licdn.com/dms/image/v2/D4E0BAQGEw-d0KstvqA/company-logo_200_200/company-logo_200_200/0/1739267861557/cleeviox_logo?e=1770249600&v=beta&t=8t9CF4oPTbILP9z4SBOcq0AIY8UcV5baTp3sTxHJew8" width="120" style="background-color: #151a1d; padding: 15px" />
</a>

# VITEST

[![NPM Version](https://img.shields.io/npm/v/%40cleeviox%2Fvitest)](https://www.npmjs.com/package/@cleeviox/vitest)

### Vitest configuration used on CleevioX projects

</div>

## Installation

```bash
bun add --dev @cleeviox/vitest vitest
```

### Optional peer dependencies

Depending on your use case, you may need to install additional peer dependencies:

```bash
# For coverage reporting
bun add --dev @vitest/coverage-v8

# For JSX/React testing (jsdom environment)
bun add --dev jsdom
```

## Usage

Create a `vitest.config.ts` file in your project root and extend one of the available configurations:

### Base

Suitable for general TypeScript/Node.js projects.

```typescript
import { base as default } from '@cleeviox/vitest/base';
```

This configuration includes:
- Node environment
- V8 coverage provider with cobertura, html, lcov, and text reporters
- Coverage for `src/**/*.ts` files

### JSX

For React/JSX projects with jsdom environment.

```typescript
import { jsx as default } from '@cleeviox/vitest';
```

This configuration includes:
- React plugin for JSX support
- jsdom environment
- V8 coverage provider
- Coverage for `src/**/*.{ts,tsx}` files
- Setup file at `tests/setup.ts`

### NestJS

For NestJS projects with SWC compilation.

```typescript
import { nestjs as default } from '@cleeviox/vitest';
```

This configuration includes:
- SWC plugin for fast compilation
- Path alias resolution for `src` directory
- Global test APIs enabled

## Running Tests

After setting up your configuration, you can run Vitest commands:

```bash
# Run tests
bun vitest

# Run tests in watch mode
bun vitest --watch

# Run tests with coverage
bun vitest --coverage

# Run tests once (CI mode)
bun vitest run
```

## Notes

- All configurations use the V8 coverage provider for fast and accurate coverage reporting
- The JSX configuration requires a `tests/setup.ts` file for test setup (e.g., testing-library cleanup)
- The NestJS configuration uses SWC for faster compilation compared to TypeScript
27 changes: 27 additions & 0 deletions packages/vitest/biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "https://biomejs.dev/schemas/2.3.11/schema.json",
"extends": "//",
"overrides": [
{
"includes": ["./src/nestjs.ts"],
"linter": {
"rules": {
"correctness": {
"noNodejsModules": "off"
}
}
}
},
{
"includes": ["./src/index.ts"],
"linter": {
"rules": {
"performance": {
"noBarrelFile": "off",
"noReExportAll": "off"
}
}
}
}
]
}
9 changes: 9 additions & 0 deletions packages/vitest/lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { workspace } from '@cleeviox/lint-staged';

/**
* @filename: lint-staged.config.js
* @type {import('lint-staged').Configuration}
*/
export default {
...workspace,
};
83 changes: 83 additions & 0 deletions packages/vitest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"bugs": {
"url": "https://github.com/cleevio/cleeviox-toolkit/issues"
},
"dependencies": {
"@swc/core": "^1.15.8",
"@vitejs/plugin-react": "^5.1.2",
"unplugin-swc": "^1.5.9",
"vite": "^7.3.1"
},
"description": "Vitest configuration used on CleevioX projects",
"devDependencies": {
"@vitest/coverage-v8": "^4.0.17",
"jsdom": "^27.4.0",
"vitest": "^4.0.17"
},
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./base": {
"import": "./dist/base.js",
"types": "./dist/base.d.ts"
},
"./coverage": {
"import": "./dist/coverage.js",
"types": "./dist/coverage.d.ts"
},
"./jsx": {
"import": "./dist/jsx.js",
"types": "./dist/jsx.d.ts"
},
"./nestjs": {
"import": "./dist/nestjs.js",
"types": "./dist/nestjs.d.ts"
}
},
"files": [
"dist"
],
"keywords": [
"vitest",
"config",
"cleevio",
"cleeviox"
],
"name": "@cleeviox/vitest",
"peerDependencies": {
"@vitest/coverage-v8": "^4.0.17",
"jsdom": "^27.4.0",
"vitest": "^4.0.17"
},
"peerDependenciesMeta": {
"@vitest/coverage-v8": {
"optional": true
},
"jsdom": {
"optional": true
}
},
"repository": {
"directory": "packages/vitest",
"type": "git",
"url": "https://github.com/cleevio/cleeviox-toolkit"
},
"scripts": {
"build": "tsc --build tsconfig.build.json",
"check": "biome check --write .",
"clean": "del .turbo tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo dist node_modules",
"fix": "run-s biome:check:fix ts",
"format": "biome format .",
"format:fix": "biome format --write .",
"lint": "biome lint .",
"lint:fix": "biome lint --write .",
"prebuild": "del dist tsconfig.build.tsbuildinfo",
"ts": "tsc --build tsconfig.json"
},
"sideEffects": false,
"type": "module",
"types": "./dist/index.d.ts",
"version": "0.0.0"
}
13 changes: 13 additions & 0 deletions packages/vitest/src/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from 'vitest/config';

import { coverage } from './coverage.js';

export const base = defineConfig({
test: {
coverage: {
...coverage,
include: ['src/**/*.ts'],
},
environment: 'node',
},
});
6 changes: 6 additions & 0 deletions packages/vitest/src/coverage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { CoverageOptions } from 'vitest/node';

export const coverage = {
provider: 'v8',
reporter: ['cobertura', 'html', 'lcovonly', 'text'],
} satisfies CoverageOptions;
4 changes: 4 additions & 0 deletions packages/vitest/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './base.js';
export * from './coverage.js';
export * from './jsx.js';
export * from './nestjs.js';
16 changes: 16 additions & 0 deletions packages/vitest/src/jsx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vitest/config';

import { coverage } from './coverage.js';

export const jsx = defineConfig({
plugins: [react()],
test: {
coverage: {
...coverage,
include: ['src/**/*.{ts,tsx}'],
},
environment: 'jsdom',
setupFiles: ['tests/setup.ts'],
},
});
23 changes: 23 additions & 0 deletions packages/vitest/src/nestjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import path from 'node:path';
import swc from 'unplugin-swc';
import { defineConfig } from 'vitest/config';

export const nestjs = defineConfig({
plugins: [
// This is required to build the test files with SWC
swc.vite({
// Explicitly set the module type to avoid inheriting this value from a `.swcrc` config file
module: { type: 'es6' },
}),
],
resolve: {
alias: {
// Ensure Vitest correctly resolves TypeScript path aliases
src: path.resolve(__dirname, './src'),
},
},
test: {
globals: true,
root: './',
},
});
10 changes: 10 additions & 0 deletions packages/vitest/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"noEmit": false,
"outDir": "./dist",
"rootDir": "./src"
},
"extends": "./tsconfig.json",
"include": ["./src"],
"references": []
}
6 changes: 6 additions & 0 deletions packages/vitest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"exclude": ["dist", "node_modules"],
"extends": "@cleeviox/tsconfig/library",
"include": ["**/*.js", "**/*.ts"],
"references": []
}