forked from nodejs/node-addon-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_all.js
49 lines (46 loc) · 1.25 KB
/
test_all.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
const fs = require('fs')
const path = require('path')
const { execSync } = require('child_process')
const chalk = require('chalk')
const semver = require('semver')
const excludeFolder = ['node_modules']
function getAllTests() {
return fs
.readdirSync('./')
.filter(i => {
return (
!i.startsWith('.') &&
fs.statSync(i).isDirectory() &&
!excludeFolder.includes(i)
)
})
.map(i => {
const p = path.join(__dirname, i)
const tests = fs
.readdirSync(p)
.filter(j => fs.statSync(path.join(p, j)).isDirectory())
.map(j => path.join(p, j))
return tests
})
}
getAllTests().map(tests => {
tests.map(i => {
console.log(chalk.green(`testing: ${i}`))
const p = require(path.join(i, 'package.json'))
if (p.engines && p.engines.node) {
const currentNodeVersion = process.versions.node
const range = p.engines.node
const engineOk = semver.satisfies(currentNodeVersion, range)
if (!engineOk) {
console.warn(
chalk.yellow(`${i} require Node.js ${range}, current is ${currentNodeVersion}, skipping`)
)
return
}
}
const stdout = execSync('npm install', {
cwd: i
})
console.log(stdout.toString())
})
})