Skip to content

Commit

Permalink
test: support more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bjohansebas committed Feb 2, 2025
1 parent 5950126 commit 1a4e94c
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion commands/__test__/upgrade.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { run } from 'jscodeshift/src/Runner'
import prompts from 'prompts'
import { upgrade } from '../upgrade'

jest.mock('jscodeshift/src/Runner', () => ({
Expand All @@ -10,7 +11,41 @@ describe('interactive mode', () => {
jest.clearAllMocks()
})

it.todo('runs without source params provided and select is true')
it('runs without source params provided and select is true', async () => {
const spyOnConsole = jest.spyOn(console, 'log').mockImplementation()

prompts.inject([['magic-redirect', 'req-param']])

await upgrade('__testfixtures__', { select: true })

expect(spyOnConsole).toHaveBeenCalled()
expect(spyOnConsole).toHaveBeenCalledTimes(3)
expect(run).toHaveBeenCalledTimes(2)
})

it('runs with source params provided and select is true', async () => {
const spyOnConsole = jest.spyOn(console, 'log').mockImplementation()

prompts.inject([['magic-redirect', 'req-param']])

await upgrade('__testfixtures__', { select: true })

expect(spyOnConsole).toHaveBeenCalled()
expect(spyOnConsole).toHaveBeenCalledTimes(3)
expect(run).toHaveBeenCalledTimes(2)
})

it('runs without source params provided and select is undefined', async () => {
const spyOnConsole = jest.spyOn(console, 'log').mockImplementation()

prompts.inject(['__testfixtures__'])

await upgrade(undefined)

expect(spyOnConsole).toHaveBeenCalled()
expect(spyOnConsole).toHaveBeenCalledTimes(5)
expect(run).toHaveBeenCalledTimes(4)
})
})

describe('Non-Interactive Mode', () => {
Expand All @@ -24,6 +59,8 @@ describe('Non-Interactive Mode', () => {
await upgrade('__testfixtures__')

expect(spyOnConsole).toHaveBeenCalled()
expect(spyOnConsole).toHaveBeenCalledTimes(5)
expect(spyOnConsole).toHaveBeenLastCalledWith('\n> All codemods have been applied successfully. \n')
expect(run).toHaveBeenCalledTimes(4)
})
})

0 comments on commit 1a4e94c

Please sign in to comment.