What the agent does
The agent reads how the extension is tested before it changes the config. In an extension started from chibat/chrome-extension-typescript-starter, jest.config.js sets roots to src and transforms .ts files with ts-jest using tsconfig.test.json, which extends tsconfig.json and sets Node module resolution. The only test is src/__tests__/sum.ts, which covers src/sum.ts; the files that do the extension's work, background.ts, content_script.tsx, options.tsx and popup.tsx, have no tests and call chrome.* APIs that do not exist under Jest. package.json pins jest ^29.5.0, ts-jest ^29.1.0, typescript ^5.0.4 and @types/chrome, and its test script is npx jest. .gitignore already lists dist/ and node_modules/ but not coverage/.
.github/workflows/build.yml runs on pushes and pull requests to main with a matrix of Node 20.x and 22.x: checkout, setup-node, npm ci, npm run build --if-present and npm test. The webpack build in webpack/webpack.common.js has four entries, popup, options, background and content_script, writes to dist/js and copies public/ beside them. Nothing measures what the one test covers, so the number is unknown until someone runs it.
The agent adds coverage to jest.config.js with no new dependency: collectCoverageFrom set to src/**/*.{ts,tsx} minus src/__tests__/**, coverageProvider set to v8 so ts-jest does not need Babel instrumentation, coverageReporters of text, lcov and json-summary, and coverageDirectory of coverage. It leaves collectCoverage off so a local npm test stays fast and makes the CI step npm test -- --coverage. In build.yml it adds, on the 22.x leg only, a step that uploads coverage/lcov.info with actions/upload-artifact and a step that reads coverage/coverage-summary.json and writes the line and branch percentages into $GITHUB_STEP_SUMMARY, so the number is on the run page without a third-party service. It adds coverage/ to .gitignore.
The agent sets a coverageThreshold floor only from a number it measured: it runs npm ci and npm test -- --coverage in its sandbox, reads the text report, which shows sum.ts covered and the four extension entry files at zero, and sets the global lines threshold to the measured total rounded down, so the floor cannot drop without someone noticing and nobody is blocked by a number picked from the air. It runs npm run build to show webpack is unaffected, then opens the pull request with the report table quoted and a note on what it would take to test the chrome.* code.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "codex",
"input": "Add code coverage to the Jest tests and the GitHub Actions workflow of this Chrome extension and open a pull request. Read package.json, jest.config.js, tsconfig.json, tsconfig.test.json, .gitignore, .github/workflows/build.yml, webpack/webpack.common.js and every file under src/ first. Use Jest's built-in coverage with the v8 provider and no new dependency: collectCoverageFrom over src/**/*.{ts,tsx} excluding the tests directory, reporters text, lcov and json-summary, output in coverage/. Keep collectCoverage off locally and pass --coverage in the workflow. On the Node 22 leg only, upload coverage/lcov.info as an artifact and write the line and branch percentages from coverage-summary.json into the job summary. Add coverage/ to .gitignore. Run npm ci, npm test -- --coverage and npm run build in the sandbox, set a global lines threshold to the total you measured rounded down, and quote the coverage table in the pull request with a note on which files are untested and why.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
What comes back is a pull request on its own branch that changes jest.config.js to collect coverage from src/ with the v8 provider and a measured lines floor, .github/workflows/build.yml to run npm test -- --coverage and, on Node 22, upload lcov.info and write the percentages to the job summary, and .gitignore to ignore coverage/. The description quotes the text report from the sandbox, with sum.ts covered and background.ts, content_script.tsx, options.tsx and popup.tsx at zero, and says how the floor was chosen.
The proof is the sandbox output kept in the run's record and quoted in the description: npm test -- --coverage with the table and the threshold passing, and npm run build finishing. The repository's own build.yml runs on the pull request, so the matrix shows the new step on both Node versions and the job summary shows the percentages on the run page.
Before merging, a reviewer checks that the floor is the measured number and not an aspiration, that the artifact retention suits them, that coverage/ is ignored, and whether they want the chrome.* files tested next, which the description sizes as a follow-up with a chrome mock. Then they merge and watch the summary on the next pull request.
Run it on every extension repository without a coverage number
A team with several extensions sends one POST /o/{org}/sessions per repository from the terminal or a script, with this prompt and the repository in resources. GET /o/{org}/github lists every repository the Rush GitHub App installation can reach, so a script can start a run for each one whose jest.config.js has no collectCoverageFrom. Each run reads its own config, so an extension on Vitest gets @vitest/coverage-v8 and one with a Babel transform gets the babel provider, and each opens its own pull request.
Set a webhook URL on the API key and Rush POSTs run.completed or run.failed when a run's turn finishes, with session_url so your server can read the pull request link. Send a fresh UUID as request_id with each request so a retry returns the run already started.
The use case this job follows, with its automation and trigger: Write the missing tests.
Why run it on Rush?
Turning on coverage takes five lines; choosing a threshold that is honest, wiring the report into a matrix without a paid service, and knowing that the extension's chrome.* code is why the number is low all take a measurement first. On Rush the agent runs the suite with coverage in its own sandbox, reads the table, and sets the floor from what it saw, so the pull request carries the report and the reasoning instead of a guessed percentage. Your machine installs nothing.
The run's record keeps the full table and every command, the workflow change is readable in one screen, and the floor is enforced from the first merge onward. The same request can go to every extension the team keeps, one sandbox and one pull request each.
Frequently asked questions
Why the v8 provider rather than Babel?
The project transforms TypeScript with ts-jest, and the v8 provider takes coverage from the Node runtime without instrumenting the source, so no Babel preset or extra dependency is needed. It also reports on the compiled output mapped back through source maps, which ts-jest emits.
Will the extension's chrome.* code show real numbers?
It will show zero until it has tests, because background.ts, content_script.tsx, options.tsx and popup.tsx call chrome.storage and chrome.action and nothing exercises them under Jest. The pull request says so and sizes the follow-up: a chrome global mock in a Jest setup file, then tests per entry point.
Does it slow the matrix down?
By the time it takes Jest to collect coverage on one small test, which is a few seconds, plus the artifact upload on the Node 22 leg only. The Node 20 leg still runs the tests with coverage so the threshold is enforced on both, but uploads nothing.
Can it enforce a minimum percentage?
It does, with a global lines floor set to the total it measured in the sandbox, rounded down. Raise it in jest.config.js as tests are added; the agent never sets a number it did not read in a report.
More Chrome Extension jobs
The same job on other stacks
- Add Test Coverage Reporting to a CMake Project's CI (CMake)
- Add Test Coverage Reporting to a Cobra CLI's CI (Cobra)
- Add Test Coverage to CI for a Django REST Framework API (Django REST Framework)