-
Notifications
You must be signed in to change notification settings - Fork 19
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
fix: fail when min_coverage is not a number #287
Conversation
Some files were formatted when I ran |
index.js
Outdated
} | ||
|
||
function canUseMinCoverage(minCoverage) { | ||
let asNumber = Number(minCoverage); |
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.
As per the documentation, minCoverage
is optional and defaults to 100.
Am I missing something trivial, or would this make the minCoverage
argument required?
isNaN(Number(undefined)) // evaluates to True
I'm surprised this isn't being captured by the tests.
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.
Yeah, you're right. I'll add a new test and fix this.
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.
Just to mention, that is happening because, when the argument min_coverage
is not provided, core.getInput('min_coverage')
, returns an empty string ''
.
const minCoverage = core.getInput('min_coverage'); // returns ''
let asNumber = Number(minCoverage); // yeah, it returns 0
isNaN(asNumber); // returns false
I love js 😍
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.
I think this test suit is not right.
First, take a look at the test which 'fails when the coverage is not 100 and min_coverage is not provided'
. If we put a breakpoint on index.js 44
, we will see that coverage
is 100
, which is not expected, since the coverage file is the lcov.95.info
, and the test description doesn't mention ignoring/excluding files.
This is happening because the previous test, 'completes when the coverage is higher than the threshold after excluding files'
, is setting the variable INPUT_EXCLUDE
, and there are no functions to clean-up the environment variables after each test.
One possible solution is to add the following code before the first test:
afterEach(() => {
delete process.env['INPUT_PATH'];
delete process.env['INPUT_EXCLUDE'];
delete process.env['INPUT_MIN_COVERAGE'];
});
Besides, there's another weird thing on this test file. Let's also take the test 'fails when the coverage is not 100 and min_coverage is not provided'
as example:
test('fails when the coverage is not 100 and min_coverage is not provided', () => {
const lcovPath = './fixtures/lcov.95.info';
process.env['INPUT_PATH'] = lcovPath;
const ip = path.join(__dirname, 'index.js');
try {
cp.execSync(`node ${ip}`, { env: process.env }).toString();
fail('this code should fail');
} catch (err) {
expect(err).toBeDefined();
}
});
This is code isn't testing anything.
If we put a breakpoint on catch
, we can see that the err
error is the one thrown by the call fail('this code should fail');
. Instead of asserting it toBeDefined()
, we should look for the output with getErrorOutput(err)
, and then assert the message.
My question is: should I fix these issues with this PR, or should I open another one?
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.
Hi @kelvinwieth thanks for the details and the work here! I'm happy for you to open two new additional Pull Requests one to include the afterEach
and another to perform a check on the error output.
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.
I will probably be offline in the next days, due to a long weekend, but at least on monday I can open these PRs. Thank you, @alestiago!
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.
I forgot that my fork branch for this PR was the main
, and did reset the changes to work on the afterEach
and the error output. After working on these other issues, I will open this fix for the min_coverage
on another PR.
Sorry, I'm not experienced with forks to PRs 😳
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.
No worries, we're all always learning! Thank you for taking the lead here, looking forward to those Pull Requests 🙌
Description
Solves #255
Type of Change