From 63ac83d0901cb74f3ede7ce7150e3025929c0aa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez?= Date: Wed, 15 Nov 2023 01:45:00 +0100 Subject: [PATCH 01/14] docs: update styles for features animations (#4499) --- .vitepress/components/ListItem.vue | 13 ++++--------- .vitepress/scripts/pwa.ts | 2 ++ .vitepress/style/main.css | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/.vitepress/components/ListItem.vue b/.vitepress/components/ListItem.vue index 4e046b2a..4a8b2fbe 100644 --- a/.vitepress/components/ListItem.vue +++ b/.vitepress/components/ListItem.vue @@ -16,7 +16,7 @@ function reset() { const color = computed(() => { return { - '--vp-c-brand': state.value === 1 + '--vp-c-brand-1': state.value === 1 ? '#66ba1c' : state.value === 2 ? 'rgba(248, 113, 113)' @@ -50,12 +50,12 @@ onMounted(async () => {
-
-
-
+
+
+
@@ -63,8 +63,3 @@ onMounted(async () => { - diff --git a/.vitepress/scripts/pwa.ts b/.vitepress/scripts/pwa.ts index fdca7e50..53bb4ee3 100644 --- a/.vitepress/scripts/pwa.ts +++ b/.vitepress/scripts/pwa.ts @@ -68,6 +68,8 @@ export const pwa: PwaOptions = { // warning: sponsors/antfu.svg is 2.51 MB, and won't be precached maximumFileSizeToCacheInBytes: 3 * 1024 * 1024, // <== 3MB globPatterns: ['**/*.{css,js,html,png,svg,ico,txt,woff2,json}'], + // Rollup 4 change the layout: don't calculate revision (hash) + dontCacheBustURLsMatching: /^assets\//, runtimeCaching: [ { urlPattern: pwaFontsRegex, diff --git a/.vitepress/style/main.css b/.vitepress/style/main.css index 7b57691c..b76a1c0f 100644 --- a/.vitepress/style/main.css +++ b/.vitepress/style/main.css @@ -8,6 +8,28 @@ html:not(.dark) [img-dark] { /* Overrides */ +.vp-doc ul.features-list { + padding: 0; +} +.vp-doc ul.features-list li { + list-style: none; + display: flex; + gap: 0.4rem; + margin: 0; +} +.vp-doc ul.features-list li div:first-of-type { + position: relative; +} +.vp-doc ul.features-list li div:first-of-type div { + position: absolute; +} +.vp-doc ul.features-list li div:first-of-type div.flip { + transform: rotateY(90deg); +} +.vp-doc ul.features-list li div:first-of-type div div { + position: unset; +} + .sp .sp-link.link:hover, .sp .sp-link.link:focus { background-color: var(--vitest-c-sponsor-hover) !important; From 94cdca19552f36cc3cbce12ef92234fba26d5c7a Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 15 Nov 2023 16:43:02 +0100 Subject: [PATCH 02/14] docs: update msw example (#4502) --- guide/mocking.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/guide/mocking.md b/guide/mocking.md index e5abbc84..69e1c19d 100644 --- a/guide/mocking.md +++ b/guide/mocking.md @@ -277,7 +277,7 @@ You can use it like below in your [setup file](/config/#setupfiles) ```js import { afterAll, afterEach, beforeAll } from 'vitest' import { setupServer } from 'msw/node' -import { graphql, rest } from 'msw' +import { HttpResponse, graphql, rest } from 'msw' const posts = [ { @@ -290,14 +290,18 @@ const posts = [ ] export const restHandlers = [ - rest.get('https://rest-endpoint.example/path/to/posts', (req, res, ctx) => { - return res(ctx.status(200), ctx.json(posts)) + http.get('https://rest-endpoint.example/path/to/posts', () => { + return HttpResponse.json(posts) }), ] const graphqlHandlers = [ - graphql.query('https://graphql-endpoint.example/api/v1/posts', (req, res, ctx) => { - return res(ctx.data(posts)) + graphql.query('https://graphql-endpoint.example/api/v1/posts', () => { + return HttpResponse.json( + { + data: { posts }, + }, + ) }), ] From cce8cc7855fdb3845d94017e26f4c7f960b04590 Mon Sep 17 00:00:00 2001 From: dsyddall Date: Wed, 15 Nov 2023 15:43:27 +0000 Subject: [PATCH 03/14] fix: inherit concurrent/sequential in nested suites (#4482) --- api/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/index.md b/api/index.md index 50dc8555..8119b974 100644 --- a/api/index.md +++ b/api/index.md @@ -654,7 +654,7 @@ You cannot use this syntax, when using Vitest as [type checker](/guide/testing-t - **Type:** `(name: string | Function, fn: TestFunction, options?: number | TestOptions) => void` -`describe.sequential` in a suite marks every test as sequential. This is useful if you want to run tests in sequential within `describe.concurrent` or with the `--sequence.concurrent` command option. +`describe.sequential` in a suite marks every test as sequential. This is useful if you want to run tests in sequence within `describe.concurrent` or with the `--sequence.concurrent` command option. ```ts describe.concurrent('suite', () => { From 44722d4697a401ddd873810875482a75abc1e7a9 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 15 Nov 2023 18:39:14 +0100 Subject: [PATCH 04/14] feat(expect): toContain can handle classList and Node.contains (#4239) --- api/expect.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/expect.md b/api/expect.md index f5322a8e..4707574a 100644 --- a/api/expect.md +++ b/api/expect.md @@ -422,7 +422,7 @@ test('structurally the same, but semantically different', () => { - **Type:** `(received: string) => Awaitable` -`toContain` asserts if the actual value is in an array. `toContain` can also check whether a string is a substring of another string. +`toContain` asserts if the actual value is in an array. `toContain` can also check whether a string is a substring of another string. Since Vitest 1.0, if you are running tests in a browser-like environment, this assertion can also check if class is contained in a `classList`, or an element is inside another one. ```ts import { expect, test } from 'vitest' @@ -430,6 +430,12 @@ import { getAllFruits } from './stocks.js' test('the fruit list contains orange', () => { expect(getAllFruits()).toContain('orange') + + const element = document.querySelector('#el') + // element has a class + expect(element.classList).toContain('flex') + // element is inside another one + expect(document.querySelector('#wrapper')).toContain(element) }) ``` From f4f46d2968146933bc2f425efeec59443f323965 Mon Sep 17 00:00:00 2001 From: jwangbychance <99638105+jwangbychance@users.noreply.github.com> Date: Thu, 16 Nov 2023 19:13:38 +1100 Subject: [PATCH 05/14] style: capitalise a few sentences for consistency (#4513) --- config/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/index.md b/config/index.md index afa5044c..4ea03b85 100644 --- a/config/index.md +++ b/config/index.md @@ -14,7 +14,7 @@ outline: deep To configure `vitest` itself, add `test` property in your Vite config. You'll also need to add a reference to Vitest types using a [triple slash command](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#-reference-types-) at the top of your config file, if you are importing `defineConfig` from `vite` itself. -using `defineConfig` from `vite` you should follow this: +Using `defineConfig` from `vite` you should follow this: ```ts /// @@ -27,7 +27,7 @@ export default defineConfig({ }) ``` -using `defineConfig` from `vitest/config` you should follow this: +Using `defineConfig` from `vitest/config` you should follow this: ```ts import { defineConfig } from 'vitest/config' From 150e24eb0b83715f0356aa5d165eee33bc8d4aff Mon Sep 17 00:00:00 2001 From: dsyddall Date: Thu, 16 Nov 2023 12:11:58 +0000 Subject: [PATCH 06/14] feat: add test.sequential() api (#4512) --- api/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/api/index.md b/api/index.md index 8119b974..5a2c5e3c 100644 --- a/api/index.md +++ b/api/index.md @@ -224,6 +224,30 @@ test.concurrent('test 2', async ({ expect }) => { You cannot use this syntax, when using Vitest as [type checker](/guide/testing-types). ::: +### test.sequential + +- **Type:** `(name: string | Function, fn: TestFunction, timeout?: number) => void` + +`test.sequential` marks a test as sequential. This is useful if you want to run tests in sequence within `describe.concurrent` or with the `--sequence.concurrent` command option. + +```ts +// with config option { sequence: { concurrent: true } } +test('concurrent test 1', async () => { /* ... */ }) +test('concurrent test 2', async () => { /* ... */ }) + +test.sequential('sequential test 1', async () => { /* ... */ }) +test.sequential('sequential test 2', async () => { /* ... */ }) + +// within concurrent suite +describe.concurrent('suite', () => { + test('concurrent test 1', async () => { /* ... */ }) + test('concurrent test 2', async () => { /* ... */ }) + + test.sequential('sequential test 1', async () => { /* ... */ }) + test.sequential('sequential test 2', async () => { /* ... */ }) +}) +``` + ### test.todo - **Type:** `(name: string | Function) => void` From c28f160d14e225867a1f6e1bd6cc67e199489d14 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Fri, 17 Nov 2023 11:53:41 +0100 Subject: [PATCH 07/14] docs: add companies that sponsor Vitest (#4523) --- .vitepress/components/HomePage.vue | 127 ++++++++++++++--------------- .vitepress/contributors.ts | 20 ++--- .vitepress/sponsors.ts | 62 ++++++++++++++ public/bit.svg | 21 +++++ public/infosupport.svg | 49 +++++++++++ public/nuxtlabs.svg | 1 + public/stackblitz.svg | 1 + public/vite.svg | 15 ++++ public/zammad.svg | 30 +++++++ 9 files changed, 250 insertions(+), 76 deletions(-) create mode 100644 .vitepress/sponsors.ts create mode 100644 public/bit.svg create mode 100644 public/infosupport.svg create mode 100644 public/nuxtlabs.svg create mode 100644 public/stackblitz.svg create mode 100644 public/vite.svg create mode 100644 public/zammad.svg diff --git a/.vitepress/components/HomePage.vue b/.vitepress/components/HomePage.vue index ad36b5d1..60fe81cf 100644 --- a/.vitepress/components/HomePage.vue +++ b/.vitepress/components/HomePage.vue @@ -1,85 +1,80 @@ + + diff --git a/.vitepress/contributors.ts b/.vitepress/contributors.ts index 95156557..def30038 100644 --- a/.vitepress/contributors.ts +++ b/.vitepress/contributors.ts @@ -45,6 +45,16 @@ function createLinks(tm: CoreTeam): CoreTeam { } const plainTeamMembers: CoreTeam[] = [ + { + avatar: contributorsAvatars['sheremet-va'], + name: 'Vladimir', + github: 'sheremet-va', + mastodon: 'https://elk.zone/m.webtoo.ls/@sheremet_va', + twitter: 'sheremet_va', + sponsor: 'https://github.com/sponsors/sheremet-va', + title: 'An open source fullstack developer', + desc: 'Core team member of Vitest & Vite', + }, { avatar: contributorsAvatars.antfu, name: 'Anthony Fu', @@ -59,16 +69,6 @@ const plainTeamMembers: CoreTeam[] = [ orgLink: 'https://nuxtlabs.com/', desc: 'Core team member of Vite & Vue', }, - { - avatar: contributorsAvatars['sheremet-va'], - name: 'Vladimir', - github: 'sheremet-va', - mastodon: 'https://elk.zone/m.webtoo.ls/@sheremet_va', - twitter: 'sheremet_va', - sponsor: 'https://github.com/sponsors/sheremet-va', - title: 'An open source fullstack developer', - desc: 'Core team member of Vitest', - }, { avatar: contributorsAvatars.AriPerkkio, name: 'Ari Perkkiö', diff --git a/.vitepress/sponsors.ts b/.vitepress/sponsors.ts new file mode 100644 index 00000000..13835a9b --- /dev/null +++ b/.vitepress/sponsors.ts @@ -0,0 +1,62 @@ +interface Sponsor { + name: string + img: string + url: string +} + +const vitestSponsors = { + special: [ + { + name: 'Vite', + url: 'https://vitejs.dev', + img: '/vite.svg', + }, + { + name: 'NuxtLabs', + url: 'https://nuxtlabs.com', + img: '/nuxtlabs.svg', + }, + { + name: 'Stackblitz', + url: 'https://stackblitz.com', + img: '/stackblitz.svg', + }, + { + name: 'Zammad', + url: 'https://zammad.com', + img: '/zammad.svg', + }, + ], + platinum: [ + { + name: 'Bit', + url: 'https://bit.dev', + img: '/bit.svg', + }, + ], + gold: [ + { + name: 'InfoSupport', + url: 'https://www.infosupport.com/open-source/', + img: '/infosupport.svg', + }, + ], +} satisfies Record + +export const sponsors = [ + { + tier: 'Special Sponsors', + size: 'big', + items: vitestSponsors.special, + }, + { + tier: 'Platinum Sponsors', + size: 'big', + items: vitestSponsors.platinum, + }, + { + tier: 'Gold Sponsors', + size: 'medium', + items: vitestSponsors.gold, + }, +] diff --git a/public/bit.svg b/public/bit.svg new file mode 100644 index 00000000..8750e3ef --- /dev/null +++ b/public/bit.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/public/infosupport.svg b/public/infosupport.svg new file mode 100644 index 00000000..e541b37b --- /dev/null +++ b/public/infosupport.svg @@ -0,0 +1,49 @@ + + + + Group 58 + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/nuxtlabs.svg b/public/nuxtlabs.svg new file mode 100644 index 00000000..d2935645 --- /dev/null +++ b/public/nuxtlabs.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/stackblitz.svg b/public/stackblitz.svg new file mode 100644 index 00000000..a16fcd92 --- /dev/null +++ b/public/stackblitz.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/vite.svg b/public/vite.svg new file mode 100644 index 00000000..de4aeddc --- /dev/null +++ b/public/vite.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/public/zammad.svg b/public/zammad.svg new file mode 100644 index 00000000..0685eb75 --- /dev/null +++ b/public/zammad.svg @@ -0,0 +1,30 @@ + + + + logo + Created with Sketch. + + + + + \ No newline at end of file From 2af12936f0e014e6b4e25d461ec09721565e8c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Fri, 17 Nov 2023 20:24:04 +0200 Subject: [PATCH 08/14] feat!(coverage): glob based coverage thresholds (#4442) --- config/index.md | 101 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 31 deletions(-) diff --git a/config/index.md b/config/index.md index 4ea03b85..34375813 100644 --- a/config/index.md +++ b/config/index.md @@ -1181,70 +1181,109 @@ Collect coverage of files outside the [project `root`](https://vitest.dev/config Do not show files with 100% statement, branch, and function coverage. -#### coverage.perFile +#### coverage.thresholds -- **Type:** `boolean` -- **Default:** `false` -- **Available for providers:** `'v8' | 'istanbul'` -- **CLI:** `--coverage.perFile`, `--coverage.perFile=false` - -Check thresholds per file. -See `lines`, `functions`, `branches` and `statements` for the actual thresholds. +Options for coverage thresholds -#### coverage.thresholdAutoUpdate +##### coverage.thresholds.lines -- **Type:** `boolean` -- **Default:** `false` +- **Type:** `number` - **Available for providers:** `'v8' | 'istanbul'` -- **CLI:** `--coverage.thresholdAutoUpdate=` +- **CLI:** `--coverage.thresholds.lines=` -Update threshold values `lines`, `functions`, `branches` and `statements` to configuration file when current coverage is above the configured thresholds. -This option helps to maintain thresholds when coverage is improved. +Global threshold for lines. +See [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. -#### coverage.lines +##### coverage.thresholds.functions - **Type:** `number` - **Available for providers:** `'v8' | 'istanbul'` -- **CLI:** `--coverage.lines=` +- **CLI:** `--coverage.thresholds.functions=` -Threshold for lines. +Global threshold for functions. See [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. -#### coverage.functions +##### coverage.thresholds.branches - **Type:** `number` - **Available for providers:** `'v8' | 'istanbul'` -- **CLI:** `--coverage.functions=` +- **CLI:** `--coverage.thresholds.branches=` -Threshold for functions. +Global threshold for branches. See [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. -#### coverage.branches +##### coverage.thresholds.statements - **Type:** `number` - **Available for providers:** `'v8' | 'istanbul'` -- **CLI:** `--coverage.branches=` +- **CLI:** `--coverage.thresholds.statements=` -Threshold for branches. +Global threshold for statements. See [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. -#### coverage.statements +##### coverage.thresholds.perFile -- **Type:** `number` +- **Type:** `boolean` +- **Default:** `false` - **Available for providers:** `'v8' | 'istanbul'` -- **CLI:** `--coverage.statements=` +- **CLI:** `--coverage.thresholds.perFile`, `--coverage.thresholds.perFile=false` -Threshold for statements. -See [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. +Check thresholds per file. -#### coverage.100 +##### coverage.thresholds.autoUpdate - **Type:** `boolean` - **Default:** `false` - **Available for providers:** `'v8' | 'istanbul'` -- **CLI:** `--coverage.100`, `--coverage.100=false` +- **CLI:** `--coverage.thresholds.autoUpdate=` + +Update all threshold values `lines`, `functions`, `branches` and `statements` to configuration file when current coverage is above the configured thresholds. +This option helps to maintain thresholds when coverage is improved. + +##### coverage.thresholds.100 -Shortcut for `--coverage.lines 100 --coverage.functions 100 --coverage.branches 100 --coverage.statements 100`. +- **Type:** `boolean` +- **Default:** `false` +- **Available for providers:** `'v8' | 'istanbul'` +- **CLI:** `--coverage.thresholds.100`, `--coverage.thresholds.100=false` + +Sets global thresholds to 100. +Shortcut for `--coverage.thresholds.lines 100 --coverage.thresholds.functions 100 --coverage.thresholds.branches 100 --coverage.thresholds.statements 100`. + +##### coverage.thresholds[glob-pattern] + +- **Type:** `{ statements?: number functions?: number branches?: number lines?: number }` +- **Default:** `undefined` +- **Available for providers:** `'v8' | 'istanbul'` + +Sets thresholds for files matching the glob pattern. + + +```ts +{ + coverage: { + thresholds: { + // Thresholds for all files + functions: 95, + branches: 70, + + // Thresholds for matching glob pattern + 'src/utils/**.ts': { + statements: 95, + functions: 90, + branches: 85, + lines: 80, + }, + + // Files matching this pattern will only have lines thresholds set. + // Global thresholds are not inherited. + '**/math.ts': { + lines: 100, + } + } + } +} +``` #### coverage.ignoreClassMethods From 7eaae924c9c13b9e11d48a4389f82e48e0c287b2 Mon Sep 17 00:00:00 2001 From: Elone Hoo Date: Sat, 18 Nov 2023 22:36:21 +0800 Subject: [PATCH 09/14] docs: modify Sponsorship Module --- .vitepress/components/HomePage.vue | 71 +----------------------------- 1 file changed, 2 insertions(+), 69 deletions(-) diff --git a/.vitepress/components/HomePage.vue b/.vitepress/components/HomePage.vue index 3b737bd7..48882618 100644 --- a/.vitepress/components/HomePage.vue +++ b/.vitepress/components/HomePage.vue @@ -15,77 +15,10 @@ import { sponsors } from '../sponsors'
-<<<<<<< HEAD -

- 贡献者 -

-

- -
- 加入我们将乐在其中! -

- - - -

- - Deploys by Netlify - -

-======= ->>>>>>> 2af12936f0e014e6b4e25d461ec09721565e8c8b
@@ -95,7 +28,7 @@ import { sponsors } from '../sponsors' target="_blank" rel="noreferrer" > - Sponsor Vitest + 赞助 Vitest

From 15e577ef34c4550eb3e752b8a966400dc6db7e71 Mon Sep 17 00:00:00 2001 From: Elone Hoo Date: Sat, 18 Nov 2023 22:40:26 +0800 Subject: [PATCH 10/14] docs: order of revision --- .vitepress/contributors.ts | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/.vitepress/contributors.ts b/.vitepress/contributors.ts index 5af0a322..9e6314fb 100644 --- a/.vitepress/contributors.ts +++ b/.vitepress/contributors.ts @@ -60,8 +60,8 @@ const plainTeamMembers: CoreTeam[] = [ mastodon: 'https://elk.zone/m.webtoo.ls/@sheremet_va', twitter: 'sheremet_va', sponsor: 'https://github.com/sponsors/sheremet-va', - title: 'An open source fullstack developer', - desc: 'Core team member of Vitest & Vite', + title: '全栈开源开发者', + desc: 'Vitest 的核心团队成员', }, { avatar: contributorsAvatars.antfu, @@ -78,19 +78,6 @@ const plainTeamMembers: CoreTeam[] = [ desc: 'Vite 和 Vue 的核心团队成员', }, { -<<<<<<< HEAD - avatar: contributorsAvatars['sheremet-va'], - name: 'Vladimir', - github: 'sheremet-va', - mastodon: 'https://elk.zone/m.webtoo.ls/@sheremet_va', - twitter: 'sheremet_va', - sponsor: 'https://github.com/sponsors/sheremet-va', - title: '全栈开源开发者', - desc: 'Vitest 的核心团队成员', - }, - { -======= ->>>>>>> 2af12936f0e014e6b4e25d461ec09721565e8c8b avatar: contributorsAvatars.AriPerkkio, name: 'Ari Perkkiö', github: 'AriPerkkio', From 78713b319ab152419d307bd30c90bd5222b3ee47 Mon Sep 17 00:00:00 2001 From: Elone Hoo Date: Sat, 18 Nov 2023 22:45:19 +0800 Subject: [PATCH 11/14] docs: modification example --- guide/mocking.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/guide/mocking.md b/guide/mocking.md index 5f9a8717..11c4bec9 100644 --- a/guide/mocking.md +++ b/guide/mocking.md @@ -297,14 +297,6 @@ export const restHandlers = [ ] const graphqlHandlers = [ -<<<<<<< HEAD - graphql.query( - 'https://graphql-endpoint.example/api/v1/posts', - (req, res, ctx) => { - return res(ctx.data(posts)) - } - ), -======= graphql.query('https://graphql-endpoint.example/api/v1/posts', () => { return HttpResponse.json( { @@ -312,7 +304,6 @@ const graphqlHandlers = [ }, ) }), ->>>>>>> 2af12936f0e014e6b4e25d461ec09721565e8c8b ] const server = setupServer(...restHandlers, ...graphqlHandlers) From e12878a2e9ee11741416260139687a1eb00f79a3 Mon Sep 17 00:00:00 2001 From: Elone Hoo Date: Sat, 18 Nov 2023 22:53:03 +0800 Subject: [PATCH 12/14] docs: modified some translations --- config/index.md | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/config/index.md b/config/index.md index e2cc53bc..8ebc8216 100644 --- a/config/index.md +++ b/config/index.md @@ -14,11 +14,7 @@ outline: deep 要配置 `vitest` 本身,请在你的 Vite 配置中添加 `test` 属性。如果你使用 `vite` 的 `defineConfig` 你还需要将 [三斜线指令](https://www.tslang.cn/docs/handbook/triple-slash-directives.html#-reference-types-) 写在配置文件的顶部。 -<<<<<<< HEAD 使用 `vite` 的 `defineConfig` 可以参考下面的格式: -======= -Using `defineConfig` from `vite` you should follow this: ->>>>>>> 2af12936f0e014e6b4e25d461ec09721565e8c8b ```ts /// @@ -31,11 +27,7 @@ export default defineConfig({ }) ``` -<<<<<<< HEAD -使用 `vitest` 的 `defineConfig` 可以参考下面的格式: -======= -Using `defineConfig` from `vitest/config` you should follow this: ->>>>>>> 2af12936f0e014e6b4e25d461ec09721565e8c8b +使用 `vitest/config` 中的 `defineConfig` 可以参考下面的格式: ```ts import { defineConfig } from 'vitest/config' From 5ce6e41603bc40d4ad609a3b718e3aad7432546b Mon Sep 17 00:00:00 2001 From: Elone Hoo Date: Sat, 18 Nov 2023 23:05:16 +0800 Subject: [PATCH 13/14] docs: partially translated --- config/index.md | 162 +++++++++++------------------------------------- 1 file changed, 37 insertions(+), 125 deletions(-) diff --git a/config/index.md b/config/index.md index 8ebc8216..357b1c1a 100644 --- a/config/index.md +++ b/config/index.md @@ -1115,7 +1115,7 @@ npx vitest --coverage.enabled --coverage.provider=istanbul --coverage.all #### coverage.clean -- **Type:** `boolean` +- **类型:** `boolean` - **默认值:** `true` - **可用的测试提供者:** `'v8' | 'istanbul'` - **命令行终端:** `--coverage.clean`, `--coverage.clean=false` @@ -1195,9 +1195,9 @@ npx vitest --coverage.enabled --coverage.provider=istanbul --coverage.all #### coverage.allowExternal -- **Type:** `boolean` -- **Default:** `false` -- **Available for providers:** `'v8' | 'istanbul'` +- **类型:** `boolean` +- **默认值:** `false` +- **可用的测试提供者:** `'v8' | 'istanbul'` - **CLI:** `--coverage.allowExternal`, `--coverage.allowExternal=false` Collect coverage of files outside the [project `root`](https://vitest.dev/config/#root). @@ -1213,167 +1213,80 @@ Collect coverage of files outside the [project `root`](https://vitest.dev/config #### coverage.thresholds -Options for coverage thresholds +覆盖范围阈值选项 ##### coverage.thresholds.lines -- **Type:** `number` -- **Available for providers:** `'v8' | 'istanbul'` -- **CLI:** `--coverage.thresholds.lines=` +- **类型:** `number` +- **可用的测试提供者:** `'v8' | 'istanbul'` +- **命令行终端:** `--coverage.thresholds.lines=` -Global threshold for lines. -See [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. +lines 的全局阈值。 +更多信息请查看 [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-thresholds)。 ##### coverage.thresholds.functions -- **Type:** `number` -- **Available for providers:** `'v8' | 'istanbul'` -- **CLI:** `--coverage.thresholds.functions=` +- **类型:** `number` +- **可用的测试提供者:** `'v8' | 'istanbul'` +- **命令行终端:** `--coverage.thresholds.functions=` -Global threshold for functions. -See [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. +functions 的全局阈值。 +更多信息请查看 [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-thresholds)。 ##### coverage.thresholds.branches -- **Type:** `number` -- **Available for providers:** `'v8' | 'istanbul'` -- **CLI:** `--coverage.thresholds.branches=` +- **类型:** `number` +- **可用的测试提供者:** `'v8' | 'istanbul'` +- **命令行终端:** `--coverage.thresholds.branches=` -Global threshold for branches. -See [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. +branches 的全局阈值。 +更多信息请查看 [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-thresholds)。 ##### coverage.thresholds.statements -- **Type:** `number` -- **Available for providers:** `'v8' | 'istanbul'` -- **CLI:** `--coverage.thresholds.statements=` +- **类型:** `number` +- **可用的测试提供者:** `'v8' | 'istanbul'` +- **命令行终端:** `--coverage.thresholds.statements=` -Global threshold for statements. -See [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-thresholds) for more information. +statements 的全局阈值。 +更多信息请查看 [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-thresholds)。 ##### coverage.thresholds.perFile -<<<<<<< HEAD - **类型:** `boolean` - **默认值:** `false` - **可用的测试提供者:** `'v8' | 'istanbul'` -- **命令行终端:** `--coverage.perFile`, `--coverage.perFile=false` +- **命令行终端:** `--coverage.thresholds.perFile`, `--coverage.thresholds.perFile=false` 检查每个文件的阈值。 -有关实际阈值,请参见 `lines`, `functions`, `branches` and `statements` 。 -======= -- **Type:** `boolean` -- **Default:** `false` -- **Available for providers:** `'v8' | 'istanbul'` -- **CLI:** `--coverage.thresholds.perFile`, `--coverage.thresholds.perFile=false` - -Check thresholds per file. ->>>>>>> 2af12936f0e014e6b4e25d461ec09721565e8c8b ##### coverage.thresholds.autoUpdate -<<<<<<< HEAD - **类型:** `boolean` - **默认值:** `false` - **可用的测试提供者:** `'v8' | 'istanbul'` -- **命令行终端:** `--coverage.thresholdAutoUpdate=` - -当前覆盖率高于配置的阈值时,将阈值 `lines`、 `functions`、`branches` 和 `statements` 更新到配置文件。 -此选项有助于在提高覆盖率时维持阈值。 - -#### coverage.lines - -- **类型:** `number` -- **可用的测试提供者:** `'v8' | 'istanbul'` -- **命令行终端:** `--coverage.lines=` +- **命令行终端:** `--coverage.thresholds.autoUpdate=` -行的阈值。参考 [istanbul 文档](https://github.com/istanbuljs/nyc#coverage-thresholds) 来了解详情。 +如果当前覆盖率高于配置的阈值时,将所有阈值 `lines` 、`functions` 、`branches` 和 `statements` 更新到配置文件中。 +此选项有助于在覆盖率提高时保持阈值不变。 -#### coverage.functions - -- **类型:** `number` -- **可用的测试提供者:** `'v8' | 'istanbul'` -- **命令行终端:** `--coverage.functions=` - -函数的阈值。参考 [istanbul 文档](https://github.com/istanbuljs/nyc#coverage-thresholds) 来了解详情。 - -#### coverage.branches - -- **类型:** `number` -- **可用的测试提供者:** `'v8' | 'istanbul'` -- **命令行终端:** `--coverage.branches=` - -分支的阈值。参考 [istanbul 文档](https://github.com/istanbuljs/nyc#coverage-thresholds) 来了解详情。 - -#### coverage.statements - -- **类型:** `number` -- **可用的测试提供者:** `'v8' | 'istanbul'` -- **命令行终端:** `--coverage.statements=` - -语句的阈值。参考 [istanbul 文档](https://github.com/istanbuljs/nyc#coverage-thresholds) 来了解详情。 - -#### coverage.allowExternal - -- **类型:** `boolean` -- **默认值:** `false` -- **可用的测试提供者:** `'v8'` -- **命令行终端:** `--coverage.allowExternal`, `--coverage.allowExternal=false` - -是否允许来自 cwd 外部的文件。 - -#### coverage.excludeNodeModules - -- **类型:** `boolean` -- **默认值:** `true` -- **可用的测试提供者:** `'v8'` -- **命令行终端:** `--coverage.excludeNodeModules`, `--coverage.excludeNodeModules=false` - -排除 `/node_modules/` 下的覆盖范围。 - -#### coverage.src - -- **类型:** `string[]` -- **默认值:** `process.cwd()` -- **可用的测试提供者:** `'v8'` -- **命令行终端:** `--coverage.src=` - -指定启用 `--all` 时使用的目录。 - -#### coverage.100 +##### coverage.thresholds.100 - **类型:** `boolean` - **默认值:** `false` - **可用的测试提供者:** `'v8' | 'istanbul'` -- **命令行终端:** `--coverage.100`, `--coverage.100=false` - -为 `--coverage.lines 100 --coverage.functions 100 --coverage.branches 100 --coverage.statements 100` 设置的快捷方式。 -======= -- **Type:** `boolean` -- **Default:** `false` -- **Available for providers:** `'v8' | 'istanbul'` -- **CLI:** `--coverage.thresholds.autoUpdate=` +- **命令行终端:** `--coverage.thresholds.100`, `--coverage.thresholds.100=false` -Update all threshold values `lines`, `functions`, `branches` and `statements` to configuration file when current coverage is above the configured thresholds. -This option helps to maintain thresholds when coverage is improved. - -##### coverage.thresholds.100 - -- **Type:** `boolean` -- **Default:** `false` -- **Available for providers:** `'v8' | 'istanbul'` -- **CLI:** `--coverage.thresholds.100`, `--coverage.thresholds.100=false` - -Sets global thresholds to 100. -Shortcut for `--coverage.thresholds.lines 100 --coverage.thresholds.functions 100 --coverage.thresholds.branches 100 --coverage.thresholds.statements 100`. +将全局阈值设置为 100。 +这是 `--coverage.thresholds.lines 100 --coverage.thresholds.functions 100 --coverage.thresholds.branches 100 --coverage.thresholds.statements 100` 的快捷方式。 ##### coverage.thresholds[glob-pattern] -- **Type:** `{ statements?: number functions?: number branches?: number lines?: number }` -- **Default:** `undefined` -- **Available for providers:** `'v8' | 'istanbul'` +- **类型:** `{ statements?: number functions?: number branches?: number lines?: number }` +- **默认值:** `undefined` +- **可用的测试提供者:** `'v8' | 'istanbul'` -Sets thresholds for files matching the glob pattern. +设置与 glob 模式匹配的文件的阈值。 ```ts @@ -1401,7 +1314,6 @@ Sets thresholds for files matching the glob pattern. } } ``` ->>>>>>> 2af12936f0e014e6b4e25d461ec09721565e8c8b #### coverage.ignoreClassMethods From 2a8efd483a33087f5f7942943532893faa69454e Mon Sep 17 00:00:00 2001 From: Elone Hoo Date: Sat, 18 Nov 2023 23:18:49 +0800 Subject: [PATCH 14/14] docs: translated a portion of the expect api. --- api/expect.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/api/expect.md b/api/expect.md index 716c6cc8..3f87909c 100644 --- a/api/expect.md +++ b/api/expect.md @@ -1,14 +1,14 @@ # expect -The following types are used in the type signatures below +以下类型在下面的类型签名中被使用。 ```ts type Awaitable = T | PromiseLike ``` -`expect` is used to create assertions. In this context `assertions` are functions that can be called to assert a statement. Vitest provides `chai` assertions by default and also `Jest` compatible assertions build on top of `chai`. +`expect` 用于创建断言。 在这种情况下, `assertions` 是可以调用来断言语句的函数。 Vitest 默认提供 `chai` 断言,并且还在 `chai` 之上构建了与 `Jest` 兼容的断言。 -For example, this code asserts that an `input` value is equal to `2`. If it's not, the assertion will throw an error, and the test will fail. +例如,此代码断言 `input` 值等于 `2`。 如果不是,assertions 将抛出错误,并且测试将失败。 ```ts import { expect } from 'vitest' @@ -19,19 +19,19 @@ expect(input).to.equal(2) // chai API expect(input).toBe(2) // jest API ``` -Technically this example doesn't use [`test`](/api/#test) function, so in the console you will see Nodejs error instead of Vitest output. To learn more about `test`, please read [Test API Reference](/api/). +从技术上讲,这个示例没有使用 [`test`](/api/#test) 函数,因此在控制台中你将看到 Nodejs 错误而不是 Vitest 输出。 要了解更多关于 `test` 的信息,请阅读[测试 API 参考](/api/)。 -Also, `expect` can be used statically to access matchers functions, described later, and more. +此外,`expect` 可以静态地使用来访问匹配器函数,稍后将会介绍。 ::: warning -`expect` has no effect on testing types, if the expression doesn't have a type error. If you want to use Vitest as [type checker](/guide/testing-types), use [`expectTypeOf`](/api/expect-typeof) or [`assertType`](/api/assert-type). +如果表达式没有类型错误,则 `expect` 对测试类型没有影响。 如果您想使用 Vitest 作为[类型检查器](/guide/testing-types),请使用 [`expectTypeOf`](/api/expect-typeof) 或 [`assertType`](/api/assert-type) 。 ::: ## soft -- **Type:** `ExpectStatic & (actual: any) => Assertions` +- **类型:** `ExpectStatic & (actual: any) => Assertions` -`expect.soft` functions similarly to `expect`, but instead of terminating the test execution upon a failed assertion, it continues running and marks the failure as a test failure. All errors encountered during the test will be displayed until the test is completed. +`expect.soft` 的功能与 `expect` 类似,但它不会在断言失败时终止测试执行,而是继续运行并将失败标记为测试失败。 测试过程中遇到的所有错误都会显示出来,直到测试完成。 ```ts import { expect, test } from 'vitest' @@ -43,7 +43,7 @@ test('expect.soft test', () => { // At the end of the test, the above errors will be output. ``` -It can also be used with `expect`. if `expect` assertion fails, the test will be terminated and all errors will be displayed. +它也可以与 `expect` 一起使用。 如果 `expect` 断言失败,测试将终止并显示所有错误。 ```ts import { expect, test } from 'vitest' @@ -56,12 +56,12 @@ test('expect.soft test', () => { ``` ::: warning -`expect.soft` can only be used inside the [`test`](/api/#test) function. +`expect.soft` 只能在 [`test`](/api/#test) 函数的内部使用。 ::: ## not -Using `not` will negate the assertion. For example, this code asserts that an `input` value is not equal to `2`. If it's equal, the assertion will throw an error, and the test will fail. +使用 `not` 将否定该断言。 例如,此代码断言 `input` 值不等于 `2`。 如果相等,断言将抛出错误,测试将失败。 ```ts import { expect, test } from 'vitest' @@ -74,11 +74,11 @@ expect(input).not.toBe(2) // jest API ## toBe -- **Type:** `(value: any) => Awaitable` +- **类型:** `(value: any) => Awaitable` -`toBe` can be used to assert if primitives are equal or that objects share the same reference. It is equivalent of calling `expect(Object.is(3, 3)).toBe(true)`. If the objects are not the same, but you want to check if their structures are identical, you can use [`toEqual`](#toequal). +`toBe` 可用于断言基元是否相等或对象共享相同的引用。 它相当于调用 `expect(Object.is(3, 3)).toBe(true)` 。 如果对象不相同,但你想检查它们的结构是否相同,可以使用 [`toEqual`](#toequal)。 -For example, the code below checks if the trader has 13 apples. +例如,下面的代码检查交易者是否有 13 个苹果。 ```ts import { expect, test } from 'vitest' @@ -100,7 +100,7 @@ test('stocks are the same', () => { }) ``` -Try not to use `toBe` with floating-point numbers. Since JavaScript rounds them, `0.1 + 0.2` is not strictly `0.3`. To reliably assert floating-point numbers, use [`toBeCloseTo`](#tobecloseto) assertion. +尽量不要将 `toBe` 与浮点数一起使用。 由于 JavaScript 对它们进行四舍五入,因此 `0.1 + 0.2` 并不严格是 `0.3` 。 要可靠地断言浮点数,请使用 [`toBeCloseTo`](#tobecloseto) 断言。 ## toBeCloseTo