Skip to content

Commit

Permalink
chore: add ci support node 16 (#292)
Browse files Browse the repository at this point in the history
* chore: bump tap version

* chore: add v16 to test matrix

* chore: update coverage settings to latest tap version

* chore: use taprc

* chore: support v17

* chore: updade coverage settings
  • Loading branch information
RafaelGSS authored Oct 28, 2021
1 parent 0021a70 commit 87e8a21
Show file tree
Hide file tree
Showing 42 changed files with 218 additions and 208 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: [12.13.0, 12.x, 14.x, 15.x]
node-version: [12.13.0, 12.x, 14.x, 16.x, 17.x]

runs-on: ${{matrix.os}}
steps:
Expand Down
5 changes: 5 additions & 0 deletions .taprc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
timeout: 0
functions: 95
branches: 95
statements: 95
jobs: 1
5 changes: 5 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ async function runTool (toolName, Tool, version, args, uiOptions) {
})

tool.on('analysing', function (message = 'Analysing data') {
/* istanbul ignore if: isEnabled is always false when spawn process. See: https://github.com/sindresorhus/ora#isenabled */
if (spinner.isEnabled) {
spinner.text = message
if (!spinner.isSpinning) {
Expand All @@ -351,13 +352,15 @@ async function runTool (toolName, Tool, version, args, uiOptions) {
tool.on('status', status)

function status (message) {
/* istanbul ignore next: isEnabled is always false when spawn process. See: https://github.com/sindresorhus/ora#isenabled */
if (spinner.isEnabled) {
spinner.text = message
} else {
console.log(message)
}
}

/* istanbul ignore next: SIGINT by spawned process is tricky */
function onsigint () {
status('Received Ctrl+C, closing process...')
if (!spinner.isSpinning) spinner.start()
Expand All @@ -372,6 +375,7 @@ async function runTool (toolName, Tool, version, args, uiOptions) {
process.once('SIGINT', onsigint)
tool.collect(args['--'], function (err, filename) {
if (err) return defer.reject(err)
/* istanbul ignore if: isEnabled is always false when spawn process. See: https://github.com/sindresorhus/ora#isenabled */
if (spinner.isEnabled) {
spinner.stop()
spinner.stream.write(`${spinner.text}\n`)
Expand All @@ -393,6 +397,7 @@ async function runTool (toolName, Tool, version, args, uiOptions) {

viz(toolName, filename, function (err) {
if (err) return defer.reject(err)
/* istanbul ignore if: isEnabled is always false when spawn process. See: https://github.com/sindresorhus/ora#isenabled */
if (spinner.isEnabled) {
spinner.stop()
spinner.stream.write(`${spinner.text}\n`)
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"clinic": "bin.js"
},
"scripts": {
"test": "standard | snazzy && tap -j1 --timeout 0 --no-cov test/*.test.js",
"test-local": "standard | snazzy && tap -j1 --timeout 0 --no-cov test/*.test.js test-local/*.test.js",
"test": "standard | snazzy && tap --no-cov test/*.test.js",
"test-local": "standard | snazzy && tap --no-cov test/*.test.js test-local/*.test.js",
"ci-lint": "standard | snazzy",
"ci-test-no-cov": "tap -j1 --timeout 0 --no-cov test/*.test.js",
"ci-test-cov": "tap -j1 --timeout 0 test/*.test.js",
"ci-test-no-cov": "tap --no-cov test/*.test.js",
"ci-test-cov": "tap test/*.test.js",
"lint": "standard --fix | snazzy"
},
"dependencies": {
Expand Down Expand Up @@ -43,7 +43,7 @@
"proxyquire": "^2.1.0",
"snazzy": "^9.0.0",
"standard": "^16.0.3",
"tap": "^14.11.0",
"tap": "^15.0.10",
"tar-stream": "^2.1.4"
},
"keywords": [
Expand Down
10 changes: 5 additions & 5 deletions test-local/cli-doctor-collect-only.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ test('clinic doctor --collect-only --dest \'./foo\' - no issues', function (t) {
'clinic', 'doctor', '--collect-only', '--dest', './foo',
'--', 'node', '-e', 'setTimeout(() => {}, 100)'
], function (err, stdout, stderr, tempdir) {
t.ifError(err)
t.error(err)
const dirname = stdout.match(/(\d+\.clinic.doctor)/)[1]
fs.access(path.resolve(tempdir, 'foo', dirname), function (err) {
t.ifError(err)
t.error(err)
fs.access(path.resolve(tempdir, 'foo', dirname + '.html'), function (err) {
t.strictEqual(err.code, 'ENOENT')
t.equal(err.code, 'ENOENT')
t.end()
})
})
Expand All @@ -27,8 +27,8 @@ test('clinic doctor --collect-only - bad status code', function (t) {
'clinic', 'doctor', '--collect-only', '--dest', './foo',
'--', 'node', '-e', 'process.exit(1)'
], function (err, stdout, stderr, tempdir) {
t.strictDeepEqual(err, new Error('process exited with exit code 1'))
t.strictEqual(stdout, 'To stop data collection press: Ctrl + C\n')
t.strictSame(err, new Error('process exited with exit code 1'))
t.equal(stdout, 'To stop data collection press: Ctrl + C\n')
t.ok(stderr.includes('process exited with exit code 1'))
t.end()
})
Expand Down
10 changes: 5 additions & 5 deletions test-local/cli-flame-collect-only.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ test('clinic flame --collect-only - no issues', function (t) {
'clinic', 'flame', '--collect-only',
'--', 'node', '-e', 'setTimeout(() => {}, 300)'
], function (err, stdout, stderr, tempdir) {
t.ifError(err)
t.error(err)
const dirname = stdout.match(/(\d+\.clinic-flame)/)[1]
fs.access(path.resolve(tempdir, dirname), function (err) {
t.ifError(err)
t.error(err)
fs.access(path.resolve(tempdir, dirname + '.html'), function (err) {
t.strictEqual(err.code, 'ENOENT')
t.equal(err.code, 'ENOENT')
t.end()
})
})
Expand All @@ -27,8 +27,8 @@ test('clinic flame --collect-only - bad status code', function (t) {
'clinic', 'flame', '--collect-only',
'--', 'node', '-e', 'process.exit(1)'
], function (err, stdout, stderr) {
t.strictDeepEqual(err, new Error('process exited with exit code 1'))
t.strictEqual(stdout, 'To stop data collection press: Ctrl + C\n')
t.strictSame(err, new Error('process exited with exit code 1'))
t.equal(stdout, 'To stop data collection press: Ctrl + C\n')
t.ok(stderr.includes('subprocess error, code: 1'))
t.end()
})
Expand Down
8 changes: 4 additions & 4 deletions test-local/cli-flame-full.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('clinic flame -- node - no issues', function (t) {
'clinic', 'flame', '--no-open',
'--', 'node', '-e', 'setTimeout(() => {}, 300)'
], function (err, stdout, stderr, tempdir) {
t.ifError(err)
t.error(err)

const htmlFilename = stdout.match(/(\d+\.clinic-flame\.html)/)[1]
const dirname = path.dirname(htmlFilename)
Expand All @@ -26,7 +26,7 @@ test('clinic flame -- node - no issues', function (t) {
fs.access(path.resolve(tempdir, htmlFilename), done)
}
}, function (err) {
t.ifError(err)
t.error(err)
t.end()
})
})
Expand All @@ -38,8 +38,8 @@ test('clinic flame -- node - bad status code', function (t) {
'clinic', 'flame', '--no-open',
'--', 'node', '-e', 'process.exit(1)'
], function (err, stdout, stderr) {
t.strictDeepEqual(err, new Error('process exited with exit code 1'))
t.strictEqual(stdout, 'To generate the report press: Ctrl + C\n')
t.strictSame(err, new Error('process exited with exit code 1'))
t.equal(stdout, 'To generate the report press: Ctrl + C\n')
t.ok(stderr.includes('subprocess error, code: 1'))
t.end()
})
Expand Down
12 changes: 6 additions & 6 deletions test-local/cli-flame-passthrough-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('clinic flame --name', function (t) {
'clinic', 'flame', '--no-open', '--name', 'custom-name',
'--', 'node', '-e', 'setTimeout(() => {}, 300)'
], function (err, stdout, stderr, tempdir) {
t.ifError(err)
t.error(err)

const htmlFilename = stdout.match(/(\d+\.custom-name)/)[1]
const dirname = path.dirname(htmlFilename)
Expand All @@ -26,7 +26,7 @@ test('clinic flame --name', function (t) {
fs.access(path.resolve(tempdir, htmlFilename), done)
}
}, function (err) {
t.ifError(err)
t.error(err)
t.end()
})
})
Expand All @@ -38,7 +38,7 @@ test('clinic flame --output-html', function (t) {
'clinic', 'flame', '--no-open', '--output-html', '{name}-{pid}-{timestamp}.html',
'--', 'node', '-e', 'setTimeout(() => {}, 300)'
], function (err, stdout, stderr, tempdir) {
t.ifError(err)
t.error(err)
const match = stderr.match(/\/(clinic-flame-)(\d+)(-)(\d+)(\.html)/)
const htmlFilename = match.slice(1).join('')
const pid = match[2]
Expand All @@ -53,7 +53,7 @@ test('clinic flame --output-html', function (t) {
fs.access(path.resolve(tempdir, htmlFilename), done)
}
}, function (err) {
t.ifError(err)
t.error(err)
t.end()
})
})
Expand All @@ -65,7 +65,7 @@ test('clinic flame --output-dir', function (t) {
'clinic', 'flame', '--no-open', '--output-dir', '{name}-{pid}',
'--', 'node', '-e', 'setTimeout(() => {}, 300)'
], function (err, stdout, stderr, tempdir) {
t.ifError(err)
t.error(err)
const match = stderr.match(/\/(\d+)(\.)(clinic-flame)(\.html)/)
const htmlFilename = match.slice(1).join('')
const pid = match[1]
Expand All @@ -79,7 +79,7 @@ test('clinic flame --output-dir', function (t) {
fs.access(path.resolve(tempdir, htmlFilename), done)
}
}, function (err) {
t.ifError(err)
t.error(err)
t.end()
})
})
Expand Down
10 changes: 5 additions & 5 deletions test-local/cli-flame-visualize-only.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ test('clinic flame --visualize-only - no issues', function (t) {
'clinic', 'flame', '--collect-only',
'--', 'node', '-e', 'setTimeout(() => {}, 300)'
], function (err, stdout, stderr, tempdir) {
t.ifError(err)
t.error(err)
const dirname = stdout.match(/(\d+\.clinic-flame)/)[1]
const dirpath = path.resolve(tempdir, dirname)

// visualize data
cli({ relayStderr: false }, [
'clinic', 'flame', '--visualize-only', dirpath
], function (err, stdout) {
t.ifError(err)
t.error(err)
const htmlFilename = stdout.match(/(\d+\.clinic-flame)/)[1]

// check that HTML file exists
fs.access(path.resolve(tempdir, htmlFilename), function (err) {
t.ifError(err)
t.error(err)
t.end()
})
})
Expand All @@ -35,8 +35,8 @@ test('clinic flame --collect-only - missing data', function (t) {
cli({ relayStderr: false }, [
'clinic', 'flame', '--visualize-only', 'missing.flamegraph'
], function (err, stdout, stderr) {
t.strictDeepEqual(err, new Error('process exited with exit code 1'))
t.strictEqual(stdout, '')
t.strictSame(err, new Error('process exited with exit code 1'))
t.equal(stdout, '')
t.match(stderr, /Unknown argument "missing\.flamegraph"\. Pattern: {pid}\.clinic-{command}/)
t.end()
})
Expand Down
14 changes: 7 additions & 7 deletions test/cli-autocannon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ test('clinic --autocannon with $PORT', function (t) {
http.createServer((req, res) => res.end('ok')).listen(0)
`
], function (err, stdout, stderr) {
t.ifError(err)
t.error(err)
t.ok(stderr.indexOf('Running 1s test @ http://localhost:') > -1)
t.strictEqual(stdout.split('\n')[0], 'Analysing data')
t.equal(stdout.split('\n')[0], 'Analysing data')
t.end()
})
})
Expand All @@ -36,10 +36,10 @@ test('clinic --autocannon with escaped $', function (t) {
}).listen(0)
`
], function (err, stdout, stderr) {
t.ifError(err)
t.error(err)
t.ok(stderr.indexOf('Running 1s test @ http://localhost:') > -1)
t.strictEqual(stdout.split('\n')[0], '/$PORT?$page=10')
t.strictEqual(stdout.split('\n')[1], 'Analysing data')
t.equal(stdout.split('\n')[0], '/$PORT?$page=10')
t.equal(stdout.split('\n')[1], 'Analysing data')
t.end()
})
})
Expand All @@ -54,9 +54,9 @@ test('clinic --autocannon with /path', function (t) {
http.createServer((req, res) => res.end(req.url)).listen(0)
`
], function (err, stdout, stderr) {
t.ifError(err)
t.error(err)
t.ok(stderr.indexOf('Running 1s test @ http://localhost:') > -1)
t.strictEqual(stdout.split('\n')[0], 'Analysing data')
t.equal(stdout.split('\n')[0], 'Analysing data')
t.end()
})
})
12 changes: 6 additions & 6 deletions test/cli-bubbleprof-collect-only.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ test('clinic bubbleprof --collect-only - no issues', function (t) {
'clinic', 'bubbleprof', '--collect-only', '--debug',
'--', 'node', '-e', 'setTimeout(() => {}, 100)'
], function (err, stdout, stderr, tempdir) {
t.ifError(err)
t.error(err)
t.ok(/Output file is \.clinic[/\\](\d+).clinic-bubbleprof/.test(stdout))

const dirname = stdout.match(/(\.clinic[/\\]\d+.clinic-bubbleprof)/)[1]
fs.access(path.resolve(tempdir, dirname), function (err) {
t.ifError(err)
t.error(err)

fs.access(path.resolve(tempdir, dirname + '.html'), function (err) {
t.strictEqual(err.code, 'ENOENT')
t.equal(err.code, 'ENOENT')
t.end()
})
})
Expand All @@ -30,15 +30,15 @@ test('clinic bubbleprof --collect-only - bad status code', function (t) {
'clinic', 'bubbleprof', '--collect-only',
'--', 'node', '-e', 'process.exit(1)'
], function (err, stdout, stderr, tempdir) {
t.ifError(err)
t.error(err)
t.ok(/Output file is \.clinic[/\\](\d+).clinic-bubbleprof/.test(stdout))

const dirname = stdout.match(/(\.clinic[/\\]\d+.clinic-bubbleprof)/)[1]
fs.access(path.resolve(tempdir, dirname), function (err) {
t.ifError(err)
t.error(err)

fs.access(path.resolve(tempdir, dirname + '.html'), function (err) {
t.strictEqual(err.code, 'ENOENT')
t.equal(err.code, 'ENOENT')
t.end()
})
})
Expand Down
22 changes: 11 additions & 11 deletions test/cli-bubbleprof-full.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ test('clinic bubbleprof -- node - no issues', function (t) {
'clinic', 'bubbleprof', '--no-open',
'--', 'node', '-e', 'setTimeout(() => {}, 100)'
], function (err, stdout, stderr, tempdir) {
t.ifError(err)
t.error(err)
const dirname = stdout.match(/(\.clinic[/\\]\d+.clinic-bubbleprof)/)[1]
const fullpath = url.pathToFileURL(fs.realpathSync(path.resolve(tempdir, dirname)))

t.strictEqual(stdout.split('\n')[1], 'Analysing data')
t.strictEqual(stdout.split('\n')[2], `Generated HTML file is ${fullpath}.html`)
t.equal(stdout.split('\n')[1], 'Analysing data')
t.equal(stdout.split('\n')[2], `Generated HTML file is ${fullpath}.html`)

// check that files exists
async.parallel({
Expand All @@ -29,7 +29,7 @@ test('clinic bubbleprof -- node - no issues', function (t) {
fs.access(path.resolve(tempdir, dirname + '.html'), done)
}
}, function (err) {
t.ifError(err)
t.error(err)
t.end()
})
})
Expand All @@ -41,12 +41,12 @@ test('clinic bubbleprof -- node - bad status code', function (t) {
'clinic', 'bubbleprof', '--no-open',
'--', 'node', '-e', 'process.exit(1)'
], function (err, stdout, stderr, tempdir) {
t.ifError(err)
t.error(err)
const dirname = stdout.match(/(\.clinic[/\\]\d+.clinic-bubbleprof)/)[1]
const fullpath = url.pathToFileURL(fs.realpathSync(path.resolve(tempdir, dirname)))

t.strictEqual(stdout.split('\n')[1], 'Analysing data')
t.strictEqual(stdout.split('\n')[2], `Generated HTML file is ${fullpath}.html`)
t.equal(stdout.split('\n')[1], 'Analysing data')
t.equal(stdout.split('\n')[2], `Generated HTML file is ${fullpath}.html`)

// check that files exists
async.parallel({
Expand All @@ -57,7 +57,7 @@ test('clinic bubbleprof -- node - bad status code', function (t) {
fs.access(path.resolve(tempdir, dirname + '.html'), done)
}
}, function (err) {
t.ifError(err)
t.error(err)
t.end()
})
})
Expand All @@ -79,8 +79,8 @@ test('clinic bubbleprof -- node - visualization error', function (t) {
))
`
], function (err, stdout, stderr) {
t.strictDeepEqual(err, new Error('process exited with exit code 1'))
t.strictEqual(stdout, 'To generate the report press: Ctrl + C\nAnalysing data\n')
t.strictSame(err, new Error('process exited with exit code 1'))
t.equal(stdout, 'To generate the report press: Ctrl + C\nAnalysing data\n')
t.ok(stderr.includes('ENOENT: no such file or directory'))
t.end()
})
Expand All @@ -92,7 +92,7 @@ test('clinic bubbleprof -- node - configure output destination', function (t) {
'--dest', 'test-bubbleprof-destination',
'--', 'node', '-e', 'setTimeout(() => {}, 200)'
], function (err, stdout, stderr, tempdir) {
t.ifError(err)
t.error(err)
const basename = stdout.match(/(\d+.clinic-bubbleprof)/)[1]
t.ok(fs.statSync(path.join(tempdir, 'test-bubbleprof-destination', basename)).isDirectory())
t.ok(fs.statSync(path.join(tempdir, 'test-bubbleprof-destination', `${basename}.html`)).isFile())
Expand Down
Loading

0 comments on commit 87e8a21

Please sign in to comment.