-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added configurable warning limits through .thresholdrc file
- added code to process a .thresholdrc file to get warnings limit - used warning limit to set exit code to 1 and print a message if warning limit is exceeded - added validation on the user input from .thresholdrc to check if valid keys and values provided in .thresholdrc - set default limit to Number.MAX_VALUE if no .thresholdrc provided - added tests to test error handling for .thresholdrc file and expected output when warning limits exceeded
- Loading branch information
Barrett Schonefeld
committed
Feb 6, 2020
1 parent
384af4c
commit 152aed4
Showing
7 changed files
with
234 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"warnings": 5 | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"errors": 0, | ||
"warnings": "text", | ||
"population": 10 | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"warnings": 0 | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// the rule names are all snake case and need to stay that way. don't lint them | ||
/* eslint-disable camelcase */ | ||
|
||
const intercept = require('intercept-stdout'); | ||
const expect = require('expect'); | ||
const stripAnsiFrom = require('strip-ansi'); | ||
const chalk = require('chalk'); | ||
|
||
const commandLineValidator = require('../../../src/cli-validator/runValidator'); | ||
|
||
describe('test the .thresholdrc limits', function() { | ||
it('should show error and set exit code to 1 when warning limit exceeded', async function() { | ||
|
||
const capturedText = []; | ||
|
||
const program = {}; | ||
program.args = ['./test/cli-validator/mockFiles/circularRefs.yml']; | ||
program.limits = | ||
'./test/cli-validator/mockFiles/thresholds/.fiveWarnings'; | ||
program.default_mode = true; | ||
|
||
const unhookIntercept = intercept(function(txt) { | ||
capturedText.push(stripAnsiFrom(txt)); | ||
return ''; | ||
}); | ||
|
||
const exitCode = await commandLineValidator(program); | ||
|
||
unhookIntercept(); | ||
|
||
expect(exitCode).toEqual(1); | ||
|
||
expect(capturedText[capturedText.length - 1].slice(0, 18)).toEqual( | ||
`Number of warnings` | ||
); | ||
}); | ||
|
||
it('should print errors for unsupported limit options and invalid limit values', async function() { | ||
|
||
const capturedText = []; | ||
|
||
const program = {}; | ||
program.args = ['./test/cli-validator/mockFiles/clean.yml']; | ||
program.limits = | ||
'./test/cli-validator/mockFiles/thresholds/.invalidValues'; | ||
program.default_mode = true; | ||
|
||
const unhookIntercept = intercept(function(txt) { | ||
capturedText.push(stripAnsiFrom(txt)); | ||
return ''; | ||
}); | ||
|
||
const exitCode = await commandLineValidator(program); | ||
|
||
unhookIntercept(); | ||
|
||
// limit values invalid, so default limit, Number.MAX_VALUE, used | ||
expect(exitCode).toEqual(0); | ||
|
||
const allOutput = capturedText.join(''); | ||
|
||
expect( | ||
allOutput.includes('\"population\" limit not supported.') && | ||
allOutput.includes('Value provided for warnings') | ||
).toEqual(true); | ||
|
||
}); | ||
|
||
it('should give exit code 0 when warnings limit not exceeded', async function() { | ||
|
||
const program = {}; | ||
program.args = ['./test/cli-validator/mockFiles/clean.yml']; | ||
program.limits = | ||
'./test/cli-validator/mockFiles/thresholds/.zeroWarnings'; | ||
program.default_mode = true; | ||
|
||
const exitCode = await commandLineValidator(program); | ||
|
||
expect(exitCode).toEqual(0); | ||
}); | ||
|
||
}); |