-
Notifications
You must be signed in to change notification settings - Fork 933
test(lint): migrate ava tests to jest #912
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,43 @@ | ||
import test from 'ava'; | ||
import lint from '.'; | ||
|
||
test('throws without params', async t => { | ||
const error = await t.throwsAsync(lint()); | ||
t.is(error.message, 'Expected a raw commit'); | ||
test('throws without params', async () => { | ||
const error = lint(); | ||
await expect(error).rejects.toThrow('Expected a raw commit'); | ||
}); | ||
|
||
test('throws with empty message', async t => { | ||
const error = await t.throwsAsync(lint('')); | ||
t.is(error.message, 'Expected a raw commit'); | ||
test('throws with empty message', async () => { | ||
const error = lint(''); | ||
await expect(error).rejects.toThrow('Expected a raw commit'); | ||
}); | ||
|
||
test('positive on stub message and no rule', async t => { | ||
test('positive on stub message and no rule', async () => { | ||
const actual = await lint('foo: bar'); | ||
t.true(actual.valid); | ||
expect(actual.valid).toBe(true); | ||
}); | ||
|
||
test('positive on stub message and adhered rule', async t => { | ||
test('positive on stub message and adhered rule', async () => { | ||
const actual = await lint('foo: bar', { | ||
'type-enum': [2, 'always', ['foo']] | ||
}); | ||
t.true(actual.valid); | ||
expect(actual.valid).toBe(true); | ||
}); | ||
|
||
test('negative on stub message and broken rule', async t => { | ||
test('negative on stub message and broken rule', async () => { | ||
const actual = await lint('foo: bar', { | ||
'type-enum': [2, 'never', ['foo']] | ||
}); | ||
t.false(actual.valid); | ||
expect(actual.valid).toBe(false); | ||
}); | ||
|
||
test('positive on ignored message and broken rule', async t => { | ||
test('positive on ignored message and broken rule', async () => { | ||
const actual = await lint('Revert "some bogus commit"', { | ||
'type-empty': [2, 'never'] | ||
}); | ||
t.true(actual.valid); | ||
t.is(actual.input, 'Revert "some bogus commit"'); | ||
expect(actual.valid).toBe(true); | ||
expect(actual.input).toBe('Revert "some bogus commit"'); | ||
}); | ||
|
||
test('negative on ignored message, disabled ignored messages and broken rule', async t => { | ||
test('negative on ignored message, disabled ignored messages and broken rule', async () => { | ||
const actual = await lint( | ||
'Revert "some bogus commit"', | ||
{ | ||
|
@@ -48,10 +47,10 @@ test('negative on ignored message, disabled ignored messages and broken rule', a | |
defaultIgnores: false | ||
} | ||
); | ||
t.false(actual.valid); | ||
expect(actual.valid).toBe(false); | ||
}); | ||
|
||
test('positive on custom ignored message and broken rule', async t => { | ||
test('positive on custom ignored message and broken rule', async () => { | ||
const ignoredMessage = 'some ignored custom message'; | ||
const actual = await lint( | ||
ignoredMessage, | ||
|
@@ -62,11 +61,11 @@ test('positive on custom ignored message and broken rule', async t => { | |
ignores: [c => c === ignoredMessage] | ||
} | ||
); | ||
t.true(actual.valid); | ||
t.is(actual.input, ignoredMessage); | ||
expect(actual.valid).toBe(true); | ||
expect(actual.input).toBe(ignoredMessage); | ||
}); | ||
|
||
test('positive on stub message and opts', async t => { | ||
test('positive on stub message and opts', async () => { | ||
const actual = await lint( | ||
'foo-bar', | ||
{ | ||
|
@@ -79,108 +78,102 @@ test('positive on stub message and opts', async t => { | |
} | ||
} | ||
); | ||
t.true(actual.valid); | ||
expect(actual.valid).toBe(true); | ||
}); | ||
|
||
test('throws for invalid rule names', async t => { | ||
const error = await t.throwsAsync( | ||
lint('foo', {foo: [2, 'always'], bar: [1, 'never']}) | ||
); | ||
test('throws for invalid rule names', async () => { | ||
const error = lint('foo', {foo: [2, 'always'], bar: [1, 'never']}); | ||
|
||
t.is(error.message.indexOf('Found invalid rule names: foo, bar'), 0); | ||
await expect(error).rejects.toThrow(/^Found invalid rule names: foo, bar/); | ||
}); | ||
|
||
test('throws for invalid rule config', async t => { | ||
const error = await t.throwsAsync( | ||
lint('type(scope): foo', { | ||
'type-enum': 1, | ||
'scope-enum': {0: 2, 1: 'never', 2: ['foo'], length: 3} | ||
}) | ||
); | ||
test('throws for invalid rule config', async () => { | ||
const error = lint('type(scope): foo', { | ||
'type-enum': 1, | ||
'scope-enum': {0: 2, 1: 'never', 2: ['foo'], length: 3} | ||
}); | ||
|
||
t.true(error.message.indexOf('type-enum must be array') > -1); | ||
t.true(error.message.indexOf('scope-enum must be array') > -1); | ||
await expect(error).rejects.toThrow('type-enum must be array'); | ||
await expect(error).rejects.toThrow('scope-enum must be array'); | ||
}); | ||
|
||
test('allows disable shorthand', async t => { | ||
await t.notThrowsAsync(lint('foo', {'type-enum': [0], 'scope-enum': [0]})); | ||
test('allows disable shorthand', async () => { | ||
const result = lint('foo', {'type-enum': [0], 'scope-enum': [0]}); | ||
|
||
await expect(result).resolves.toEqual({ | ||
errors: [], | ||
input: 'foo', | ||
valid: true, | ||
warnings: [] | ||
}); | ||
}); | ||
|
||
test('throws for rule with invalid length', async t => { | ||
const error = await t.throwsAsync( | ||
lint('type(scope): foo', {'scope-enum': [1, 2, 3, 4]}) | ||
); | ||
test('throws for rule with invalid length', async () => { | ||
const error = lint('type(scope): foo', {'scope-enum': [1, 2, 3, 4]}); | ||
|
||
t.true(error.message.indexOf('scope-enum must be 2 or 3 items long') > -1); | ||
await expect(error).rejects.toThrow('scope-enum must be 2 or 3 items long'); | ||
}); | ||
|
||
test('throws for rule with invalid level', async t => { | ||
const error = await t.throwsAsync( | ||
lint('type(scope): foo', { | ||
'type-enum': ['2', 'always'], | ||
'header-max-length': [{}, 'always'] | ||
}) | ||
); | ||
|
||
t.true(error.message.indexOf('rule type-enum must be number') > -1); | ||
t.true(error.message.indexOf('rule type-enum must be number') > -1); | ||
test('throws for rule with invalid level', async () => { | ||
const error = lint('type(scope): foo', { | ||
'type-enum': ['2', 'always'], | ||
'header-max-length': [{}, 'always'] | ||
}); | ||
await expect(error).rejects.toThrow('rule type-enum must be number'); | ||
await expect(error).rejects.toThrow('rule header-max-length must be number'); | ||
}); | ||
|
||
test('throws for rule with out of range level', async t => { | ||
const error = await t.throwsAsync( | ||
lint('type(scope): foo', { | ||
'type-enum': [-1, 'always'], | ||
'header-max-length': [3, 'always'] | ||
}) | ||
); | ||
test('throws for rule with out of range level', async () => { | ||
const error = lint('type(scope): foo', { | ||
'type-enum': [-1, 'always'], | ||
'header-max-length': [3, 'always'] | ||
}); | ||
|
||
t.true(error.message.indexOf('rule type-enum must be between 0 and 2') > -1); | ||
t.true(error.message.indexOf('rule type-enum must be between 0 and 2') > -1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of checking this 2 times we should check 'rule type-enum must be between 0 and 2'
'rule header-max-length must be between 0 and 2' |
||
await expect(error).rejects.toThrow('rule type-enum must be between 0 and 2'); | ||
await expect(error).rejects.toThrow( | ||
'rule header-max-length must be between 0 and 2' | ||
); | ||
}); | ||
|
||
test('throws for rule with invalid condition', async t => { | ||
const error = await t.throwsAsync( | ||
lint('type(scope): foo', { | ||
'type-enum': [1, 2], | ||
'header-max-length': [1, {}] | ||
}) | ||
); | ||
test('throws for rule with invalid condition', async () => { | ||
const error = lint('type(scope): foo', { | ||
'type-enum': [1, 2], | ||
'header-max-length': [1, {}] | ||
}); | ||
|
||
t.true(error.message.indexOf('type-enum must be string') > -1); | ||
t.true(error.message.indexOf('header-max-length must be string') > -1); | ||
await expect(error).rejects.toThrow('type-enum must be string'); | ||
await expect(error).rejects.toThrow('header-max-length must be string'); | ||
}); | ||
|
||
test('throws for rule with out of range condition', async t => { | ||
const error = await t.throwsAsync( | ||
lint('type(scope): foo', { | ||
'type-enum': [1, 'foo'], | ||
'header-max-length': [1, 'bar'] | ||
}) | ||
); | ||
test('throws for rule with out of range condition', async () => { | ||
const error = lint('type(scope): foo', { | ||
'type-enum': [1, 'foo'], | ||
'header-max-length': [1, 'bar'] | ||
}); | ||
|
||
t.true(error.message.indexOf('type-enum must be "always" or "never"') > -1); | ||
t.true( | ||
error.message.indexOf('header-max-length must be "always" or "never"') > -1 | ||
await expect(error).rejects.toThrow('type-enum must be "always" or "never"'); | ||
await expect(error).rejects.toThrow( | ||
'header-max-length must be "always" or "never"' | ||
); | ||
}); | ||
|
||
test('succeds for issue', async t => { | ||
test('succeds for issue', async () => { | ||
const report = await lint('somehting #1', { | ||
'references-empty': [2, 'never'] | ||
}); | ||
|
||
t.true(report.valid); | ||
expect(report.valid).toBe(true); | ||
}); | ||
|
||
test('fails for issue', async t => { | ||
test('fails for issue', async () => { | ||
const report = await lint('somehting #1', { | ||
'references-empty': [2, 'always'] | ||
}); | ||
|
||
t.false(report.valid); | ||
expect(report.valid).toBe(false); | ||
}); | ||
|
||
test('succeds for custom issue prefix', async t => { | ||
test('succeds for custom issue prefix', async () => { | ||
const report = await lint( | ||
'somehting REF-1', | ||
{ | ||
|
@@ -193,10 +186,10 @@ test('succeds for custom issue prefix', async t => { | |
} | ||
); | ||
|
||
t.true(report.valid); | ||
expect(report.valid).toBe(true); | ||
}); | ||
|
||
test('fails for custom issue prefix', async t => { | ||
test('fails for custom issue prefix', async () => { | ||
const report = await lint( | ||
'somehting #1', | ||
{ | ||
|
@@ -209,10 +202,10 @@ test('fails for custom issue prefix', async t => { | |
} | ||
); | ||
|
||
t.false(report.valid); | ||
expect(report.valid).toBe(false); | ||
}); | ||
|
||
test('fails for custom plugin rule', async t => { | ||
test('fails for custom plugin rule', async () => { | ||
const report = await lint( | ||
'somehting #1', | ||
{ | ||
|
@@ -229,10 +222,10 @@ test('fails for custom plugin rule', async t => { | |
} | ||
); | ||
|
||
t.false(report.valid); | ||
expect(report.valid).toBe(false); | ||
}); | ||
|
||
test('passes for custom plugin rule', async t => { | ||
test('passes for custom plugin rule', async () => { | ||
const report = await lint( | ||
'somehting #1', | ||
{ | ||
|
@@ -249,31 +242,31 @@ test('passes for custom plugin rule', async t => { | |
} | ||
); | ||
|
||
t.true(report.valid); | ||
expect(report.valid).toBe(true); | ||
}); | ||
|
||
test('returns original message only with commit header', async t => { | ||
test('returns original message only with commit header', async () => { | ||
const message = 'foo: bar'; | ||
const report = await lint(message); | ||
|
||
t.is(report.input, message); | ||
expect(report.input).toBe(message); | ||
}); | ||
|
||
test('returns original message with commit header and body', async t => { | ||
test('returns original message with commit header and body', async () => { | ||
const message = 'foo: bar/n/nFoo bar bizz buzz.'; | ||
const report = await lint(message); | ||
|
||
t.is(report.input, message); | ||
expect(report.input).toBe(message); | ||
}); | ||
|
||
test('returns original message with commit header, body and footer', async t => { | ||
test('returns original message with commit header, body and footer', async () => { | ||
const message = 'foo: bar/n/nFoo bar bizz buzz./n/nCloses #1'; | ||
const report = await lint(message); | ||
|
||
t.is(report.input, message); | ||
expect(report.input).toBe(message); | ||
}); | ||
|
||
test('returns original message with commit header, body and footer, parsing comments', async t => { | ||
test('returns original message with commit header, body and footer, parsing comments', async () => { | ||
const expected = 'foo: bar/n/nFoo bar bizz buzz./n/nCloses #1'; | ||
const message = `${expected}\n\n# Some comment to ignore`; | ||
const report = await lint( | ||
|
@@ -288,5 +281,5 @@ test('returns original message with commit header, body and footer, parsing comm | |
} | ||
); | ||
|
||
t.is(report.input, expected); | ||
expect(report.input).toBe(expected); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of checking this 2 times we should check