Skip to content

feature: template coverage - #433

Open
lifeart wants to merge 1 commit into
ember-cli-code-coverage:masterfrom
lifeart:track-coverage-for-gts-hbs-files
Open

feature: template coverage#433
lifeart wants to merge 1 commit into
ember-cli-code-coverage:masterfrom
lifeart:track-coverage-for-gts-hbs-files

Conversation

@lifeart

@lifeart lifeart commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Template Coverage

This addon supports branch coverage for Glimmer/Handlebars templates (.hbs files and <template> tags in .gjs/.gts files). When COVERAGE=true, templates are automatically instrumented during compilation to track which branches are executed.

What is tracked

  • Block conditionals: {{#if}}, {{#unless}} (with and without {{else}})
  • Inline conditionals: {{if condition "yes" "no"}}, (if condition "a" "b"), and the unless equivalents
  • List branches: {{#each}}/{{#each-in}} with {{else}} (items vs empty list)
  • Chained conditionals: {{else if}} chains

How it works

A Glimmer AST plugin runs at build time and:

  1. Injects {{coverageInit}} at the template root to register an Istanbul-compatible coverage object in window.__coverage__
  2. Injects {{coverageMark}} at the start of each block branch body to record block branch hits
  3. Wraps inline conditional conditions with (coverageCond) to record inline branch hits reactively

The coverage data integrates seamlessly with the existing Istanbul pipeline, appearing in the same HTML/LCOV/JSON reports alongside JavaScript coverage.

Setup for .hbs files

No additional setup is needed. The AST plugin is registered automatically via setupPreprocessorRegistry when the addon is installed. Branch coverage for .hbs files works out of the box.

Setup for .gjs/.gts files (strict mode)

For .gjs/.gts files using <template> tags, coverage helpers need to be in JavaScript scope. The buildBabelPlugin() method already includes a Babel plugin that injects the necessary imports automatically. No extra configuration is required if you already have buildBabelPlugin() in your ember-cli-build.js.

@lifeart
lifeart force-pushed the track-coverage-for-gts-hbs-files branch 3 times, most recently from 316b242 to 3ca5027 Compare March 18, 2026 07:57
feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage

feature: template coverage
@lifeart
lifeart force-pushed the track-coverage-for-gts-hbs-files branch from 3cd51e7 to d6b09e8 Compare March 18, 2026 10:00
@SergeAstapov SergeAstapov mentioned this pull request Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant