Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests and bugfix for line-after-title #29

Merged
merged 2 commits into from
Oct 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 'evanlucas@me.com'
, 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: 'evanlucas@me.com'
, 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: 'evanlucas@me.com'
, 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()
})