-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
58 lines (51 loc) · 1.83 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const debug = require('debug')('compatibility:test')
const fs = require('fs')
const path = require('path')
const spawn = require('child_process').spawn
debug.enabled = true
module.exports = function (dir, _modules, cb) {
const fullPath = path.join(dir, 'package.json')
debug('getting dependencies from %s', fullPath)
const parentPackage = JSON.parse(fs.readFileSync(fullPath))
// get dependencies from ssb-server
var modules = parentPackage.compatibility
if(!modules.length)
throw new Error('compatibility: please specify an array of dependencies to be tested in package.json')
const root_module = parentPackage.name
try {
fs.symlinkSync(dir, path.join(dir, 'node_modules', root_module))
} catch(_) { }
function test(name, cb) {
debug('testing dependency for compatibilty:'+name)
var mod_dir = path.join(dir, 'node_modules', name)
const childPackage = JSON.parse(fs.readFileSync(path.join(mod_dir, 'package.json')))
if(!childPackage.scripts.test)
throw new Error('compatibility: module to be tested is missing tests:'+name)
debug('running test script: ' + childPackage.scripts.test)
var cp = spawn('bash', ['-c', childPackage.scripts.test], {
stdio: ['inherit', 'inherit', 'inherit'],
cwd: mod_dir
})
cp.on('exit', cb)
}
if(_modules.length) {
_modules.forEach(function (m) {
if(!~modules.indexOf(m))
throw new Error('compatibility: requested test run of module:'+m+' but it was not in compatibiltiy testing list')
})
modules = _modules
}
;(function next(i) {
if(i >= modules.length)
return debug('all tests passed')
test(modules[i], function (code) {
if(code) {
debug('tests for '+modules[i]+' failed with:'+code)
// process.exit(code)
cb(code)
}
else
next(++i)
})
})(0)
}