Writing tests is step one. Knowing which code paths are actually exercised is step two β€” without coverage, you may have tests and still deploy untested branches to production.

Run jest with --coverage to generate a report showing which lines, functions, and branches of your Adobe Campaign JavaScript are tested.

Preparation

Requirements: acc installed and authenticated, jest configured. Refer to Unit tests for Adobe Campaign JavaScript with jest before proceeding.

Walkthrough

1. Run jest with coverage

npx jest --coverage

Jest generates a summary in the terminal and a detailed HTML report in coverage/lcov-report/index.html.

----------|---------|----------|---------|---------|
File      | % Stmts | % Branch | % Funcs | % Lines |
----------|---------|----------|---------|---------|
myHelpers |    85.7 |     66.6 |     100 |    85.7 |
----------|---------|----------|---------|---------|

2. Read the report

Open coverage/lcov-report/index.html in a browser. Each file shows line-by-line coverage:

  • Green β€” line was executed during tests
  • Red β€” line was never reached
  • Yellow β€” branch partially covered (e.g. an if with no else test)

Red lines in a workflow helper or a delivery formatting function indicate logic that reaches production untested.

3. Set a coverage threshold

Fail the test run automatically if coverage drops below a minimum. Add to package.json:

{
  "jest": {
    "setupFiles": ["./jest.setup.js"],
    "coverageThreshold": {
      "global": {
        "lines": 80,
        "functions": 80,
        "branches": 60
      }
    }
  }
}

Jest exits with a non-zero code if thresholds are not met β€” blocking a CI/CD pipeline on regressions.

Validation & troubleshooting

Coverage report shows 0% for all files

Jest only tracks coverage for files imported by your test files. Verify each .test.js file uses require("./myFile.js") and that the path is correct.

HTML report not generated

Run with --coverage --coverageReporters=html explicitly, or add "coverageReporters": ["html", "text"] to the jest config in package.json.

Going further

Add npx jest --coverage to your CI/CD pipeline after each acc instance pull. A coverage drop between two pulls signals that new code was added to the instance without corresponding tests. Refer to Improve Code Traceability with acc CLI and Git.