question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`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 

$ 

Re: https://github.com/Automattic/mongoose/issues/8053

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
vkarpov15commented, Sep 4, 2019

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

0reactions
github-actions[bot]commented, May 11, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found