How to exclude `node_modules` in the testing cover...
# help
b
How to exclude
node_modules
in the testing coverage report? I tried with
sst test --coverage
showing the node_modules files also in the coverage report.
a
use
--collectCoverageFrom='!**/node_modules'
flag
b
It didn't work. Still showing the node_modules in the coverage report
a
weird, this is what I use with create-react-app. Not sure what the issue is.
b
it's showing only a few packages i.e @aws/cdk and construct. Refer the screenshot.
a
It maybe because of how the constructs are wired, let me think.
share your tsconfig.json
b
{   "compilerOptions": {     "target": "ES2018",     "module": "commonjs",     "lib": ["es2018"],     "declaration": true,     "strict": true,     "noImplicitAny": true,     "strictNullChecks": true,     "noImplicitThis": true,     "alwaysStrict": true,     "noUnusedLocals": false,     "noUnusedParameters": false,     "noImplicitReturns": true,     "noFallthroughCasesInSwitch": false,     "inlineSourceMap": true,     "inlineSources": true,     "experimentalDecorators": true,     "strictPropertyInitialization": false,     "typeRoots": ["./node_modules/@types"]   },   "include": ["lib","src"] }
Default config.
a
add a exclude: [“node_modules”]
b
Okay. Let me try.
Still, it's showing the node_modules in coverage report.
a
okay, no more ideas left. 😅
b
Ok. NP. I resolved this by including the lib and src folder 😂
a
oh yes, that would work, good workaround. 👏
j
Just wanted to chime in here. I haven’t done much with coverage reports before but should the
node_modules
be ignored automatically?
a
No, most tooling require a configuration which decides what is to be included and what is to be not.
j
Ah I see. The flag that you posted before
--collectCoverageFrom='!**/node_modules'
that works in CRA but not in SST?
If so then let me let @Frank know about it. We’ll need to create an issue for it.
a
Yep, sst test could accept that flag and pass it to jest internally.
j
We’ll create an issue for this @Frank ?
f
Should we pass all the options passed to
sst test
to jest?
a
Yes, that would be the best way to ensure minimal confusion and avoid additional documentation.
t
Started to look into this and as far as I can tell the arguments are passed through. If you run
sst test --collectCoverageFrom='!**/node_modules' --showConfig
you can see that the
"collectCoverageFrom"
field shows the expected value
j
Oh so we do support it? I wonder what @Bhuvaneshwaran Rajendran’s issue was then?
b
@Jay Even though I use collectCoverageFrom='!**/node_modules' it still covers some of the node_modules which should not happen. Please refer to the screenshot.
j
@thdxr Just bringing this up. It seems like something is amiss with our Jest configs?
t
Need to dig into this more, this doesn't happen for me. We should probably talk more about if
sst test
is adding value