Skip to content

Commit

Permalink
test: add not found case for getSuspensiveReactQueryPackageJson
Browse files Browse the repository at this point in the history
  • Loading branch information
gwansikk committed Dec 3, 2024
1 parent e9ef2f5 commit 3a46e54
Showing 1 changed file with 78 additions and 46 deletions.
124 changes: 78 additions & 46 deletions packages/react-query/src/bin/utils/package.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tanStackReactQueryPackageJson from '@tanstack/react-query/package.json'
import packageJson from '../../../package.json'
import {
getIndexFileContent,
getPackageJson,
getSuspensiveReactQueryPackageJson,
getTanStackReactQueryAPIs,
Expand Down Expand Up @@ -29,70 +30,101 @@ const version4APIs = [
]

describe('package', () => {
it('should get package.json', () => {
const result = getPackageJson()

expect(result).toBeDefined()
expect(result.name).toBe(packageJson.name)
expect(result.description).toBe(packageJson.description)
expect(result.version).toBe(packageJson.version)
describe('getPackageJson', () => {
it('should get package.json', () => {
const result = getPackageJson()

expect(result).toBeDefined()
expect(result.name).toBe(packageJson.name)
expect(result.description).toBe(packageJson.description)
expect(result.version).toBe(packageJson.version)
})
})

it('should get @tanstack/react-query package.json', () => {
const result = getTanStackReactQueryPackageJson()
describe('getTanStackReactQueryPackageJson', () => {
it('should get @tanstack/react-query package.json', () => {
const result = getTanStackReactQueryPackageJson()

expect(result).toBeDefined()
expect(result.name).toBe(tanStackReactQueryPackageJson.name)
expect(result.description).toBe(tanStackReactQueryPackageJson.description)
expect(result.version).toBe(tanStackReactQueryPackageJson.version)
expect(result).toBeDefined()
expect(result.name).toBe(tanStackReactQueryPackageJson.name)
expect(result.description).toBe(tanStackReactQueryPackageJson.description)
expect(result.version).toBe(tanStackReactQueryPackageJson.version)
})
})

it('should get the target @suspensive/react-query version from the index file content', () => {
const targetSuspensiveReactQueryVersion = getTargetSuspensiveReactQueryVersion()
describe('getTargetSuspensiveReactQueryVersion', () => {
it('should get the target @suspensive/react-query version from the index file content', () => {
const targetSuspensiveReactQueryVersion = getTargetSuspensiveReactQueryVersion()

expect(targetSuspensiveReactQueryVersion).toBe('4')
expect(targetSuspensiveReactQueryVersion).toBe('4')
})
})

it('should get the target @suspensive/react-query version 4 APIs', () => {
const apis = getTargetSuspensiveReactQueryAPIs()
describe('getTargetSuspensiveReactQueryAPIs', () => {
it('should get the target @suspensive/react-query version 4 APIs', () => {
const apis = getTargetSuspensiveReactQueryAPIs()

expect(apis).toEqual(version4APIs)
expect(apis).toEqual(version4APIs)
})
})

it('should get the @suspensive/react-query package.json for version 4', () => {
const result = getSuspensiveReactQueryPackageJson('4')
describe('getSuspensiveReactQueryPackageJson', () => {
it('should get the @suspensive/react-query package.json for version 4', () => {
const result = getSuspensiveReactQueryPackageJson('4')

expect(result).toBeDefined()
expect(result.name).toBe('@suspensive/react-query-4')
})
expect(result).toBeDefined()
expect(result.name).toBe('@suspensive/react-query-4')
})

it('should return correct APIs for version 5', () => {
const apis = getTanStackReactQueryAPIs('5')

expect(apis).toEqual([
'useSuspenseQuery',
'useSuspenseQueries',
'useSuspenseInfiniteQuery',
'usePrefetchQuery',
'usePrefetchInfiniteQuery',
'queryOptions',
'infiniteQueryOptions',
])
})
it('should get the @suspensive/react-query package.json for version 5', () => {
const result = getSuspensiveReactQueryPackageJson('5')

it('should return placeholder for version 4', () => {
const apis = getTanStackReactQueryAPIs('4')
expect(result).toBeDefined()
expect(result.name).toBe('@suspensive/react-query-5')
})

expect(apis).toEqual(['-'])
it('should get the @suspensive/react-query package.json for version 0', () => {
expect(() => getSuspensiveReactQueryPackageJson('0')).toThrow('@suspensive/react-query-0 is not found.')
})
})

it('should throw error for missing version', () => {
expect(() => getTanStackReactQueryAPIs('')).toThrow('@tanstack/react-query version is required')
describe('getTanStackReactQueryAPIs', () => {
it('should return correct APIs for version 5', () => {
const apis = getTanStackReactQueryAPIs('5')

expect(apis).toEqual([
'useSuspenseQuery',
'useSuspenseQueries',
'useSuspenseInfiniteQuery',
'usePrefetchQuery',
'usePrefetchInfiniteQuery',
'queryOptions',
'infiniteQueryOptions',
])
})

it('should return placeholder for version 4', () => {
const apis = getTanStackReactQueryAPIs('4')

expect(apis).toEqual(['-'])
})

it('should throw error for missing version', () => {
expect(() => getTanStackReactQueryAPIs('')).toThrow('@tanstack/react-query version is required')
})
})

describe('loadModule', () => {
it('should throw an error if the module cannot be resolved', () => {
expect(() => loadModule('unresolved-module-to-test')).toThrow('unresolved-module-to-test is not found.')
})
})
})

describe('loadModule', () => {
it('should return `{ exports: undefined, isSuccess: false }` if unresolved package', () => {
expect(loadModule('unresolved-module-to-test')).toStrictEqual({ exports: undefined, isSuccess: false })
describe('getIndexFileContent', () => {
it('should return the content of the index.js file', () => {
expect(() => getIndexFileContent('unresolved-module-to-test')).toThrow(
"no such file or directory, open 'unresolved-module-to-test'"
)
})
})
})

0 comments on commit 3a46e54

Please sign in to comment.