Skip to content

Commit 74f87c1

Browse files
alexstratcodebytere
authored andcommitted
feat: upgrade for Electron v5 support (electron-userland#364)
1 parent a64c809 commit 74f87c1

File tree

13 files changed

+54
-41
lines changed

13 files changed

+54
-41
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ For given versions of Electron you must depend on a very specific version range
3232
| `^2.0.0` | `^4.0.0` |
3333
| `^3.0.0` | `^5.0.0` |
3434
| `^4.0.0` | `^6.0.0` |
35+
| `^5.0.0` | `^7.0.0` |
3536

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

@@ -183,8 +184,8 @@ Create a new application with the following options:
183184
### Node Integration
184185

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

190191
You can do this by adding a [`preload`][preload] script that does the following:

lib/application.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,6 @@ Application.prototype.createClient = function () {
153153
args.push(arg)
154154
})
155155

156-
// Since ChromeDriver v2.41, ChromeDriver will only connect
157-
// if, either we precise a port for remote debugging, either
158-
// the embedder (ie electron) made sure to pass `USER_DATA_DIR`
159-
// to the remote debugging server.
160-
// https://bitbucket.org/chromiumembedded/cef/issues/2476/cef-webdriver-instructions-will-need-to
161-
// `USER_DATA_DIR` is properly passed to the remote debugging server
162-
// since electron 5 (see electron/electron#17800)
163-
// So, for now, we'll just use a random port if not already set.
164-
// todo(electron-5): remove me
165-
if (!args.some(arg => arg.startsWith('remote-debugging-port'))) {
166-
const randomPort = Math.floor(Math.random() * (9999 - 9000) + 9000)
167-
args.push(`remote-debugging-port=${randomPort}`)
168-
}
169-
170156
var isWin = process.platform === 'win32'
171157
var launcherPath = path.join(__dirname, isWin ? 'launcher.bat' : 'launcher.js')
172158

package-lock.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spectron",
3-
"version": "6.0.0",
3+
"version": "7.0.0",
44
"description": "Easily test your Electron apps using ChromeDriver and WebdriverIO.",
55
"main": "index.js",
66
"types": "./lib/spectron.d.ts",
@@ -25,7 +25,7 @@
2525
"license": "MIT",
2626
"dependencies": {
2727
"dev-null": "^0.1.1",
28-
"electron-chromedriver": "~4.0.0",
28+
"electron-chromedriver": "^5.0.1",
2929
"request": "^2.87.0",
3030
"split": "^1.0.0",
3131
"webdriverio": "^4.13.0"
@@ -36,7 +36,7 @@
3636
"chai-as-promised": "^7.1.1",
3737
"chai-roughly": "^1.0.0",
3838
"check-for-leaks": "^1.0.2",
39-
"electron": "^4.2.2",
39+
"electron": "^5.0.1",
4040
"husky": "^0.14.3",
4141
"mocha": "^5.2.0",
4242
"standard": "^12.0.1",

test/application-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe('application loading', function () {
137137
it('gets the render process console logs and clears them', function () {
138138
return app.client.waitUntilWindowLoaded()
139139
.getRenderProcessLogs().then(function (logs) {
140-
expect(logs.length).to.equal(4)
140+
expect(logs.length).to.equal(3)
141141

142142
expect(logs[0].message).to.contain('6:14 "render log"')
143143
expect(logs[0].source).to.equal('console-api')

test/fixtures/accessible/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ app.on('ready', function () {
66
mainWindow = new BrowserWindow({
77
center: true,
88
width: 800,
9-
height: 600
9+
height: 600,
10+
webPreferences: {
11+
nodeIntegration: true
12+
}
1013
})
1114
mainWindow.loadFile('index.html')
1215
mainWindow.on('closed', function () { mainWindow = null })

test/fixtures/app/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ app.on('ready', function () {
1616
x: 25,
1717
y: 35,
1818
width: 200,
19-
height: 100
19+
height: 100,
20+
webPreferences: {
21+
nodeIntegration: true
22+
}
2023
})
2124
mainWindow.loadFile('index.html')
2225
mainWindow.on('closed', function () { mainWindow = null })

test/fixtures/example/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ app.on('ready', function () {
88
width: 800,
99
height: 400,
1010
minHeight: 100,
11-
minWidth: 100
11+
minWidth: 100,
12+
webPreferences: {
13+
nodeIntegration: true
14+
}
1215
})
1316
mainWindow.loadFile('index.html')
1417
mainWindow.on('closed', function () { mainWindow = null })

test/fixtures/multi-window/main.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ app.on('ready', function () {
88
x: 25,
99
y: 35,
1010
width: 200,
11-
height: 100
11+
height: 100,
12+
webPreferences: {
13+
nodeIntegration: true
14+
}
1215
})
1316
topWindow.loadFile('index-top.html')
1417
topWindow.on('closed', function () { topWindow = null })
@@ -17,7 +20,10 @@ app.on('ready', function () {
1720
x: 25,
1821
y: 135,
1922
width: 300,
20-
height: 50
23+
height: 50,
24+
webPreferences: {
25+
nodeIntegration: true
26+
}
2127
})
2228
bottomWindow.loadFile('index-bottom.html')
2329
bottomWindow.on('closed', function () { bottomWindow = null })

test/fixtures/not-accessible/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ app.on('ready', function () {
66
mainWindow = new BrowserWindow({
77
center: true,
88
width: 800,
9-
height: 600
9+
height: 600,
10+
webPreferences: {
11+
nodeIntegration: true,
12+
webviewTag: true
13+
}
1014
})
1115
mainWindow.loadFile('index.html')
1216
mainWindow.on('closed', function () { mainWindow = null })

0 commit comments

Comments
 (0)