Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(*): official @vitest/eslint-plugin #7896

Merged
merged 2 commits into from
Aug 19, 2024
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
10 changes: 10 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// @ts-ignore Needed due to moduleResolution Node vs Bundler
import { tanstackConfig } from '@tanstack/config/eslint'
import pluginCspell from '@cspell/eslint-plugin'
import vitest from '@vitest/eslint-plugin'

export default [
...tanstackConfig,
Expand Down Expand Up @@ -40,4 +41,13 @@ export default [
'no-case-declarations': 'off',
},
},
{
files: ['**/*.spec.ts*', '**/*.test.ts*', '**/*.test-d.ts*'],
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
settings: { vitest: { typecheck: true } },
},
]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@types/react": "npm:types-react@rc",
"@types/react-dom": "npm:types-react-dom@rc",
"@vitest/coverage-istanbul": "^2.0.4",
"@vitest/eslint-plugin": "^1.0.2",
"cpy-cli": "^5.0.0",
"esbuild-plugin-file-path-extensions": "^2.1.2",
"eslint": "^8.57.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('injectMutationState', () => {
})

describe('injectMutationState', () => {
test('should return variables after calling mutate', async () => {
test('should return variables after calling mutate 1', async () => {
const mutationKey = ['mutation']
const variables = 'foo123'

Expand Down Expand Up @@ -91,7 +91,7 @@ describe('injectMutationState', () => {
expect(mutationState()).toEqual([variables2])
})

test('should return variables after calling mutate', async () => {
test('should return variables after calling mutate 2', async () => {
queryClient.clear()
const mutationKey = ['mutation']
const variables = 'bar234'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { TestBed } from '@angular/core/testing'
import { assertInjector } from './assert-injector'

describe(assertInjector.name, () => {
describe('assertInjector', () => {
const token = new InjectionToken('token', {
factory: () => 1,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import { TestBed } from '@angular/core/testing'
import { createNoopInjectionToken } from './create-injection-token'

describe(createNoopInjectionToken.name, () => {
describe('createNoopInjectionToken', () => {
describe('given an injection token', () => {
const [injectFn, provideFn] = createNoopInjectionToken<number, true>(
'noop',
Expand Down
24 changes: 12 additions & 12 deletions packages/query-core/src/__tests__/OmitKeyof.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('OmitKeyof', () => {
// @ts-expect-error Type does not satisfy the constraint keyof A
'z' | 'y'
>
>().toEqualTypeOf<ExpectedType>
>().toEqualTypeOf<ExpectedType>()
expectTypeOf<
OmitKeyof<
A,
Expand All @@ -36,7 +36,7 @@ describe('OmitKeyof', () => {
'z' | 'y',
'strictly'
>
>().toEqualTypeOf<ExpectedType>
>().toEqualTypeOf<ExpectedType>()

// 2. safely
expectTypeOf<
Expand All @@ -46,15 +46,15 @@ describe('OmitKeyof', () => {
// @ts-expect-error Type does not satisfy the constraint keyof A
'z' | 'y'
>
>().toEqualTypeOf<ExpectedType>
>().toEqualTypeOf<ExpectedType>()
expectTypeOf<
OmitKeyof<
A,
// With 'safely', OmitKeyof can use 'z' as type parameter like original Omit but This support autocomplete too yet for DX.
'z' | 'y',
'safely'
>
>().toEqualTypeOf<ExpectedType>
>().toEqualTypeOf<ExpectedType>()
})

it("'s number key type check", () => {
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('OmitKeyof', () => {
// @ts-expect-error Type does not satisfy the constraint keyof A
3 | 2
>
>().toEqualTypeOf<ExpectedType>
>().toEqualTypeOf<ExpectedType>()
expectTypeOf<
OmitKeyof<
A,
Expand All @@ -91,7 +91,7 @@ describe('OmitKeyof', () => {
3 | 2,
'strictly'
>
>().toEqualTypeOf<ExpectedType>
>().toEqualTypeOf<ExpectedType>()

// 2. safely
expectTypeOf<
Expand All @@ -101,15 +101,15 @@ describe('OmitKeyof', () => {
// @ts-expect-error Type does not satisfy the constraint keyof A
3 | 2
>
>().toEqualTypeOf<ExpectedType>
>().toEqualTypeOf<ExpectedType>()
expectTypeOf<
OmitKeyof<
A,
// With 'safely', OmitKeyof can use 3 as type parameter like original Omit but This support autocomplete too yet for DX.
3 | 2,
'safely'
>
>().toEqualTypeOf<ExpectedType>
>().toEqualTypeOf<ExpectedType>()
})

it("'s symbol key type check", () => {
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('OmitKeyof', () => {
// @ts-expect-error Type does not satisfy the constraint keyof A
typeof symbol3 | typeof symbol2
>
>().toEqualTypeOf<ExpectedType>
>().toEqualTypeOf<ExpectedType>()
expectTypeOf<
OmitKeyof<
A,
Expand All @@ -152,7 +152,7 @@ describe('OmitKeyof', () => {
typeof symbol3 | typeof symbol2,
'strictly'
>
>().toEqualTypeOf<ExpectedType>
>().toEqualTypeOf<ExpectedType>()

// 2. safely
expectTypeOf<
Expand All @@ -162,14 +162,14 @@ describe('OmitKeyof', () => {
// @ts-expect-error Type does not satisfy the constraint keyof A
typeof symbol3 | typeof symbol2
>
>().toEqualTypeOf<ExpectedType>
>().toEqualTypeOf<ExpectedType>()
expectTypeOf<
OmitKeyof<
A,
// With 'safely', OmitKeyof can use symbol3 as type parameter like original Omit but This support autocomplete too yet for DX.
typeof symbol3 | typeof symbol2,
'safely'
>
>().toEqualTypeOf<ExpectedType>
>().toEqualTypeOf<ExpectedType>()
})
})
4 changes: 2 additions & 2 deletions packages/query-core/src/__tests__/mutations.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ describe('mutations', () => {
expect(error).toEqual(new Error('No mutationFn found'))
})

test('mutate update the mutation state even without an active subscription', async () => {
test('mutate update the mutation state even without an active subscription 1', async () => {
const onSuccess = vi.fn()
const onSettled = vi.fn()

Expand All @@ -364,7 +364,7 @@ describe('mutations', () => {
expect(onSettled).not.toHaveBeenCalled()
})

test('mutate update the mutation state even without an active subscription', async () => {
test('mutate update the mutation state even without an active subscription 2', async () => {
const onSuccess = vi.fn()
const onSettled = vi.fn()

Expand Down
8 changes: 4 additions & 4 deletions packages/query-core/src/__tests__/queryClient.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ describe('queryClient', () => {
expect(testCache.find({ queryKey: key })).toBe(testCache.get('someKey'))
})

test('should create a new query if query was not found', () => {
test('should create a new query if query was not found 1', () => {
const key = queryKey()
queryClient.setQueryData(key, 'bar')
expect(queryClient.getQueryData(key)).toBe('bar')
})

test('should create a new query if query was not found', () => {
test('should create a new query if query was not found 2', () => {
const key = queryKey()
queryClient.setQueryData(key, 'qux')
expect(queryClient.getQueryData(key)).toBe('qux')
Expand Down Expand Up @@ -1074,7 +1074,7 @@ describe('queryClient', () => {
expect(queryFn2).toHaveBeenCalledTimes(1)
})

test('should be able to refetch all active and inactive queries', async () => {
test('should be able to refetch all active and inactive queries (queryClient.refetchQueries()', async () => {
const key1 = queryKey()
const key2 = queryKey()
const queryFn1 = vi
Expand All @@ -1097,7 +1097,7 @@ describe('queryClient', () => {
expect(queryFn2).toHaveBeenCalledTimes(2)
})

test('should be able to refetch all active and inactive queries', async () => {
test('should be able to refetch all active and inactive queries (queryClient.refetchQueries({ type: "all" }))', async () => {
const key1 = queryKey()
const key2 = queryKey()
const queryFn1 = vi
Expand Down
4 changes: 2 additions & 2 deletions packages/query-core/src/__tests__/queryObserver.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('queryObserver', () => {
unsubscribe()
})

test('should not be re-fetched if not subscribed to after enabled was toggled to true', async () => {
test('should not be re-fetched if not subscribed to after enabled was toggled to true (fetchStatus: "idle")', async () => {
const unsubscribe = observer.subscribe(vi.fn())

// Toggle enabled
Expand All @@ -175,7 +175,7 @@ describe('queryObserver', () => {
expect(count).toBe(0)
})

test('should not be re-fetched if not subscribed to after enabled was toggled to true', async () => {
test('should not be re-fetched if not subscribed to after enabled was toggled to true (fetchStatus: "fetching")', async () => {
const unsubscribe = observer.subscribe(vi.fn())

// Toggle enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function getMockStorage(limitSize?: number) {
} as any as Storage
}

describe('create persister ', () => {
describe('create persister', () => {
test('basic store and recover', async () => {
const queryCache = new QueryCache()
const mutationCache = new MutationCache()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ describe('useInfiniteQuery', () => {
expect(abortListeners[callIndex]).not.toHaveBeenCalled()
})

it('should not cancel an ongoing fetchNextPage request when another fetchNextPage is invoked if `cancelRefetch: false` is used ', async () => {
it('should not cancel an ongoing fetchNextPage request when another fetchNextPage is invoked if `cancelRefetch: false` is used', async () => {
const key = queryKey()
const start = 10
const onAborts: Array<Mock<(...args: Array<any>) => any>> = []
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/src/__tests__/useQueries.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('UseQueries config object overload', () => {
expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>()
})

it('it should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQuery', () => {
it('should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQuery', () => {
const query1 = queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(1),
Expand Down
3 changes: 2 additions & 1 deletion packages/react-query/src/__tests__/useQueries.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ describe('useQueries', () => {
}
})

it('correctly returns types when passing through queryOptions ', () => {
it('correctly returns types when passing through queryOptions', () => {
// @ts-expect-error (Page component is not rendered)
function Page() {
// data and results types are correct when using queryOptions
Expand Down Expand Up @@ -713,6 +713,7 @@ describe('useQueries', () => {
queryFn:
fn && fn !== skipToken
? (ctx: QueryFunctionContext<TQueryKey>) => {
// eslint-disable-next-line vitest/valid-expect
expectTypeOf<TQueryKey>(ctx.queryKey)
return fn.call({}, ctx)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/src/__tests__/useQuery.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('initialData', () => {
expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>()
})

it('it should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQuery', () => {
it('should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQuery', () => {
const options = queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(1),
Expand Down
4 changes: 2 additions & 2 deletions packages/react-query/src/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3959,7 +3959,7 @@ describe('useQuery', () => {
expect(results[2]).toMatchObject({ data: 'fetched data', isStale: false })
})

it('it should support enabled:false in query object syntax', async () => {
it('should support enabled:false in query object syntax', async () => {
const key = queryKey()
const queryFn = vi.fn<(...args: Array<unknown>) => string>()
queryFn.mockImplementation(() => 'data')
Expand Down Expand Up @@ -5911,7 +5911,7 @@ describe('useQuery', () => {
})
})

it('it should have status=error on mount when a query has failed', async () => {
it('should have status=error on mount when a query has failed', async () => {
const key = queryKey()
const states: Array<UseQueryResult<unknown>> = []
const error = new Error('oops')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('UseSuspenseQueries config object overload', () => {
expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>()
})

it('it should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQuery', () => {
it('should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQuery', () => {
const query1 = queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(1),
Expand Down
12 changes: 9 additions & 3 deletions packages/solid-query/src/__tests__/createInfiniteQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ describe('useInfiniteQuery', () => {
expect(abortListeners[callIndex]).not.toHaveBeenCalled()
})

it('should not cancel an ongoing fetchNextPage request when another fetchNextPage is invoked if `cancelRefetch: false` is used ', async () => {
it('should not cancel an ongoing fetchNextPage request when another fetchNextPage is invoked if `cancelRefetch: false` is used', async () => {
const key = queryKey()
const start = 10
const onAborts: Array<Mock<(...args: Array<any>) => any>> = []
Expand Down Expand Up @@ -2053,7 +2053,10 @@ describe('useInfiniteQuery', () => {

const rendered = render(() => <Page />)

await waitFor(() => rendered.getByText('Status: custom client'))
await waitFor(() => {
const statusElement = rendered.getByText('Status: custom client')
expect(statusElement).toBeInTheDocument()
})
})

it('should work with infiniteQueryOptions', async () => {
Expand All @@ -2079,6 +2082,9 @@ describe('useInfiniteQuery', () => {

const rendered = render(() => <Page />)

await waitFor(() => rendered.getByText('Status: 220'))
await waitFor(() => {
const statusElement = rendered.getByText('Status: 220')
expect(statusElement).toBeInTheDocument()
})
})
})
1 change: 1 addition & 0 deletions packages/solid-query/src/__tests__/createQueries.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ describe('useQueries', () => {
queryKey: key,
queryFn: fn
? (ctx: QueryFunctionContext<TQueryKey>) => {
// eslint-disable-next-line vitest/valid-expect
expectTypeOf<TQueryKey>(ctx.queryKey)
return (fn as QueryFunction<TQueryFnData, TQueryKey>).call(
{},
Expand Down
8 changes: 4 additions & 4 deletions packages/solid-query/src/__tests__/createQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ describe('createQuery', () => {
expect(states[1]).toMatchObject({ data: 'test' })
})

it('should be able to select a part of the data with select in object syntax', async () => {
it('should be able to select a part of the data with select in object syntax 2', async () => {
const key = queryKey()
const states: Array<CreateQueryResult<string>> = []

Expand Down Expand Up @@ -831,7 +831,7 @@ describe('createQuery', () => {
expect(states[1]).toMatchObject({ data: 'test' })
})

it('should be able to select a part of the data with select in object syntax', async () => {
it('should be able to select a part of the data with select in object syntax 1', async () => {
const key = queryKey()
const states: Array<CreateQueryResult<string>> = []

Expand Down Expand Up @@ -3754,7 +3754,7 @@ describe('createQuery', () => {
expect(results[2]).toMatchObject({ data: 'fetched data', isStale: false })
})

it('it should support enabled:false in query object syntax', async () => {
it('should support enabled:false in query object syntax', async () => {
const key = queryKey()
const queryFn = vi.fn<(...args: Array<unknown>) => string>()
queryFn.mockImplementation(() => 'data')
Expand Down Expand Up @@ -5913,7 +5913,7 @@ describe('createQuery', () => {
})
})

it('it should have status=error on mount when a query has failed', async () => {
it('should have status=error on mount when a query has failed', async () => {
const key = queryKey()
const states: Array<CreateQueryResult<unknown>> = []
const error = new Error('oops')
Expand Down
Loading
Loading