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

Example coverage task #89

@BridgeAR

Description

@BridgeAR

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions