0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

execa を試してみた

Posted at

背景

Node.js の CLI ツールを作っていて、CLI ツールの E2E テストをしたかった。テスト内でコマンドを実行するツール調べていたら execa というものがあったので触ってみた。

(ちなみに execanetlify clicreate-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 テストには便利ですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?