Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
C:UsersKranthiKumarDocumentsGitHubAltiushub-App-Backend-Testsaltius-nxnode_modulesloadtestindex.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import {loadTest} from './lib/loadtest.js'
Facing issue while running Jest test cases
given all my files with nx work space
i created 2 apps for loadtest and normal api test:
Facing issue while running Jest test cases
given all my files with nx work space
i created 2 apps for loadtest and normal api test:
jest.config.ts:
/* eslint-disable */
const esModules = ['loadtest'];
export default {
displayName: 'load-test',
preset: '../../jest.preset.js',
testEnvironment: 'node',
// moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/load-test',
extensionsToTreatAsEsm: ['.ts'],
globals: {
useESM: true,
tsconfig: '<rootDir>/tsconfig.spec.json',
},
moduleFileExtensions:
['ts', 'html', 'js', 'json', 'mjs'],
moduleNameMapper: {
'^(\.{1,2}/.*)\.js$': '$1',
},
transform: {
'^.+\.(ts|js)$': 'ts-jest',
},
transformIgnorePatterns: [
`C:/Users/KranthiKumar/Documents/GitHub/Altiushub-App-Backend-Tests/altius-nx/node_modules/(?!.*\.mjs$|${esModules.join('|')})`,
]
};
tsconfig.app.json:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["node"]
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"],
}
tsconfig.json:
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"esModuleInterop": true,
}
}
tsconfig.spec.ts:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
this is nx workspace and folder structure is like :
enter image description here — folder struct
Pleaase help me resolve this is nx workspace
kranthi kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.