`require('./')` broken if parent directory has file with the same name
See original GitHub issue🐛 Bug Report
Suppose you have a file dir/fn.js
that requires the current directory using const x = require('./')
, and the parent directory has a file dir.js
. In Node.js 8, x
will contain the exported value from dir/index.js
. In Jest, x
will contain the exported value from dir.js
To Reproduce
Steps to reproduce the behavior:
https://github.com/vkarpov15/jest-bug
Expected behavior
require()
in Jest should behave the same as require()
in vanilla Node.js, especially if using the Node test environment.
Link to repl or repo (highly encouraged)
https://github.com/vkarpov15/jest-bug
envinfo
$ npx envinfo --preset jest
npx: installed 1 in 1.063s
System:
OS: Linux 4.15 Ubuntu 16.04.3 LTS (Xenial Xerus)
CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
Binaries:
Node: 8.9.4 - /usr/bin/node
npm: 5.6.0 - /usr/bin/npm
npmPackages:
jest: 24.9.0 => 24.9.0
$
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
node.js - How to write file if parent folder doesn't exist?
As of Node v10, this is built into the fs.mkdir function, which we can use in combination with path.dirname: var fs = require('fs');...
Read more >Finding all files with a given extension whose base name is ...
Therefore, basename $(dirname $file) gives the parent directory of the file. $ for file in $(find . -type f); do basename $(dirname $file)...
Read more >Move and rename files based on their parent's directory
You want instead to move the file that the name variable refers to. For this use "$name" rather than name . Note the...
Read more >How to Fix the “Is its parent directory writable by the server ...
Read this article to learn how to fix "Is its parent directory writable by the server?" issue using three simple methods.
Read more >File Permissions from UNIX - NRAO Information
The permissions string is in the form of 10 characters, further broken down into four fields: File Type: - for normal file, d...
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 FreeTop 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
Top GitHub Comments
I don’t think I have the time to put in a PR. I already worked around this in Mongoose so nothing more to do on my end.
Why does Jest monkey patch require() anyway? Seems very dubious
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.