code-and-learn
code-and-learn copied to clipboard
Example coverage task
This is used as example how to solve a coverage task:
https://tinyurl.com/codeandlearn-assert-1
Description: A test case is missing for the else case.
Task:
Add a test case to cover this branch. Be carful to reach exactly this code branch.
Check for other examples in the assertion test files (test/parallel/test-assert*.js
).
Before opening the pull request: Please read the commit guidelines (https://tinyurl.com/commit-guidelines) and add a proper description as commit message. After finishing the task ask a mentor to verify the change, the commit message and the pull request description. If everything is in order, open the pull request.
Solving the task:
- Add
console.log
to this specific code path.
-
Compile Node.js with the changed code running
make -J
. -
Find out how to trigger this specific code path by looking at the code.
-
Start the repl and execute the code or add a test case to run that file.
Looking at the code we found out that we have to have extra actual
lines to trigger this case using assert.deepStrictEqual()
.
As we see, we managed to trigger the new code path (executing the code shows YEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa
). That is exactly what we wanted, so we found a way to trigger this case. So now let's add a test for it as well.
- Check existing tests for something similar. There are test files for the
assert
module intest/parallel/test-assert*.js
.
One of these files is called test-assert-deep.js
. This is one that contains tests for assert.deepStrictEqual()
.
- We want to add a test that verifies the error message output, so we copy an existing one and use our test case to trigger this error:
- Verify the output.
-
Remove the console output again.
-
Run
make lint
to verify that the linter is happy. It might take a while running it for the first time.
If there is no error output, everything is fine!
-
Commit your change with a proper commit message (check the guidelines).
-
Call for a collaborator to verify everything and then open your PR!
This is really neat @BridgeAR 👍