From 80a706a1686741ff3c3772cb8e0c515c83ddefe4 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Tue, 17 Oct 2023 10:24:07 +0200 Subject: [PATCH 1/9] fix(expect): publish semantically correct chai types (#4322) --- packages/expect/index.d.ts | 4 ++-- packages/expect/rollup.config.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/expect/index.d.ts b/packages/expect/index.d.ts index 1f129c72f135..3b82ac400909 100644 --- a/packages/expect/index.d.ts +++ b/packages/expect/index.d.ts @@ -1,3 +1,3 @@ -import './dist/chai' +import './dist/chai.cjs' -export * from './dist/index' +export * from './dist/index.js' diff --git a/packages/expect/rollup.config.js b/packages/expect/rollup.config.js index bf8c7f56631b..ca7d4a1c25f7 100644 --- a/packages/expect/rollup.config.js +++ b/packages/expect/rollup.config.js @@ -19,7 +19,7 @@ const plugins = [ }), copy({ targets: [ - { src: 'node_modules/@types/chai/index.d.ts', dest: 'dist', rename: 'chai.d.ts' }, + { src: 'node_modules/@types/chai/index.d.ts', dest: 'dist', rename: 'chai.d.cts' }, ], }), ] From 30ddd2614b23ef72d6294b6db276ca2592d20cc9 Mon Sep 17 00:00:00 2001 From: Malki Abdurrahman Date: Thu, 19 Oct 2023 08:07:18 +0100 Subject: [PATCH 2/9] docs: add bun to vitest installation (#4331) --- docs/guide/index.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/guide/index.md b/docs/guide/index.md index dce7857532f5..ada2bc7cfd4c 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -28,6 +28,9 @@ You can try Vitest online on [StackBlitz](https://vitest.new). It runs Vitest di ```bash [pnpm] pnpm add -D vitest ``` + ```bash [bun] + bun add -D vitest + ``` ::: :::tip From df4606dca2ea276fdf4d570ec6598bdcdff8d154 Mon Sep 17 00:00:00 2001 From: Rahul Singh <43885405+ChiChuRita@users.noreply.github.com> Date: Thu, 19 Oct 2023 09:07:40 +0200 Subject: [PATCH 3/9] docs: typo on config page (#4334) --- docs/config/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config/index.md b/docs/config/index.md index afa346a280bc..028b1d897793 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -1319,7 +1319,7 @@ Run all tests in a specific browser. Possible options in different providers: - **Type:** `boolean` - **Default:** `process.env.CI` -- **CLI:** `--browser.headless`, `--brower.headless=false` +- **CLI:** `--browser.headless`, `--browser.headless=false` Run the browser in a `headless` mode. If you are running Vitest in CI, it will be enabled by default. From a1aadd713c767b047ef46976bb690a57351322e6 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 19 Oct 2023 11:21:51 +0200 Subject: [PATCH 4/9] feat(vitest): run typecheck during tests (#4324) --- docs/advanced/api.md | 5 - docs/config/index.md | 20 ++- docs/guide/cli.md | 3 + docs/guide/testing-types.md | 10 +- packages/runner/src/utils/tasks.ts | 4 +- packages/ui/client/components/Suites.vue | 1 + packages/ui/client/components/TaskItem.vue | 1 + .../ui/client/components/views/ViewEditor.vue | 2 +- packages/ui/client/composables/summary.ts | 27 +++- packages/ui/package.json | 1 + packages/vitest/src/node/cli-api.ts | 9 ++ packages/vitest/src/node/cli.ts | 12 +- packages/vitest/src/node/config.ts | 9 +- packages/vitest/src/node/core.ts | 20 +-- packages/vitest/src/node/logger.ts | 19 ++- packages/vitest/src/node/pool.ts | 19 ++- packages/vitest/src/node/pools/typecheck.ts | 123 ++++++++++++++++++ packages/vitest/src/node/reporters/base.ts | 32 +++-- .../node/reporters/renderers/listRenderer.ts | 2 +- packages/vitest/src/node/stdin.ts | 4 - packages/vitest/src/node/workspace.ts | 75 ++--------- packages/vitest/src/runtime/execute.ts | 2 + packages/vitest/src/typecheck/collect.ts | 2 + packages/vitest/src/typecheck/typechecker.ts | 34 ++++- packages/vitest/src/types/config.ts | 14 +- packages/vitest/src/types/pool-options.ts | 2 +- pnpm-lock.yaml | 13 +- test/coverage-test/package.json | 2 +- test/typescript/package.json | 2 +- test/typescript/test/runner.test.ts | 7 +- test/typescript/test/vitest.custom.config.ts | 1 + test/typescript/test/vitest.empty.config.ts | 1 + 32 files changed, 330 insertions(+), 148 deletions(-) create mode 100644 packages/vitest/src/node/pools/typecheck.ts diff --git a/docs/advanced/api.md b/docs/advanced/api.md index fa4990699fda..e21fe2f0ae5a 100644 --- a/docs/advanced/api.md +++ b/docs/advanced/api.md @@ -52,7 +52,6 @@ Vitest instance requires the current test mode. It can be either: - `test` when running runtime tests - `benchmark` when running benchmarks -- `typecheck` when running type tests ### mode @@ -64,10 +63,6 @@ Test mode will only call functions inside `test` or `it`, and throws an error wh Benchmark mode calls `bench` functions and throws an error, when it encounters `test` or `it`. This mode uses `benchmark.include` and `benchmark.exclude` options in the config to find benchmark files. -#### typecheck - -Typecheck mode doesn't _run_ tests. It only analyses types and gives a summary. This mode uses `typecheck.include` and `typecheck.exclude` options in the config to find files to analyze. - ### start You can start running tests or benchmarks with `start` method. You can pass an array of strings to filter test files. diff --git a/docs/config/index.md b/docs/config/index.md index 028b1d897793..841e1e8b26d2 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -547,7 +547,7 @@ export default defineConfig({ ### poolMatchGlobs -- **Type:** `[string, 'threads' | 'forks' | 'vmThreads'][]` +- **Type:** `[string, 'threads' | 'forks' | 'vmThreads' | 'typescript'][]` - **Default:** `[]` - **Version:** Since Vitest 0.29.4 @@ -1637,6 +1637,24 @@ Changes the order in which setup files are executed. Options for configuring [typechecking](/guide/testing-types) test environment. +#### typecheck.enabled + +- **Type**: `boolean` +- **Default**: `false` +- **CLI**: `--typecheck`, `--typecheck.enabled` +- **Version**: Since Vitest 1.0.0-beta.3 + +Enable typechecking alongside your regular tests. + +#### typecheck.only + +- **Type**: `boolean` +- **Default**: `false` +- **CLI**: `--typecheck.only` +- **Version**: Since Vitest 1.0.0-beta.3 + +Run only typecheck tests, when typechecking is enabled. When using CLI, this option will automatically enable typechecking. + #### typecheck.checker - **Type**: `'tsc' | 'vue-tsc' | string` diff --git a/docs/guide/cli.md b/docs/guide/cli.md index 5d7b7317f5ef..c4569ec8a106 100644 --- a/docs/guide/cli.md +++ b/docs/guide/cli.md @@ -96,6 +96,9 @@ Run only [benchmark](https://vitest.dev/guide/features.html#benchmarking-experim | `--inspect-brk` | Enables Node.js inspector with break | | `--bail ` | Stop test execution when given number of tests have failed | | `--retry ` | Retry the test specific number of times if it fails | +| `--typecheck [options]` | Custom options for typecheck pool. If passed without options, enables typechecking | +| `--typecheck.enabled` | Enable typechecking alongside tests (default: `false`) | +| `--typecheck.only` | Run only typecheck tests. This automatically enables typecheck (default: `false`) | | `-h, --help` | Display available CLI options | ::: tip diff --git a/docs/guide/testing-types.md b/docs/guide/testing-types.md index 258e970ab4c4..eb2f167dbf68 100644 --- a/docs/guide/testing-types.md +++ b/docs/guide/testing-types.md @@ -66,12 +66,12 @@ assertType(answr) // ## Run typechecking -Add this command to your `scripts` section in `package.json`: +To enabled typechecking, just add `--typecheck` flag to your Vitest command in `package.json`: ```json { "scripts": { - "typecheck": "vitest typecheck" + "test": "vitest --typecheck" } } ``` @@ -80,13 +80,13 @@ Now you can run typecheck: ```sh # npm -npm run typecheck +npm run test # yarn -yarn typecheck +yarn test # pnpm -pnpm run typecheck +pnpm run test ``` Vitest uses `tsc --noEmit` or `vue-tsc --noEmit`, depending on your configuration, so you can remove these scripts from your pipeline. diff --git a/packages/runner/src/utils/tasks.ts b/packages/runner/src/utils/tasks.ts index 40244da59c8a..d692a7995494 100644 --- a/packages/runner/src/utils/tasks.ts +++ b/packages/runner/src/utils/tasks.ts @@ -7,8 +7,8 @@ function isAtomTest(s: Task): s is Test | Custom { export function getTests(suite: Arrayable): (Test | Custom)[] { const tests: (Test | Custom)[] = [] - const suite_arr = toArray(suite) - for (const s of suite_arr) { + const arraySuites = toArray(suite) + for (const s of arraySuites) { if (isAtomTest(s)) { tests.push(s) } diff --git a/packages/ui/client/components/Suites.vue b/packages/ui/client/components/Suites.vue index 492b10d3bb3e..c9a1d8038194 100644 --- a/packages/ui/client/components/Suites.vue +++ b/packages/ui/client/components/Suites.vue @@ -23,6 +23,7 @@ async function onRunCurrent() {