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
30 changes: 30 additions & 0 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: autofix.ci

on:
pull_request:
permissions:
contents: read

jobs:
autofix:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v5

- name: Use Node.js lts/*
uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Setup
run: npm i -g @antfu/ni

- name: Install
run: nci

- name: Lint
run: nr lint --fix

- uses: autofix-ci/action@635ffb0c9798bd160680f18fd73371e355b85f27
6 changes: 3 additions & 3 deletions advanced/runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface VitestRunner {
* 这是在实际运行测试函数之前被调用的。
* 此时已经有了带有 "state" 和 "startTime" 属性的 "result" 对象。
*/
onBeforeTryTask?: (test: Test, options: { retry: number; repeats: number }) => unknown
onBeforeTryTask?: (test: Test, options: { retry: number, repeats: number }) => unknown
/**
* 这是在结果和状态都被设置之后被调用的。
*/
Expand All @@ -40,12 +40,12 @@ export interface VitestRunner {
* 这是在运行测试函数后立即被调用的。此时还没有新的状态。
* 如果测试函数抛出异常,将不会调用此方法。
*/
onAfterTryTask?: (test: Test, options: { retry: number; repeats: number }) => unknown
onAfterTryTask?: (test: Test, options: { retry: number, repeats: number }) => unknown
/**
* 在重试结果确定后调用。与 `onAfterTryTask` 不同,此时测试已进入新的状态,
* 并且所有的 `after` 钩子此时也已被执行。
*/
onAfterRetryTask?: (test: Test, options: { retry: number; repeats: number }) => unknown
onAfterRetryTask?: (test: Test, options: { retry: number, repeats: number }) => unknown

/**
* 这是在运行单个测试套件之前被调用的,此时还没有测试结果。
Expand Down
30 changes: 11 additions & 19 deletions api/expect-typeof.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const user = {
name: 'John',
address: { city: 'New York', zip: '10001' }
}
expectTypeOf(user).toMatchObjectType<{ name: string; address: { city: string } }>()
expectTypeOf(user).toMatchObjectType<{ name: string, address: { city: string } }>()
```

::: warning
Expand All @@ -91,12 +91,9 @@ This matcher only works with plain object types. It will fail for union types an
```ts
import { expectTypeOf } from 'vitest'

type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }
type ResponsiveProp<T> = T | T[] | { xs?: T, sm?: T, md?: T }

interface CSSProperties {
margin?: string
padding?: string
}
interface CSSProperties { margin?: string, padding?: string }

function getResponsiveProp<T>(_props: T): ResponsiveProp<T> {
return {}
Expand All @@ -106,11 +103,7 @@ const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }

expectTypeOf(getResponsiveProp(cssProperties))
.extract<{ xs?: any }>() // extracts the last type from a union
.toEqualTypeOf<{
xs?: CSSProperties
sm?: CSSProperties
md?: CSSProperties
}>()
.toEqualTypeOf<{ xs?: CSSProperties, sm?: CSSProperties, md?: CSSProperties }>()

expectTypeOf(getResponsiveProp(cssProperties))
.extract<unknown[]>() // extracts an array from a union
Expand All @@ -130,21 +123,20 @@ expectTypeOf(getResponsiveProp(cssProperties))
```ts
import { expectTypeOf } from 'vitest'

type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }
type ResponsiveProp<T> = T | T[] | { xs?: T, sm?: T, md?: T }

interface CSSProperties { margin?: string; padding?: string }
interface CSSProperties { margin?: string, padding?: string }

function getResponsiveProp<T>(\_props: T): ResponsiveProp<T> {
return {}
function getResponsiveProp<T>(_props: T): ResponsiveProp<T> {
return {}
}

const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }

expectTypeOf(getResponsiveProp(cssProperties))
.exclude<unknown[]>()
.exclude<{ xs?: unknown }>() // or just .exclude<unknown[] | { xs?: unknown }>()
.toEqualTypeOf<CSSProperties>()

.exclude<unknown[]>()
.exclude<{ xs?: unknown }>() // or just .exclude<unknown[] | { xs?: unknown }>()
.toEqualTypeOf<CSSProperties>()
```

::: warning
Expand Down
2 changes: 1 addition & 1 deletion api/expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ test('expect.soft test', () => {

```ts
interface ExpectPoll extends ExpectStatic {
(actual: () => T, options?: { interval?: number; timeout?: number; message?: string }): Promise<Assertions<T>>
(actual: () => T, options?: { interval?: number, timeout?: number, message?: string }): Promise<Assertions<T>>
}
```

Expand Down
7 changes: 5 additions & 2 deletions api/vi.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,13 @@ test('importing the next module imports mocked one', async () => {
### vi.mocked

```ts
function mocked<T>(object: T, deep?: boolean): MaybeMockedDeep<T>
function mocked<T>(
object: T,
options?: { partial?: boolean; deep?: boolean }
deep?: boolean
): MaybeMockedDeep<T>
function mocked<T>(
object: T,
options?: { partial?: boolean, deep?: boolean }
): MaybePartiallyMockedDeep<T>
```

Expand Down
176 changes: 40 additions & 136 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,138 +1,42 @@
import antfu, { GLOB_SRC } from '@antfu/eslint-config'

export default antfu(
{
vue: true,
// Disable tests rules because we need to test with various setup
test: false,
// This replaces the old `.gitignore`
ignores: [
'**/coverage',
'**/*.snap',
'**/bench.json',
'**/fixtures',
'**/assets/**',
'**/*.d.ts',
'**/*.timestamp-*',
'test/core/src/self',
'test/core/test/mocking/already-hoisted.test.ts',
'test/cache/cache/.vitest-base/results.json',
'test/core/src/wasm/wasm-bindgen-no-cyclic',
'test/workspaces/results.json',
'test/workspaces-browser/results.json',
'test/reporters/fixtures/with-syntax-error.test.js',
'test/network-imports/public/[email protected]',
'test/coverage-test/src/transpiled.js',
'test/coverage-test/src/original.ts',
'test/cli/deps/error/*',
'examples/**/mockServiceWorker.js',
'examples/sveltekit/.svelte-kit',
'packages/browser/**/esm-client-injector.js',
// contains technically invalid code to display pretty diff
'docs/guide/snapshot.md',
// uses invalid js example
'docs/advanced/api/import-example.md',
'docs/guide/examples/*.md',
],
},
{
rules: {
// prefer global Buffer to not initialize the whole module
'node/prefer-global/buffer': 'off',
'node/prefer-global/process': 'off',
'no-empty-pattern': 'off',
'antfu/indent-binary-ops': 'off',
'unused-imports/no-unused-imports': 'error',
'style/member-delimiter-style': [
'error',
{
multiline: { delimiter: 'none' },
singleline: { delimiter: 'semi' },
},
],
// let TypeScript handle this
'no-undef': 'off',
'ts/no-invalid-this': 'off',
'eslint-comments/no-unlimited-disable': 'off',
'curly': ['error', 'all'],

// TODO: migrate and turn it back on
'ts/ban-types': 'off',
'ts/no-unsafe-function-type': 'off',

'no-restricted-imports': [
'error',
{
paths: ['path'],
},
],

'import/no-named-as-default': 'off',
},
},
{
files: [`packages/*/*.{js,mjs,d.ts}`],
rules: {
'antfu/no-import-dist': 'off',
},
},
{
files: [`packages/${GLOB_SRC}`],
rules: {
'no-restricted-imports': [
'error',
{
paths: ['vitest', 'path', 'vitest/node'],
},
],
},
},
{
// these files define vitest as peer dependency
files: [`packages/{coverage-*,ui,browser,web-worker,browser-*}/${GLOB_SRC}`],
rules: {
'no-restricted-imports': [
'error',
{
paths: ['path'],
},
],
},
},
{
files: [
`docs/${GLOB_SRC}`,
`**/*.md`,
`**/*.md/${GLOB_SRC}`,
],
rules: {
'perfectionist/sort-imports': 'off',
'style/max-statements-per-line': 'off',
'import/newline-after-import': 'off',
'import/first': 'off',
'unused-imports/no-unused-imports': 'off',
'ts/method-signature-style': 'off',
'no-self-compare': 'off',
'import/no-mutable-exports': 'off',
},
},
{
files: [
`docs/${GLOB_SRC}`,
`packages/web-worker/${GLOB_SRC}`,
`test/core/${GLOB_SRC}`,
],
rules: {
'no-restricted-globals': 'off',
},
},
{
files: [
`test/${GLOB_SRC}`,
],
rules: {
'antfu/no-top-level-await': 'off',
'unicorn/consistent-function-scoping': 'off',
},
},
)
export default antfu({
stylistic: true,
typescript: true,
vue: true,
jsonc: false,
yaml: false,
ignores: [
'dist',
'node_modules',
'*.svelte',
'*.snap',
'*.d.ts',
'coverage',
'!.vitepress',
// contains technically invalid code to display pretty diff
'guide/snapshot.md',
// uses invalid js example
'advanced/api/import-example.md',
'guide/examples/*.md',
],
rules: {
'no-restricted-globals': 'off',
'no-empty-pattern': 'off',
},
}, {
files: [
`**/*.md`,
`**/*.md/${GLOB_SRC}`,
],
rules: {
'perfectionist/sort-imports': 'off',
'style/max-statements-per-line': 'off',
'import/newline-after-import': 'off',
'import/first': 'off',
'unused-imports/no-unused-imports': 'off',
'ts/method-signature-style': 'off',
'no-self-compare': 'off',
'import/no-mutable-exports': 'off',
},
})
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"prefetch": "tsx .vitepress/scripts/fetch-avatars.ts",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"generate-pwa-icons": "pwa-assets-generator"
"generate-pwa-icons": "pwa-assets-generator",
"prepare": "simple-git-hooks"
},
"dependencies": {
"@vueuse/core": "latest",
Expand All @@ -41,8 +42,10 @@
"esno": "^4.8.0",
"fs-extra": "^11.3.0",
"https-localhost": "^4.7.1",
"lint-staged": "^16.2.6",
"ofetch": "^1.4.1",
"pathe": "^2.0.3",
"simple-git-hooks": "^2.13.1",
"tinyglobby": "latest",
"tsx": "^4.19.3",
"typescript": "^5.8.2",
Expand All @@ -55,5 +58,11 @@
"vitepress-plugin-tabs": "^0.7.3",
"vitest": "^4.0.6",
"workbox-window": "^7.3.0"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": "eslint --fix"
}
}
Loading