Skip to content

Commit

Permalink
feat: upgrade for Electron v5 support (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstrat authored and codebytere committed Jun 24, 2019
1 parent a64c809 commit 74f87c1
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 41 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ For given versions of Electron you must depend on a very specific version range
| `^2.0.0` | `^4.0.0` |
| `^3.0.0` | `^5.0.0` |
| `^4.0.0` | `^6.0.0` |
| `^5.0.0` | `^7.0.0` |

Learn more from [this presentation](https://speakerdeck.com/kevinsawicki/testing-your-electron-apps-with-chromedriver).

Expand Down Expand Up @@ -183,8 +184,8 @@ Create a new application with the following options:
### Node Integration

The Electron helpers provided by Spectron require accessing the core Electron
APIs in the renderer processes of your application. So if your Electron
application has `nodeIntegration` set to `false` then you'll need to expose a
APIs in the renderer processes of your application. So, either your Electron
application has `nodeIntegration` set to `true` or you'll need to expose a
`require` window global to Spectron so it can access the core Electron APIs.

You can do this by adding a [`preload`][preload] script that does the following:
Expand Down
14 changes: 0 additions & 14 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,6 @@ Application.prototype.createClient = function () {
args.push(arg)
})

// Since ChromeDriver v2.41, ChromeDriver will only connect
// if, either we precise a port for remote debugging, either
// the embedder (ie electron) made sure to pass `USER_DATA_DIR`
// to the remote debugging server.
// https://bitbucket.org/chromiumembedded/cef/issues/2476/cef-webdriver-instructions-will-need-to
// `USER_DATA_DIR` is properly passed to the remote debugging server
// since electron 5 (see electron/electron#17800)
// So, for now, we'll just use a random port if not already set.
// todo(electron-5): remove me
if (!args.some(arg => arg.startsWith('remote-debugging-port'))) {
const randomPort = Math.floor(Math.random() * (9999 - 9000) + 9000)
args.push(`remote-debugging-port=${randomPort}`)
}

var isWin = process.platform === 'win32'
var launcherPath = path.join(__dirname, isWin ? 'launcher.bat' : 'launcher.js')

Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spectron",
"version": "6.0.0",
"version": "7.0.0",
"description": "Easily test your Electron apps using ChromeDriver and WebdriverIO.",
"main": "index.js",
"types": "./lib/spectron.d.ts",
Expand All @@ -25,7 +25,7 @@
"license": "MIT",
"dependencies": {
"dev-null": "^0.1.1",
"electron-chromedriver": "~4.0.0",
"electron-chromedriver": "^5.0.1",
"request": "^2.87.0",
"split": "^1.0.0",
"webdriverio": "^4.13.0"
Expand All @@ -36,7 +36,7 @@
"chai-as-promised": "^7.1.1",
"chai-roughly": "^1.0.0",
"check-for-leaks": "^1.0.2",
"electron": "^4.2.2",
"electron": "^5.0.1",
"husky": "^0.14.3",
"mocha": "^5.2.0",
"standard": "^12.0.1",
Expand Down
2 changes: 1 addition & 1 deletion test/application-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('application loading', function () {
it('gets the render process console logs and clears them', function () {
return app.client.waitUntilWindowLoaded()
.getRenderProcessLogs().then(function (logs) {
expect(logs.length).to.equal(4)
expect(logs.length).to.equal(3)

expect(logs[0].message).to.contain('6:14 "render log"')
expect(logs[0].source).to.equal('console-api')
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/accessible/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ app.on('ready', function () {
mainWindow = new BrowserWindow({
center: true,
width: 800,
height: 600
height: 600,
webPreferences: {
nodeIntegration: true
}
})
mainWindow.loadFile('index.html')
mainWindow.on('closed', function () { mainWindow = null })
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ app.on('ready', function () {
x: 25,
y: 35,
width: 200,
height: 100
height: 100,
webPreferences: {
nodeIntegration: true
}
})
mainWindow.loadFile('index.html')
mainWindow.on('closed', function () { mainWindow = null })
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/example/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ app.on('ready', function () {
width: 800,
height: 400,
minHeight: 100,
minWidth: 100
minWidth: 100,
webPreferences: {
nodeIntegration: true
}
})
mainWindow.loadFile('index.html')
mainWindow.on('closed', function () { mainWindow = null })
Expand Down
10 changes: 8 additions & 2 deletions test/fixtures/multi-window/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ app.on('ready', function () {
x: 25,
y: 35,
width: 200,
height: 100
height: 100,
webPreferences: {
nodeIntegration: true
}
})
topWindow.loadFile('index-top.html')
topWindow.on('closed', function () { topWindow = null })
Expand All @@ -17,7 +20,10 @@ app.on('ready', function () {
x: 25,
y: 135,
width: 300,
height: 50
height: 50,
webPreferences: {
nodeIntegration: true
}
})
bottomWindow.loadFile('index-bottom.html')
bottomWindow.on('closed', function () { bottomWindow = null })
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/not-accessible/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ app.on('ready', function () {
mainWindow = new BrowserWindow({
center: true,
width: 800,
height: 600
height: 600,
webPreferences: {
nodeIntegration: true,
webviewTag: true
}
})
mainWindow.loadFile('index.html')
mainWindow.on('closed', function () { mainWindow = null })
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/slow/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ app.on('ready', function () {
x: 25,
y: 35,
width: 200,
height: 100
height: 100,
webPreferences: {
nodeIntegration: true
}
})
mainWindow.loadFile('index.html')
mainWindow.on('closed', function () { mainWindow = null })
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/web-view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
</script>
</head>
<body>
<webview src="web-view.html" autosize="on" minwidth="500" minheight="500"></webview>
<webview src="web-view.html" autosize="on" minwidth="500" minheight="500" nodeintegration></webview>
</body>
</html>
6 changes: 5 additions & 1 deletion test/fixtures/web-view/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ app.on('ready', function () {
width: 800,
height: 400,
minHeight: 100,
minWidth: 100
minWidth: 100,
webPreferences: {
nodeIntegration: true,
webviewTag: true
}
})
mainWindow.loadFile('index.html')
mainWindow.on('closed', function () { mainWindow = null })
Expand Down

0 comments on commit 74f87c1

Please sign in to comment.