Skip to content

Commit d41256b

Browse files
committed
fix(test): trying to handle errors better
1 parent 40add0b commit d41256b

File tree

7 files changed

+41
-17
lines changed

7 files changed

+41
-17
lines changed

src/exec-test.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ var spawn = require('child_process').spawn
44
var q = require('q')
55
var npmPath = require('./npm-test').npmPath
66
var _ = require('lodash')
7+
const debug = require('debug')('next-update')
78

89
// returns a promise
10+
// TODO switch to execa
911
function test (options, testCommand) {
1012
options = options || {}
1113
var log = options.tldr ? _.noop : console.log.bind(console)
14+
debug('exec-test "%s"', testCommand)
1215

1316
verify.unemptyString(testCommand, 'missing test command string')
1417
log(' ', testCommand)
@@ -40,21 +43,21 @@ function test (options, testCommand) {
4043
console.error('test command: "' + testCommand + '"')
4144
console.error(err)
4245
testErrors += err.toString()
43-
deferred.reject({
44-
code: err.code,
45-
errors: testErrors
46-
})
46+
const e = new Error('test command failed')
47+
e.code = err.code
48+
e.errors = testErrors
49+
deferred.reject(e)
4750
})
4851

4952
testProcess.on('exit', function (code) {
5053
if (code) {
5154
console.error('testProcess test returned', code)
5255
console.error('test errors:\n' + testErrors)
5356
console.error(testOutput)
54-
deferred.reject({
55-
code: code,
56-
errors: testErrors
57-
})
57+
const e = new Error('test exit code means error')
58+
e.code = code
59+
e.errors = testErrors
60+
return deferred.reject(e)
5861
}
5962
deferred.resolve()
6063
})

src/next-update.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function checkCurrentInstall (options) {
6868
return cleanDependencies()
6969
.then(checkDependenciesInstalled)
7070
.then(function () {
71+
log('running test command')
7172
return runTest(options, options.testCommand)()
7273
})
7374
.then(function () {

src/npm-test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ function test (options) {
6161
var deferred = q.defer()
6262
npm.on('exit', function (code) {
6363
if (code) {
64-
errorLog('npm test returned', code)
64+
errorLog('npm test returned', code, '\n')
6565
errorLog('test output:\n' + testOutput)
6666
errorLog('test errors:\n' + testErrors)
6767

68-
deferred.reject({
69-
code: code,
70-
errors: testErrors
71-
})
68+
const e = new Error('npm test exit code means error')
69+
e.code = code
70+
e.errors = testErrors
71+
72+
deferred.reject(e)
7273
}
7374
deferred.resolve()
7475
})

src/test-module-version.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ function testModuleVersions (options, results) {
174174
})
175175
var checkAllPromise = checkPromises.reduce(q.when, q())
176176
if (options.keep) {
177+
debug('keep working updates for %s', name)
177178
checkAllPromise = checkAllPromise.then(function (result) {
178179
verify.array(result, 'expected array of results', result)
179180
var lastSuccess = _.last(_.filter(result, { works: true }))
@@ -194,10 +195,16 @@ function testModuleVersions (options, results) {
194195
})
195196
} else {
196197
checkAllPromise = checkAllPromise
197-
.then(restoreVersionFunc)
198+
.then(restoreVersionFunc, (err) => {
199+
console.error('Could not check all versions')
200+
console.error(err)
201+
throw err
202+
})
198203
}
199204
checkAllPromise
200205
.then(function (result) {
206+
debug('got result')
207+
debug(result)
201208
check.verify.array(result, 'could not get result array')
202209
results.push(result)
203210
deferred.resolve(results)
@@ -290,13 +297,15 @@ function testModuleVersion (options, results) {
290297
}, function (error) {
291298
reportFailure(nameVersion + ' tests failed :(', options.color)
292299

300+
debug('sending stats results')
293301
stats.sendUpdateResult({
294302
name: options.name,
295303
from: options.currentVersion,
296304
to: options.version,
297305
success: false
298306
})
299307

308+
debug('checking error code', error.code)
300309
verify.number(error.code, 'expected code in error ' +
301310
JSON.stringify(error, null, 2))
302311

@@ -324,6 +333,8 @@ function testPromise (options, command) {
324333
if (command) {
325334
verify.unemptyString(command, 'expected string command, not ' + command)
326335
testFunction = execTest.bind(null, options, command)
336+
} else {
337+
debug('missing test command')
327338
}
328339
return testFunction
329340
}

src/utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ function getTestCommand (packageFilename, moduleName) {
4040
return config.commands[moduleName]
4141
}
4242

43+
const stringify = (x) => JSON.stringify(x, null, 2)
44+
45+
const errorObject = (x) => (new Error(stringify(x)))
46+
4347
module.exports = {
4448
name,
4549
getConfig,
4650
getSkippedModules,
47-
getTestCommand
51+
getTestCommand,
52+
stringify,
53+
errorObject
4854
}

test/as-parent-spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ describe('testing check-types', () => {
3939
this.timeout(TWO_MINUTES)
4040
const opts = {
4141
module: 'check-types',
42-
latest: true
42+
latest: true,
43+
keep: false
4344
}
4445
const removeVersions = (results) => results.map(r => {
4546
la(is.semver(r.version), 'expected version', r)
@@ -64,6 +65,7 @@ describe('testing check-types', () => {
6465

6566
const opts = {
6667
module: 'check-types',
68+
keep: false,
6769
limit
6870
}
6971
return snapShot(nextUpdate(opts))

test/test-next-updater/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",
1919
"license": "MIT",
2020
"dependencies": {
21-
"check-types": "7.0.1"
21+
"check-types": "0.6.5"
2222
}
2323
}

0 commit comments

Comments
 (0)