imports not working when done through tests
See original GitHub issueReproduce
Install fresh RW 0.14
yarn rw g page post
yarn rw g layout post
Modify PostPage to include PostLayout, and wrap everything in the layout
import { Link } from '@redwoodjs/router'
import PostLayout from 'src/layouts/PostLayout'
const PostPage = () => {
return (
<PostLayout>
<h1>PostPage</h1>
<p>Find me in "./web/src/pages/PostPage/PostPage.js"</p>
<p>
My default route is named "post", link to me with `
<Link to="post">routes.post()</Link>`
</p>
</PostLayout>
)
}
export default PostPage
Run all tests with yarn rw test
Expected
All tests pass
Actual
FAIL web web/src/pages/PostPage/PostPage.test.js
● Test suite failed to run
Cannot find module '../../../../src/layouts/PostLayout' from 'src/pages/PostPage/PostPage.js'
Require stack:
src/pages/PostPage/PostPage.js
src/pages/PostPage/PostPage.test.js
1 | import { Link } from '@redwoodjs/router'
> 2 | import PostLayout from 'src/layouts/PostLayout'
| ^
3 |
4 | const PostPage = () => {
5 | return (
at Resolver.resolveModule (../node_modules/jest-resolve/build/index.js:308:11)
at Object.<anonymous> (src/pages/PostPage/PostPage.js:2:1)
PASS web web/src/layouts/PostLayout/PostLayout.test.js (11.293 s)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 13.451 s
Ran all test suites.
Note
I need #869 first, before I can actually get this far.
Actually running the app with yarn rw dev works fine. No problems with the imports
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (14 by maintainers)
Top Results From Across the Web
Unit Testing Python; Imports breaking - Stack Overflow
Running the test I find I have problems with the imports in the main class. To resolve I have to change the imports...
Read more >[BUG] Unable to import module in test [ERR_REQUIRE_ESM]
A test with some imports and global setup. The doc won't help because it uses global setup, imports doesn't work due to the...
Read more >Good Integration Practices — pytest documentation
In prepend and append import-modes, if pytest finds a "a/b/test_module.py" test file while recursing into the filesystem it determines the import name as ......
Read more >Problems regarding test and module imports - Julia Discourse
Hello, I'm having some trouble structuring my project so that i can easily run tests. Right now I have the following structure: Project/...
Read more >Traps for the Unwary in Python's Import System
I'm cross-referencing packages that all reside under 'project' and I hit a problem with an internal import that's using explicit relative imports (i.e....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Didn’t have anything up on Github, so I just now created a new project and pushed that https://github.com/Tobbe/v14
<TestPage>has a relative import of<TestLayout>that doesn’t work when runningyarn rw testIt looks like jest is incorrectly determining the
srcalias frombabel-plugin-module-resolver; I think we might need to do something like this: https://www.robinwieruch.de/babel-module-resolver-jest