2

Electron を使用してアプリケーションを構築しようとしています。

electron 環境に基づいて、electron パッケージを使用して単体テストを行う必要があります。

このようにして、スペクトロンを使用してアプリケーションをシミュレートしています。

ドキュメントには、実行可能ファイルがあるパスを「パス」プロパティに入力する必要があると書かれています。今のところ実行可能ファイルはありません。開発モードです。

別の質問に基づいて私が試したことは次のとおりです。

beforeEach(() => {
    app = new Application({
        path: 'node_modules/.bin/electron'
    });
    app.start().then(res => console.log(res), err => console.log(err));

});

プロンプトには何も表示されず、次のテストは、未定義のオブジェクトで getWindowCount を取得できないことを示しています (明らかに、アプリはインスタンス化されていません)。

 it('should call currentWindow', (done) => {
            app.client.getWindowCount().then((count) => {
                expect(count).to.equals(1);
                done();
            });
        });

私のテスト環境を機能させるために、このパスに何を入れるべきか誰かが知っていますか?

PS : モカチャイとシノンを使っています。

ご協力いただきありがとうございます

4

2 に答える 2

11

最初はテスト目的で実行可能ファイルを作成していましたが、実際には必要ありません。

Spectron にexample testglobal setupがあることがわかります。

この例ではargsというオプションを渡していますが、それはまさにあなたが見逃しているものです。これは私がやっていることです:

  var appPath = path.resolve(__dirname, '../'); //require the whole thing
  var electronPath = path.resolve(__dirname, '../node_modules/.bin/electron');

  beforeEach(function() {
    myApp = new Application({
      path: electronPath,
      args: [appPath], // pass args along with path
    });

   return myApp.start().then(function() {
     assert.equal(myApp.isRunning(), true);
     chaiAsPromised.transferPromiseness = myApp.transferPromiseness;
     return myApp;
   });
 });

私のテストは ./tests/app-test.js にあります。上記は私にとってはうまくいきます。

于 2016-05-20T21:51:44.363 に答える