0
0
Node.jsframework~10 mins

Code coverage basics in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the code coverage tool 'nyc' in a Node.js project.

Node.js
const nyc = require('[1]');
Drag options to blanks, or click blank then click option'
Amocha
Bnyc
Cjest
Dchai
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'mocha' or 'jest' instead of 'nyc' for coverage import.
Forgetting to install 'nyc' before importing.
2fill in blank
medium

Complete the command to run tests with coverage using 'nyc' and 'mocha'.

Node.js
npm [1]
Drag options to blanks, or click blank then click option'
Atest
Brun
Cexec
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' or 'start' instead of 'test' in the command.
Forgetting to configure the package.json 'test' script with 'nyc mocha'.
3fill in blank
hard

Fix the error in the coverage configuration by completing the missing key in the JSON.

Node.js
{
  "[1]": "./src",
  "reporter": ["text", "html"]
}
Drag options to blanks, or click blank then click option'
Ainclude
Bexclude
Csource
DcoverageDir
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'exclude' instead of 'include' causes wrong coverage files.
Using 'source' which is not a valid key.
4fill in blank
hard

Fill both blanks to create a script in package.json that runs tests with coverage and outputs an HTML report.

Node.js
"scripts": {
  "coverage": "nyc --reporter=[1] [2]"
}
Drag options to blanks, or click blank then click option'
Ahtml
Bmocha
Ctext
Djest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' instead of 'html' for the reporter when HTML output is needed.
Using 'jest' instead of 'mocha' if the project uses mocha.
5fill in blank
hard

Fill all three blanks to create a coverage ignore configuration that excludes test files and node_modules.

Node.js
{
  "exclude": ["[1]", "[2]", "[3]"]
}
Drag options to blanks, or click blank then click option'
Atest
Bnode_modules
C*.spec.js
Dsrc
Attempts:
3 left
💡 Hint
Common Mistakes
Including 'src' in exclude which removes source files from coverage.
Not excluding test files causing coverage to include tests.