I'm using vanilla javascript in a project with Rollup. I'm using and I had installed Jest for first time, and after doing some research on my problem, I have a basic setup:
// jest.config.js
module.exports = {
coverageDirectory: 'coverage',
moduleFileExtensions: ['js'],
moduleNameMapper: {
'^applicationRoot/(.*)$': '<rootDir>/src/$1',
},
};
I am using the rollup-plugin-alias library and this is an example from my rollup.config.js
// rollup.config.js
// ...
alias({
resolve: ['.js'],
applicationRoot: __dirname + '/src',
entries: [
{
find: 'global/http',
replacement: `${__dirname}/src/global/http/index.js`,
},
]})
All classes in my library reside in the ./src directory. If in my input file (./src/index.js) I have the following lines:
// ./src/index.js
import Http from 'global/http';
export class MyClass {
}
In my test file I have:
// ./src/index.spec.js
import { MyClass } from './index';
In the terminal I get the following error:
● Test suite failed to run
Cannot find module 'global/http' from 'src/index.js'
Require stack:
src/index.js
src/index.spec.js
> 1 | import Http from 'global/http';
What else should i do? Thanks for any help or comment.
[Edited]
I have created a dummy repository with a structure similar to that described above:
https://github.com/luenmuvel/dummy-project-rollup-jest-issues
In this case all they have to do is clone the project and run "npm i" or "yarn".
In the browser it does work: You just have to run:
- "npm run build" or "yarn build"
- see the output in the browser terminal.
Running jest doesn't work. You just have to run: - "npm run t" or "yarn t" - Wait for the output.