From 0e137d0e88e941afd6fecfc2350931416dafd854 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Tue, 1 Mar 2022 12:13:56 +0000 Subject: [PATCH] feat: point to guidelines on failure in TAP output (#95) If commit linting fails, include the URL to the commit message guidelines in the TAP output. Refs: https://github.com/nodejs/node/issues/41697 --- lib/tap.js | 2 ++ test/cli-test.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/tap.js b/lib/tap.js index aec27d5..5e847ec 100644 --- a/lib/tap.js +++ b/lib/tap.js @@ -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) diff --git a/test/cli-test.js b/test/cli-test.js index 8729078..03beaf4 100644 --- a/test/cli-test.js +++ b/test/cli-test.js @@ -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 = ''