Closed Nutriadmin closed 1 year ago
No manual Wallaby config is required for your case.
The reason it's working as described is that Jest prefers .js
files over .ts
files when processing imports, because according to your log the moduleFileExtensions
Jest setting's value is [ 'js', 'jsx', 'ts', 'tsx', 'json', 'node' ]
.
When I run jest --coverage in my terminal, I get coverage shown in my TS files with Istanbul. Seems to work fine outside of wallaby when using plain jest.
We have tried creating a sample project with default ts-jest config and jest --coverage
works the same way as in Wallaby (it reports coverage for .js
files).
Not sure why it's working differently in in your project, it may be because .js
files are created after you run Jest, or you're using some custom Jest config. Hard to tell without having a reproducible repo with all of your configs and build process.
To make Jest pick .ts
files over .js
files, you may change your <homeDir>/WebstormProjects/NutriAdmin/jest.config.js
file and move .js/.jsx
extension to the end of the moduleFileExtensions
setting:
module.exports = {
...
+ moduleFileExtensions: [ 'ts', 'tsx', 'json', 'node', 'js', 'jsx' ],
};
If you prefer not to do it and would like us to investigate and help configure Wallaby/Jest to work the same way as Jest CLI for your project, please create and share a reproducible repo with all of your configs, build process (that creates .js
files) and a dummy test importing a dummy .ts
file (where Wallaby picks us a .js
file sitting next to it instead, while jest --coverage
is working as expected).
Thanks for your quick reply and suggestion.
I've tried adding the moduleFileExtensions
property to my jest.config.ts
but it still doesn't work. Here is how it looks like at the moment:
export default {
resetMocks: false,
clearMocks: true,
testMatch: ['<rootDir>/**/*.spec.ts'],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
preset: 'ts-jest',
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'tsx', 'json', 'node', 'js', 'jsx'],
transform: {
'^.+\\.ts?$': 'ts-jest',
},
transformIgnorePatterns: ['<rootDir>/node_modules/'],
};
here is also my tsconfig in case it's useful:
{
"compilerOptions": {
"resolveJsonModule": true,
"target": "es2017" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"allowJs": false /* Allow javascript files to be compiled. */,
"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */,
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
"baseUrl": "./" /* Base directory to resolve non-absolute module names. */,
"typeRoots": [
"node_modules/@types",
"types"
] /* List of folders to include type definitions from. */,
"types": [
"node",
"jest"
] /* Type declaration files to be included in compilation. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
"inlineSourceMap": true /* Emit a single file with source maps instead of having a separate file. */,
"inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"exclude": ["index.js", "node_modules", "coverage", "public", "test"]
}
Do you have other suggestions? If not I will produce a sample repo to reproduce as advised. Should I just create a public github project and share the link?
If not I will produce a sample repo to reproduce as advised. Should I just create a public github project and share the link?
Yes, please create a sample Github repo and paste the link here.
I've fixed the problem!
As I was creating the sample Github repo I had to install npm packages. I realised that I was missing ts-node
. After adding it to my package.json
and reinstalling I now get coverage on my TS files.
I used to have ts-node
in my project in the past but I removed it at some point. Perhaps I still had files installed locally on my node_modules
folder or something.
Thanks for looking into it, we can close this now.
Issue description or question
I have a Typescript project where I need to compile my source TS files into JS files within the same directory.
When I run wallaby, the coverage green/red side menu boxes are shown for my compiled JS files, instead of the TS source files. I want coverage to be visible for TS files.
When I run
jest --coverage
in my terminal, I get coverage shown in my TS files with Istanbul. Seems to work fine outside of wallaby when using plain jest.Any idea why this is happening? Am I doing something wrong? Couldn't find a reference to this issue in the repo or documentation.
wallaby.js
I've tried automatic configuration, and also with this
wallaby.js
file:Wallaby diagnostics report
Here is my Wallaby Diagnostics report