-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: 各パッケージのテストを jest から vitest への移行した #468
Conversation
P.S. テストの実行には失敗する
@@ -1,3 +1,4 @@ | |||
import { describe, test, expect } from 'vitest'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import しないグローバルAPI方式もありますが、TypeScript の型エラーが発生して別途設定が必要になってくるので、あえて import する形式で実装しています。
console.error = vi.fn(); | ||
vi.spyOn(Log, 'error'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vitest では .mockImplementation()
の引数が必須なので、console.error()
をモックする形で実装しました。そのほうが、Log.error()
の内部処理をなるべく実行しつつテストできるので。
jest.spyOn(helper, 'generateFileIfNotExist').mockImplementation(); | ||
console.log = jest.fn(); | ||
console.error = jest.fn(); | ||
vi.spyOn(helper, 'generateFileIfNotExist').mockReturnValue(undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vitest だと .mockImplementation()
の引数が必須になるので、.mockReturnValue(undefined)
で対応しています。( 他のファイルも同様です )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
副作用系は undefined になるイメージですね。
jest.spyOn(process, 'exit').mockImplementation(); | ||
jest.spyOn(Log, 'error').mockImplementation(); | ||
vi.spyOn(process, 'cwd').mockReturnValue('foo'); | ||
vi.spyOn(process, 'exit').mockReturnValue(undefined as never); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process.exit()
の返り値が never
なので as never
を使って対応する必要がありました。
@@ -1 +1 @@ | |||
export type CliExecFn = (argv?: string[]) => void; | |||
export type CliExecFn = (argv?: string[]) => void | Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
より正確な型付けを行いました。動作に影響はありません。
// markdownToHtml で diff を使っているので、あらかじめ読み込んでおく | ||
loadLanguages('diff'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
本来は Babel を使って自動で行っている処理ですが、vitest だと Babel がうまく動作しなかったので、手動で loadLanguages()
を実行しています。
ローカルでテストが成功しないため確認中です。私の環境の問題の可能性高。
|
リポジトリを作り直して解決しました |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
📑 Summary
packages 内のパッケージのテストを jest から vitest へ移行しました。
Resolves #419
📋 Tasks
プルリクエストを作成いただく際、お手数ですが以下の内容についてご確認をお願いします。
canary
ブランチに対するプルリクエストであるより詳しい内容は Pull Request Policy を参照してください。