Jestjs 使用Spectron来;模拟;开玩笑时的电子测试
我正在用Jest测试Electron应用程序的库代码。Jest对Jestjs 使用Spectron来;模拟;开玩笑时的电子测试,jestjs,electron,spectron,Jestjs,Electron,Spectron,我正在用Jest测试Electron应用程序的库代码。Jest对要求做了一些奇怪的事情,这干扰了电子需要做的事情。。。我想 Spectron旨在允许您通过库调用创建电子应用程序,从而从测试框架中访问各种电子位 最终,我需要能够用一些来自electron的真实东西(比如创建浏览器窗口)来模拟require('electron'),主要是为了让各种库位能够按预期工作 下面是它应该工作的样子: 在package.json中: "jest": { "moduleNameMapper": {
要求做了一些奇怪的事情,这干扰了电子需要做的事情。。。我想
Spectron旨在允许您通过库调用创建电子应用程序,从而从测试框架中访问各种电子位
最终,我需要能够用一些来自electron的真实东西(比如创建浏览器窗口)来模拟require('electron')
,主要是为了让各种库位能够按预期工作
下面是它应该工作的样子:
在package.json中:
"jest": {
"moduleNameMapper": {
"^electron$": "<rootDir>/test/mocks/electron.js"
}
}
根据
app.electron的规定,在正常操作下,require('electron')
应该能够访问与require('electron')相同的东西
一些测试:
const { BrowserWindow } = require("electron")
test("some test", () => {
const window = new BrowserWindow()
// ...
})
但是,这会失败,因为app.electron
未定义,尽管app
本身已定义:
console.log test/mocks/electron.js:58
<ref *1> Application {
host: '127.0.0.1',
port: 9515,
quitTimeout: 1000,
startTimeout: 5000,
waitTimeout: 5000,
connectionRetryCount: 10,
connectionRetryTimeout: 30000,
nodePath: '~/.nvm/versions/node/v13.0.1/bin/node',
path: '~/electron-hello-world/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron',
args: [],
chromeDriverArgs: [],
env: {},
workingDirectory: '~/electron-hello-world',
debuggerAddress: undefined,
chromeDriverLogPath: undefined,
webdriverLogPath: undefined,
webdriverOptions: {},
requireName: 'require',
api: Api { app: [Circular *1], requireName: 'require' },
transferPromiseness: [Function (anonymous)]
}
console.log test/mocks/electron.js:58
应用{
主持人:“127.0.0.1”,
港口:9515,
退出时间:1000,
起始时间:5000,
等待超时:5000,
connectionRetryCount:10,
connectionRetryTimeout:30000,
nodePath:“~/.nvm/versions/node/v13.0.1/bin/node”,
路径:“~/electron hello world/node_modules/electron/dist/electron.app/Contents/MacOS/electron”,
args:[],
铬驱动参数:[],
环境:{},
工作目录:“~/electron hello world”,
debuggerAddress:未定义,
chromeDriverLogPath:未定义,
webdriverLogPath:未定义,
webdriverOptions:{},
requireName:“require”,
api:api{app:[Circular*1],requireName:'require'},
转让承诺:[功能(匿名)]
}
我真的不知道从这里到哪里去。正在寻找任何解决方案是否有此方面的更新?我也有类似的问题。嗯,我想我没有取得任何进展,但我明天会检查。
console.log test/mocks/electron.js:58
<ref *1> Application {
host: '127.0.0.1',
port: 9515,
quitTimeout: 1000,
startTimeout: 5000,
waitTimeout: 5000,
connectionRetryCount: 10,
connectionRetryTimeout: 30000,
nodePath: '~/.nvm/versions/node/v13.0.1/bin/node',
path: '~/electron-hello-world/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron',
args: [],
chromeDriverArgs: [],
env: {},
workingDirectory: '~/electron-hello-world',
debuggerAddress: undefined,
chromeDriverLogPath: undefined,
webdriverLogPath: undefined,
webdriverOptions: {},
requireName: 'require',
api: Api { app: [Circular *1], requireName: 'require' },
transferPromiseness: [Function (anonymous)]
}