snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
This commit is contained in:
5
packages/query-test-utils/eslint.config.js
Normal file
5
packages/query-test-utils/eslint.config.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// @ts-check
|
||||
|
||||
import rootConfig from './root.eslint.config.js'
|
||||
|
||||
export default [...rootConfig]
|
||||
44
packages/query-test-utils/package.json
Normal file
44
packages/query-test-utils/package.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "@tanstack/query-test-utils",
|
||||
"version": "0.0.0",
|
||||
"description": "Internal test utilities for TanStack Query",
|
||||
"author": "Jonghyeon Ko <manudeli.ko@gmail.com>",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/TanStack/query.git",
|
||||
"directory": "packages/query-test-utils"
|
||||
},
|
||||
"homepage": "https://tanstack.com/query",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/tannerlinsley"
|
||||
},
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"module": "src/index.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./src/index.ts",
|
||||
"default": "./src/index.ts"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "premove ./build ./coverage ./dist-ts ./.cache/test-types",
|
||||
"test:eslint": "eslint --concurrency=auto ./src",
|
||||
"test:types": "npm-run-all --serial test:types:*",
|
||||
"test:types:tscurrent": "tsc --project tsconfig.json --outDir .cache/test-types/tscurrent --tsBuildInfoFile .cache/test-types/tscurrent.tsbuildinfo",
|
||||
"test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --project tsconfig.json --outDir .cache/test-types/ts70 --tsBuildInfoFile .cache/test-types/ts70.tsbuildinfo",
|
||||
"test:lib": "vitest",
|
||||
"test:lib:dev": "pnpm run test:lib --watch"
|
||||
},
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"npm-run-all2": "^5.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vitest": "^4.0.18"
|
||||
}
|
||||
}
|
||||
1
packages/query-test-utils/root.eslint.config.js
Symbolic link
1
packages/query-test-utils/root.eslint.config.js
Symbolic link
@@ -0,0 +1 @@
|
||||
../../eslint.config.js
|
||||
12
packages/query-test-utils/src/__test__/queryKey.test.ts
Normal file
12
packages/query-test-utils/src/__test__/queryKey.test.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { queryKey } from '../queryKey'
|
||||
|
||||
describe('queryKey', () => {
|
||||
it('should return a query key', () => {
|
||||
const key = queryKey()
|
||||
expect(key).toEqual(['query_1'])
|
||||
})
|
||||
it('should return a new query key each time', () => {
|
||||
expect(queryKey()).not.toEqual(queryKey())
|
||||
})
|
||||
})
|
||||
11
packages/query-test-utils/src/__test__/sleep.test.ts
Normal file
11
packages/query-test-utils/src/__test__/sleep.test.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { sleep } from '../sleep'
|
||||
|
||||
describe('sleep', () => {
|
||||
it('should sleep for the given amount of time', async () => {
|
||||
const start = Date.now()
|
||||
await sleep(100)
|
||||
const end = Date.now()
|
||||
expect(end - start).toBeGreaterThanOrEqual(100)
|
||||
})
|
||||
})
|
||||
3
packages/query-test-utils/src/index.ts
Normal file
3
packages/query-test-utils/src/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export { sleep } from './sleep'
|
||||
export { queryKey } from './queryKey'
|
||||
export { mockVisibilityState } from './mockVisibilityState'
|
||||
7
packages/query-test-utils/src/mockVisibilityState.ts
Normal file
7
packages/query-test-utils/src/mockVisibilityState.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { vi } from 'vitest'
|
||||
import type { MockInstance } from 'vitest'
|
||||
|
||||
export const mockVisibilityState = (
|
||||
value: DocumentVisibilityState,
|
||||
): MockInstance<() => DocumentVisibilityState> =>
|
||||
vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
|
||||
6
packages/query-test-utils/src/queryKey.ts
Normal file
6
packages/query-test-utils/src/queryKey.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
let queryKeyCount = 0
|
||||
|
||||
export const queryKey = (): Array<string> => {
|
||||
queryKeyCount++
|
||||
return [`query_${queryKeyCount}`]
|
||||
}
|
||||
4
packages/query-test-utils/src/sleep.ts
Normal file
4
packages/query-test-utils/src/sleep.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export const sleep = (ms: number): Promise<void> =>
|
||||
new Promise((resolve) => {
|
||||
setTimeout(resolve, ms)
|
||||
})
|
||||
8
packages/query-test-utils/tsconfig.json
Normal file
8
packages/query-test-utils/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist-ts",
|
||||
"rootDir": "."
|
||||
},
|
||||
"include": ["src", "*.config.ts", "*.config.js", "package.json"]
|
||||
}
|
||||
29
packages/query-test-utils/vite.config.ts
Normal file
29
packages/query-test-utils/vite.config.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { defineConfig } from 'vitest/config'
|
||||
|
||||
import packageJson from './package.json'
|
||||
|
||||
export default defineConfig({
|
||||
// fix from https://github.com/vitest-dev/vitest/issues/6992#issuecomment-2509408660
|
||||
resolve: {
|
||||
conditions: ['@tanstack/custom-condition'],
|
||||
},
|
||||
environments: {
|
||||
ssr: {
|
||||
resolve: {
|
||||
conditions: ['@tanstack/custom-condition'],
|
||||
},
|
||||
},
|
||||
},
|
||||
test: {
|
||||
name: packageJson.name,
|
||||
dir: './src',
|
||||
watch: false,
|
||||
coverage: {
|
||||
enabled: !!process.env.CI,
|
||||
provider: 'istanbul',
|
||||
include: ['src/**/*'],
|
||||
},
|
||||
typecheck: { enabled: true },
|
||||
restoreMocks: true,
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user