Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ dist-ssr
/helm/charts/
/apps/*/helm/charts/
*.tgz

**/coverage/
3 changes: 2 additions & 1 deletion apps/visr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"preview": "vite preview",
"relay": "relay-compiler",
"test": "vitest run",
"test:watch": "vitest"
"test:watch": "vitest",
"coverage": "vitest run --coverage"
},
"dependencies": {
"@atlas/blueapi": "workspace:*",
Expand Down
15 changes: 11 additions & 4 deletions apps/visr/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { defineConfig } from "vitest/config";
import { defineConfig, mergeConfig } from "vitest/config";
import baseConfig from "@atlas/vitest-conf/vitest.config";

export default defineConfig({
...baseConfig,
});
export default mergeConfig(
baseConfig,
defineConfig({
test: {
coverage: {
exclude: ["**/RelayEnvironment.ts"],
},
},
}),
);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@eslint/js": "^9.36.0",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.1",
"@vitest/coverage-v8": "^4.0.13",
"eslint": "^9.36.0",
"prettier": "^3.6.2",
"sort-package-json": "^3.4.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/blueapi-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
".": "./src/index.ts"
},
"scripts": {
"test": "vitest run"
"test": "vitest run",
"coverage": "vitest run --coverage"
},
"dependencies": {
"@atlas/blueapi": "workspace:*"
Expand Down
3 changes: 2 additions & 1 deletion packages/blueapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
".": "./src/index.ts"
},
"scripts": {
"test": "vitest run"
"test": "vitest run",
"coverage": "vitest run --coverage"
},
"dependencies": {
"axios": "^1.13.5"
Expand Down
52 changes: 41 additions & 11 deletions packages/vitest-conf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Shared Vitest configuration and test environment for the **Atlas** monorepo.

This package centralises all testing setup — including Vitest configuration, jsdom environment, and Testing Library matchers — so that individual apps and packages can keep their own configs minimal and consistent.

---

## Features

- Shared **Vitest** configuration via `vitest.config.ts`
Expand All @@ -14,23 +12,19 @@ This package centralises all testing setup — including Vitest configuration, j
- TypeScript definitions for `expect`, `describe`, etc.
- Central place to update dependencies like `@testing-library/*`

---

## Usage

1. add `vitest` and `@atlas/vitest-conf` as dev dependencies in `apps/my-app/package.json`:
1. Add `vitest` and `@atlas/vitest-conf` as dev dependencies:

```json
"devDependencies": {
"vitest": "*",
"@atlas/vitest-conf": "workspace:*"
}
```bash
pnpm add -D -F @atlas/myapp @atlas/vitest-conf --workspace
pnpm add -D -F @atlas/myapp vitest
```

2. Create a `vitest.config.ts` that simply reuses the shared base config:

```ts
// apps/my-app/vitest.config.ts
// apps/myapp/vitest.config.ts
import { defineConfig } from "vitest/config";
import baseConfig from "@atlas/vitest-conf/vitest.config";

Expand All @@ -50,3 +44,39 @@ export default defineConfig({
```

Comment thread
douglaswinter marked this conversation as resolved.
4. Write some tests! Vitest will find tests that match `**/*.test.{ts,tsx}`.

5. Add test and coverage Vitest scripts to your `package.json`. Turbo will run them if you call them 'test' and 'coverage':

```json
{
"scripts": {
"test": "vitest run",
"coverage": "vitest run --coverage"
}
}
```

## Coverage

Should _everything_ be covered by unit tests? `@atlas/vitest-conf` doesn't think so, and so makes some opinionated and generic exclusions for producing coverage reports. If your app needs to add to these, use `mergeConfig` in your app's `vitest.config.ts`.

Example:

```typescript
// apps/myapp/vitest.config.ts
import { defineConfig, mergeConfig } from "vitest/config";
import baseConfig from "@atlas/vitest-conf/vitest.config";

export default mergeConfig(
baseConfig,
defineConfig({
test: {
coverage: {
exclude: ["../RelayEnvironment.ts", "**/AppProviders.tsx"],
},
},
}),
);
```

If it is not a logic-bearing module, it may be OK for exclusion. Use your discretion.
2 changes: 1 addition & 1 deletion packages/vitest-conf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"devDependencies": {
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.6.4",
"@testing-library/react": "^16.3.0",
"@testing-library/react": "^15.0.1",
"@testing-library/user-event": "^14.6.1",
"@types/node": "^25.0.10",
"jsdom": "^26.1.0"
Expand Down
12 changes: 12 additions & 0 deletions packages/vitest-conf/src/vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,17 @@ export default defineConfig({
include: ["**/*.test.{ts,tsx}"],
css: false,
reporters: ["verbose"],
coverage: {
reporter: ["lcov", "json-summary", "text"],
include: ["src/**/*.{ts,tsx}"],
exclude: [
"**/*.d.ts",
"**/main.tsx",
"**/index.ts",
"**/types.ts",
"**/mocks/**",
"**/*.graphql.ts",
],
},
},
});
Loading
Loading