I am new to jest and am trying to implement unit tests in a sharepoint framework solution. I am using ts-jest to process my typescript files and am currently struggling to get a self built package to get transpiled.
Whenever ts-jest hits the following javascript file
export * from "./common";
export * from "./services";
export * from "./models";
export * from "./controls";
which is the entrypoint of my package, it throws the following error:
ts-jest[ts-compiler] (WARN) Unable to process '[path to file]', falling back to original file content. You can also configure Jest config option `transformIgnorePatterns` to ignore [path to file] from transformation or make sure that `outDir` in your tsconfig is neither `''` or `'.'`
To try and make it work i have the following jest config:
const { createJsWithTsPreset } = require('ts-jest')
module.exports = {
preset: 'ts-jest/presets/js-with-ts',
testEnvironment: 'node',
transformIgnorePatterns: ["node_modules/(?!(project-room-base))"],
verbose: true,
transform: {
...createJsWithTsPreset().transform,
},
};
This is my ts config:
{
"extends": "./node_modules/@microsoft/rush-stack-compiler-4.7/includes/tsconfig-web.json",
"compilerOptions": {
"target": "es5",
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"jsx": "react",
"declaration": true,
"sourceMap": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"outDir": "lib",
"inlineSources": false,
"strictNullChecks": false,
"noImplicitAny": true,
"useDefineForClassFields": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"typeRoots": ["./node_modules/@types", "./node_modules/@microsoft"],
"types": ["webpack-env", "node", "jest"],
"lib": ["es5", "dom", "es2015.collection", "es2015.promise"]
},
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.spec.ts"]
}
I’ve also tried to have the package be already transpiled to commonJS which makes jest be able to understand some of the files but then throws errors as soon as any of the dependencies of the package are being called with the same issue of being unable to process them.
Ludie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.