electronでテストを行う。
nodejs初心者なので、テストのセッティングも大変。
テストを書いておかないと不安なので、調べて見た。
その結果。
electron-mochaというライブラリを使えば良さそうということがわかった。インストールする
$ npm install -D electron-mocha
// どちらがいいかよく分かってない
// $ npm install -g electron-mocha
// 動作確認
$ npx mocha --help
// これではまだ動かない
$ npm test
Error: no test specified
mochaだけでtestディレクトリの中を探索してくれるようだ。test/testes.jsに以下の内容のファイルを作成した。(mochaの公式にあったやつ)
// test/testes.js
var assert = require('assert');
describe('Array', function() {
describe('#indexOf()', function() {
it('should return -1 when the value is not present', function() {
assert.equal([1, 2, 3].indexOf(4), -1);
});
});
});
これを保存し、npx mochaだけで動く。
npm testで動いてくれるよう、package.jsonを更新する。scriptsにtestを追加/修正すればいい。
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"test": "mocha", // 追加
"make": "electron-forge make",
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\""
},
これで、npm testで動作するようになった。
nodejs、面白いが難しい。簡単なアプリを作れるところまで行きたい。


コメント