Skip to content

Commit

Permalink
feat: point to guidelines on failure in TAP output (#95)
Browse files Browse the repository at this point in the history
If commit linting fails, include the URL to the commit message
guidelines in the TAP output.

Refs: nodejs/node#41697
  • Loading branch information
richardlau authored Mar 1, 2022
1 parent 69435db commit 0e137d0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ module.exports = class Tap extends Readable {

if (this._failures) {
this.write(`# fail ${this._failures}`)
this.write('# Please review the commit message guidelines:')
this.write('# https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines')
}

this.push(null)
Expand Down
31 changes: 31 additions & 0 deletions test/cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,37 @@ test('Test cli flags', (t) => {
})
})

t.test('test tap output', (tt) => {
// Use a commit from this repository that does not follow the guidelines.
const ls = spawn('./bin/cmd.js', ['--no-validate-metadata', '--tap', '69435db261'])
let compiledData = ''
ls.stdout.on('data', (data) => {
compiledData += data
})

ls.stderr.on('data', (data) => {
tt.fail(`Unexpected stderr output ${data.toString()}`)
})

ls.on('close', (code) => {
const output = compiledData.trim()
tt.match(output,
/# 69435db261/,
'TAP output contains the sha of the commit being linted')
tt.match(output,
/not ok \d+ subsystem: Invalid subsystem: "chore" \(chore: update tested node release lines \(#94\)\)/,
'TAP output contains failure for subsystem')
tt.match(output,
/# fail\s+\d+/,
'TAP output contains total failures')
tt.match(output,
/# Please review the commit message guidelines:\s# https:\/\/github.com\/nodejs\/node\/blob\/HEAD\/doc\/contributing\/pull-requests.md#commit-message-guidelines/,
'TAP output contains pointer to commit message guidelines')
tt.equal(code, 1, 'CLI exits with non-zero code on failure')
tt.end()
})
})

t.test('test url', (tt) => {
const ls = spawn('./bin/cmd.js', ['--no-validate-metadata', 'https://api.github.com/repos/nodejs/core-validate-commit/commits/2b98d02b52'])
let compiledData = ''
Expand Down

0 comments on commit 0e137d0

Please sign in to comment.