We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Importing from absolute paths in test files throws "Cannot find module" error.
Currently this test code:
import { render } from '@redwoodjs/testing' import HomePage from './HomePage' import data from 'src/model/data' // <-- here describe('HomePage', () => { it('renders successfully', () => { expect(() => { render(<HomePage />) }).not.toThrow() }) it('reads data', () => { expect(data).toBe(3) }) })
throws error:
Changing it to relative path (import data from '../../model/data') works fine.
import data from '../../model/data'
As redwood supports src path alias out of the box, it seems natural to expect the same for test codes as well.
src
I got it working by adding moduleNameMapper configuration to web/config/jest.config.js: (from jest configuration#moduleNameMapper)
moduleNameMapper
web/config/jest.config.js
config.moduleNameMapper = config.moduleNameMapper || {} config.moduleNameMapper['src/(.*)'] = '<rootDir>/src/$1'
Since like jest.createConfig.ts is already using moduleNameMapper heavily,
jest.createConfig.ts
redwood/packages/core/src/configs/browser/jest.createConfig.ts
Lines 20 to 47 in f0b2ac5
I think it would be plausible to add src alias too.
The text was updated successfully, but these errors were encountered:
Weird, this should be handled by babel - which jest should be using
Sorry, something went wrong.
yarn rw test web
@dac09 fixed this in a recent release (perhaps the last one even):
No branches or pull requests
Importing from absolute paths in test files throws "Cannot find module" error.
Currently this test code:
throws error:
Changing it to relative path (
import data from '../../model/data'
) works fine.As redwood supports
src
path alias out of the box, it seems natural to expect the same for test codes as well.I got it working by adding
moduleNameMapper
configuration toweb/config/jest.config.js
:(from jest configuration#moduleNameMapper)
Since like
jest.createConfig.ts
is already usingmoduleNameMapper
heavily,redwood/packages/core/src/configs/browser/jest.createConfig.ts
Lines 20 to 47 in f0b2ac5
I think it would be plausible to add
src
alias too.The text was updated successfully, but these errors were encountered: