I'm trying to get test coverage using Playwright on a Next server. The tests reside in e2e-tests/
and the server in frontend/
.
After some struggles I've managed to end up some json files looking like the following inside e2e-tests/.nyc_output
:
{
"/[path]/Component.tsx": {
"path": "/[path]/Component.tsx",
"all": false,
"statementMap": {
"0": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 45 } },
"1": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 37 } },
...
},
"s": {
"0": 1,
"1": 1,
...
},
"branchMap": {
"0": {
"type": "branch",
"line": 14,
"loc": { "start": { "line": 14, "column": 0 }, "end": { "line": 36, "column": 1 } },
"locations": [{ "start": { "line": 14, "column": 0 }, "end": { "line": 36, "column": 1 } }]
},
...
},
"b": { "0": [6] ... },
"fnMap": {
"0": {
"name": "Component",
"decl": { "start": { "line": 14, "column": 0 }, "end": { "line": 36, "column": 1 } },
"loc": { "start": { "line": 14, "column": 0 }, "end": { "line": 36, "column": 1 } },
"line": 14
},
...
},
"f": { "0": 6, ... }
}
}
I'm not sure how to read these files, but it looks to me like there is some coverage. But when I then run
npx nyc report --all --cwd ".." --include "**/frontend/**" --nycrc-path e2e-tests/.nycrc
where .nycrc
is
{
"extends": "nyc-config-tsx",
"all": true
}
the output shows zero coverage:
-------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
Component.tsx | 0 | 0 | 0 | 0 | 15-48
... | 0 | 0 | 0 | 0 |
I suspect it has something to do with paths. Do I have to specify how the results in the json files correspond to their source files somehow?