Hi, I am trying to add Unit tests to my project, but I am having trouble integrating the tests with typescript. I set up a fresh project with lng create
to try to pinpoint the issue. Any help would be appreciated.
This is the error I see when I try to run the tests.
This is what I have in my package.json:
{
...
"dependencies": {
"@lightningjs/sdk": "^5.2.0"
},
"devDependencies": {
"@babel/core": "^7.20.5",
"@babel/plugin-transform-modules-commonjs": "^7.19.6",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@types/jest": "^29.2.4",
"babel-jest": "^29.3.1",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"jest-webgl-canvas-mock": "^0.2.3",
"ts-jest": "^29.0.3",
"typescript": "^4.7.4"
}
}
babel.config.js:
module.exports = {
presets: [['@babel/preset-env', {targets: {node: 'current'}}], '@babel/preset-typescript'],
env: {
test: {
plugins: [
'@babel/plugin-transform-modules-commonjs',
]
}
}
};
tsconfig.json
{
"compilerOptions": {
"outDir": "build-ts",
"target": "ES2019",
"lib": ["ES2019", "DOM"],
"moduleResolution": "node",
"strict": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"module": "commonjs",
"esModuleInterop": true,
}
}
jest.config.js
module.exports = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
resources: 'usable',
},
setupFiles: ['jest-webgl-canvas-mock'],
moduleNameMapper: {
'^src(.*)': '<rootDir>/src$1',
'^test(.*)': '<rootDir>/test$1',
},
preset: 'ts-jest',
transform: {
'^.+\\.(ts|tsx)?$': 'ts-jest',
'^.+\\.[m|t]?js$': 'babel-jest',
},
transformIgnorePatterns: [],
};
App.test.js is copied straight from the docs. Thanks!