Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Example coverage task #89

Open
BridgeAR opened this issue Nov 6, 2018 · 1 comment
Open

Example coverage task #89

BridgeAR opened this issue Nov 6, 2018 · 1 comment

Comments

@BridgeAR
Copy link
Member

BridgeAR commented Nov 6, 2018

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:

  1. Add console.log to this specific code path.

image

  1. Compile Node.js with the changed code running make -J.

  2. Find out how to trigger this specific code path by looking at the code.

  3. 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().

image

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.

  1. Check existing tests for something similar. There are test files for the assert module in test/parallel/test-assert*.js.

image

One of these files is called test-assert-deep.js. This is one that contains tests for assert.deepStrictEqual().

  1. 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:

image

  1. Verify the output.

image

  1. Remove the console output again.

  2. Run make lint to verify that the linter is happy. It might take a while running it for the first time.

image

If there is no error output, everything is fine!

  1. Commit your change with a proper commit message (check the guidelines).

  2. Call for a collaborator to verify everything and then open your PR!

@antsmartian
Copy link

This is really neat @BridgeAR 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants