-
-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: replace jest with vitest (#156)
* test: replace jest with vitest * chore: remove built-in modules prefix * chore: version bump to v2.0.0-beta.0
- Loading branch information
Showing
31 changed files
with
204 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,17 @@ | ||
import { jest, test, expect, beforeEach, afterAll } from '@jest/globals' | ||
|
||
const mockedInit = jest.fn() | ||
const mockedList = jest.fn() | ||
import { vi, test, expect } from 'vitest' | ||
|
||
const mockArgv = (...args: string[]): () => void => { | ||
const original = process.argv | ||
process.argv = original.slice(0, 2).concat(...args) | ||
return () => { process.argv = original } | ||
} | ||
|
||
beforeEach(async () => { | ||
jest.resetAllMocks() | ||
jest.resetModules() | ||
jest.mock('.', () => ({ __esModule: true, default: mockedInit, list: mockedList })) | ||
}) | ||
|
||
afterAll(async () => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
test('unit:cli:init', async () => { | ||
const restore = mockArgv('template', 'project', '--force', '--offline', '--foo', 'bar') | ||
await import('./cli') | ||
expect(mockedInit).toHaveBeenCalled() | ||
expect(mockedInit.mock.calls[0][0]).toBe('template') | ||
expect(mockedInit.mock.calls[0][1]).toBe('project') | ||
expect(mockedInit.mock.calls[0][2]).toEqual({ '--': [], f: true, force: true, o: true, offline: true, foo: 'bar' }) | ||
restore() | ||
}) | ||
|
||
test('unit:cli:list', async () => { | ||
const restore = mockArgv('list', 'zce', '--json', '--short') | ||
await import('./cli') | ||
expect(mockedList).toHaveBeenCalled() | ||
expect(mockedList.mock.calls[0][0]).toBe('zce') | ||
expect(mockedList.mock.calls[0][1]).toEqual({ '--': [], j: true, json: true, s: true, short: true }) | ||
restore() | ||
}) | ||
|
||
test('unit:cli:help', async () => { | ||
const restore = mockArgv('--help') | ||
const log = jest.spyOn(console, 'log') | ||
const log = vi.spyOn(console, 'log') | ||
await import('./cli') | ||
expect(log).toHaveBeenCalledTimes(1) | ||
expect(log.mock.calls[0][0]).toContain('$ caz <template> [project]') | ||
log.mockRestore() | ||
restore() | ||
}) | ||
|
||
// // TODO: error | ||
// // https://github.com/facebook/jest/issues/5620 | ||
// test('unit:cli:error', async () => { | ||
// const error = jest.spyOn(console, 'error') | ||
// const exit = jest.spyOn(process, 'exit') | ||
// const restore = mockArgv() | ||
// await import('./cli') | ||
// expect(error).toHaveBeenCalled() | ||
// expect(exit).toHaveBeenCalled() | ||
// restore() | ||
// }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.