Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9409

execa を試してみた

$
0
0
背景 Node.js の CLI ツールを作っていて、CLI ツールの E2E テストをしたかった。テスト内でコマンドを実行するツール調べていたら execa というものがあったので触ってみた。 (ちなみに execa は netlify cli や create-react-app の E2E テストでも使われています) 使い方 import {execa} from 'execa'; const test = async () => { const res = await execa('echo', ['unicorns']); console.log(res); } test() 出力結果 $ node index.js { command: 'echo unicorns', escapedCommand: 'echo unicorns', exitCode: 0, stdout: 'unicorns', stderr: '', all: undefined, failed: false, timedOut: false, isCanceled: false, killed: false } 標準出力や、標準エラー出力、ステータスコード何かを返してくれるので、CLI ツールの E2E テストには便利ですね。

Viewing all articles
Browse latest Browse all 9409

Trending Articles