jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.27k stars 6.46k forks source link

upath module not working properly inside jest #9360

Closed vajahath closed 2 years ago

vajahath commented 4 years ago

🐛 Bug Report

In Windows, upath module behaves differently with node and jest. When using node, path separator is / and for jest it is \.

To Reproduce

test.spec.js

const p = require('upath');

console.log(
  p.normalize('C:\\Users\\hivaj\\AppData\\Local\\Temp\\1577863552245')
);

test.todo('todo');

With jest:

jest e2e.spec.js

results in:

 PASS  tests/e2e.spec.js
  ✎ todo todo

  console.log tests/e2e.spec.js:3
    C:\Users\hivaj\AppData\Local\Temp\1577863552245

with node (with commented test.todo('todo'); line)

node .\tests\e2e.spec.js
C:/Users/hivaj/AppData/Local/Temp/1577863552245

Closer look:

node: C:/Users/hivaj/AppData/Local/Temp/1577863552245 (correct)
jest: C:\Users\hivaj\AppData\Local\Temp\1577863552245

Expected behavior

A module should display same behavior with node and jest in the same platform.

envinfo

  System:
    OS: Windows 10 10.0.18363
    CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
  Binaries:
    Node: 13.3.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.13.1 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^24.9.0 => 24.9.0
jeysal commented 4 years ago

Confirmed - also does not require Windows for testing, since upath does not actually do any conditionals based on the platform, I tested on Linux. However, the fact that it doesn't do any such things is also why I don't spontaneously have an idea how the Jest environment could be causing this :/ One interesting observation is that upath.normalizeSafe, unlike upath.normalize, does the toUnix correctly both in and outside of Jest.

mmeij commented 4 years ago

Just ran into this issue. It essentially comes down to e.g. require('path').resolve instanceof Function returning false in Jest context, preventing upath from reimplementing the path functions (see upath.coffee#L21). I guess that makes this issue a duplicate of #2549.

jeysal commented 4 years ago

Ahh. yay it's that one again 🙈

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] commented 2 years ago

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] commented 2 years ago

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.