[英]Spectron and electron without exe files
我正在嘗試使用Electron構建應用程序。
我需要根據電子env和使用電子封裝進行一些單元測試。
這樣,我使用spectron來模擬我的應用程序。
在文檔中,我寫道我必須在'path'屬性中放入我的可執行文件所在的路徑。 我現在沒有可執行文件,我處於開發模式。
以下是我根據另一個問題嘗試的內容:
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:我使用摩卡柴和sinon。
謝謝你的幫助
起初我是為了測試而創建一個可執行文件,但實際上並不是必需的。
該示例傳遞了一個名為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。 以上對我有用。
如果您使用doc中提到的電子預建,您還可以為變量路徑提供“電子”:
路徑 - 必填。 要啟動的Electron應用程序的字符串路徑。 注意:如果您想直接使用應用程序的主腳本調用電子,那么您應該通過電子預建指定路徑為電子,並將應用程序的主腳本路徑指定為args數組中的第一個參數。
我覺得它看起來像這樣:
import electron from 'electron'
import { Application } from 'spectron'
describe('application launch', function () {
this.timeout(10000)
beforeEach(function () {
this.app = new Application({
path: electron,
args: ['app']
})
return this.app.start()
})
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.