-
Notifications
You must be signed in to change notification settings - Fork 91
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 (#132)
Adds the option for a warning limit to be configured. When the number of warnings exceeds the limit, the exit code is set to 1. There is no limit by default
- Loading branch information
1 parent
09315b4
commit 2c3a919
Showing
8 changed files
with
276 additions
and
19 deletions.
There are no files selected for viewing
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
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,2 @@ | ||
[ | ||
: } |
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,113 @@ | ||
// 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 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.json'; | ||
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.json'; | ||
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.')).toEqual( | ||
true | ||
); | ||
|
||
expect(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.json'; | ||
program.default_mode = true; | ||
|
||
const capturedText = []; | ||
|
||
const unhookIntercept = intercept(function(txt) { | ||
capturedText.push(stripAnsiFrom(txt)); | ||
return ''; | ||
}); | ||
|
||
const exitCode = await commandLineValidator(program); | ||
|
||
unhookIntercept(); | ||
|
||
expect(exitCode).toEqual(0); | ||
}); | ||
|
||
it('should give an error for invalid JSON', async function() { | ||
const program = {}; | ||
program.args = ['./test/cli-validator/mockFiles/clean.yml']; | ||
program.limits = | ||
'./test/cli-validator/mockFiles/thresholds/invalidJSON.json'; | ||
program.default_mode = true; | ||
|
||
const capturedText = []; | ||
|
||
const unhookIntercept = intercept(function(txt) { | ||
capturedText.push(stripAnsiFrom(txt)); | ||
return ''; | ||
}); | ||
|
||
await expect(commandLineValidator(program)).rejects.toBe(2); | ||
|
||
unhookIntercept(); | ||
|
||
const allOutput = capturedText.join(''); | ||
|
||
expect( | ||
allOutput.includes( | ||
'[Error] There is a problem with the .thresholdrc file.' | ||
) | ||
); | ||
}); | ||
}); |