Skip to content

Commit

Permalink
tests and bugfix for line-after-title (#29)
Browse files Browse the repository at this point in the history
* add basic tests for line-after-title rule

* fix line-after-title for commits without a body
  • Loading branch information
Trott authored Oct 7, 2018
1 parent 3977e00 commit 3032b71
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/line-after-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
, options: {}
, validate: (context, rule) => {
// all commits should have a body and a blank line after the title
if (!context.body.length || context.body[0]) {
if (context.body[0]) {
context.report({
id: id
, message: 'blank line expected after title'
Expand Down
82 changes: 82 additions & 0 deletions test/rules/line-after-title.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
'use strict'

const test = require('tap').test
const Rule = require('../../lib/rules/line-after-title')
const Commit = require('gitlint-parser-node')
const Validator = require('../../')

test('rule: line-after-title', (t) => {
t.test('no blank line', (tt) => {
tt.plan(7)
const v = new Validator()
const context = new Commit({
sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea'
, author: {
name: 'Evan Lucas'
, email: '[email protected]'
, date: '2016-04-12T19:42:23Z'
}
, message: 'test: fix something\nfhqwhgads'
}, v)

context.report = (opts) => {
tt.pass('called report')
tt.equal(opts.id, 'line-after-title', 'id')
tt.equal(opts.message, 'blank line expected after title', 'message')
tt.equal(opts.string, 'fhqwhgads', 'string')
tt.equal(opts.line, 1, 'line')
tt.equal(opts.column, 0, 'column')
tt.equal(opts.level, 'fail', 'level')
}

Rule.validate(context)
})

t.test('blank line', (tt) => {
tt.plan(4)
const v = new Validator()
const context = new Commit({
sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea'
, author: {
name: 'Evan Lucas'
, email: '[email protected]'
, date: '2016-04-12T19:42:23Z'
}
, message: 'test: fix something\n\nfhqwhgads'
}, v)

context.report = (opts) => {
tt.pass('called report')
tt.equal(opts.id, 'line-after-title', 'id')
tt.equal(opts.message, 'blank line after title', 'message')
tt.equal(opts.level, 'pass', 'level')
}

Rule.validate(context)
})

t.test('just one line', (tt) => {
tt.plan(4)
const v = new Validator()
const context = new Commit({
sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea'
, author: {
name: 'Evan Lucas'
, email: '[email protected]'
, date: '2016-04-12T19:42:23Z'
}
, message: 'test: fix something'
}, v)

context.report = (opts) => {
tt.pass('called report')
tt.equal(opts.id, 'line-after-title', 'id')
tt.equal(opts.message, 'blank line after title', 'message')
tt.equal(opts.level, 'pass', 'level')
}

Rule.validate(context)
})

t.end()
})

0 comments on commit 3032b71

Please sign in to comment.