Skip to content

Commit c42f663

Browse files
committed
fix: Ensure, that chromedriver processes terminate
* If the tests fail and grunt aborts. * If the process is terminated. * If the process is interrrupted.
1 parent ba5b353 commit c42f663

File tree

3 files changed

+57
-38
lines changed

3 files changed

+57
-38
lines changed

package-lock.json

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

package.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,19 @@
3232
"coveralls": "test `node --version | cut -c 2` -eq 8 && npm run coverage && grunt coveralls"
3333
},
3434
"dependencies": {
35-
"mkdirp": "^0.5.1",
36-
"node-cleanup": "^2.1.2",
37-
"pad-left": "^2.1.0",
38-
"webdriverio": "^4.14.1"
35+
"mkdirp": "0.5.1",
36+
"pad-left": "2.1.0",
37+
"webdriverio": "4.14.1"
3938
},
4039
"devDependencies": {
4140
"grunt": "1.0.4",
42-
"grunt-contrib-clean": "^2.0.0",
43-
"grunt-contrib-connect": "^2.0.0",
44-
"grunt-contrib-nodeunit": "^2.0.0",
45-
"grunt-coveralls": "^2.0.0",
46-
"grunt-istanbul": "^0.8.0",
47-
"grunt-selenium-standalone": "^1.0.1",
48-
"grunt-standard": "^3.1.0"
41+
"grunt-contrib-clean": "2.0.0",
42+
"grunt-contrib-connect": "2.0.0",
43+
"grunt-contrib-nodeunit": "2.0.0",
44+
"grunt-coveralls": "2.0.0",
45+
"grunt-istanbul": "0.8.0",
46+
"grunt-selenium-standalone": "1.0.1",
47+
"grunt-standard": "3.1.0"
4948
},
5049
"peerDependencies": {
5150
"grunt": ">=1.0.4"

tasks/html-dom-snapshot.js

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const {writeFile} = require('fs')
1313
const pad = require('pad-left')
1414
const {basename, dirname, isAbsolute, join} = require('path')
1515
const mkdirp = require('mkdirp')
16-
const nodeCleanup = require('node-cleanup')
1716
const instructions = [
1817
'setViewport', 'url', 'go', 'scroll', 'clearValue', 'setValue', 'addValue',
1918
'selectOptionByIndex', 'selectOptionByValue', 'moveCursor',
@@ -69,6 +68,7 @@ module.exports = grunt => {
6968
let urlCount = 0
7069
let snapshotCount = 0
7170
let screenshotCount = 0
71+
let failed
7272
let commands
7373
if (browserCapabilities) {
7474
grunt.log.warn('The property "browserCapabilities" is deprecated. ' +
@@ -93,7 +93,6 @@ module.exports = grunt => {
9393
target + '".')
9494
let client = webdriverio.remote(webdriver)
9595
client.init()
96-
.then(() => nodeCleanup(stop))
9796
.then(setViewportSize)
9897
.then(gatherCommands)
9998
.then(performConditionalCommands)
@@ -107,25 +106,51 @@ module.exports = grunt => {
107106
' and ' + screenshotCount + ' ' +
108107
grunt.util.pluralize(screenshotCount, 'screenshot/screenshots') +
109108
' written.')
110-
return stop()
109+
return stop(false)
111110
})
112111
.catch(error => {
112+
failed = true
113113
grunt.verbose.error(error.stack)
114114
grunt.log.error(error)
115-
const warn = options.force ? grunt.log.warn : grunt.fail.warn
116-
warn('Taking snapshots failed.')
117-
return stop()
115+
return stop(false)
118116
})
119-
.then(done)
117+
.then(() => {
118+
if (failed) {
119+
const warn = options.force ? grunt.log.warn : grunt.fail.warn
120+
warn('Taking snapshots failed.')
121+
}
122+
})
123+
.then(() => {
124+
if (!failed) {
125+
done()
126+
}
127+
})
128+
129+
process
130+
.on('SIGINT', stop.bind(null, true))
131+
.on('SIGTERM', stop.bind(null, true))
120132

121-
function stop () {
133+
function stop (exit) {
134+
function exitProcess () {
135+
if (exit) {
136+
grunt.log.writeln('Stopping the process...')
137+
process.exit(1)
138+
}
139+
}
122140
if (client) {
123-
const backup = client
141+
const oldClient = client
124142
client = null
125-
return backup.end()
143+
grunt.log.writeln('Closing the browser in one second...')
144+
const result = oldClient
145+
.end()
126146
// Workaround for hanging chromedriver; for more information
127147
// see https://github.com/vvo/selenium-standalone/issues/351
128-
.pause(100)
148+
.pause(1000)
149+
// The promise returned from pause() appears to never resolve.
150+
setTimeout(exitProcess, 1500)
151+
return result
152+
} else {
153+
exitProcess()
129154
}
130155
}
131156

0 commit comments

Comments
 (0)