Skip to content
New issue

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

Mocking modules not working with whitespace in file path #1210

Closed
6 tasks done
pYr0x opened this issue Apr 29, 2022 · 10 comments · Fixed by #1457
Closed
6 tasks done

Mocking modules not working with whitespace in file path #1210

pYr0x opened this issue Apr 29, 2022 · 10 comments · Fixed by #1457
Labels
help wanted Extra attention is needed

Comments

@pYr0x
Copy link

pYr0x commented Apr 29, 2022

Describe the bug

i had trouble with mocking a module. the module will not be mocked. so i found a test on vitest test's.
https://github.com/vitest-dev/vitest/blob/main/test/core/test/hoist-import.test.ts
i tried to reproduce the test in my project and it failed. so i tried to create a stackblitz and it worked... !?
the only difference i can see is that i am working on a windows machine

Reproduction

stackblitz with working test:
https://stackblitz.com/edit/vitest-dev-vitest-ma89ey

Github Repo that i used locally on my windows 10 machine (and it failed)
https://github.com/pYr0x/vitest_mock

i used pnpm and npm. both not working for my locally

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
    Memory: 3.17 GB / 15.85 GB
  Binaries:
    Node: 14.18.1 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.15 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (100.0.1185.50)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    vite: latest => 2.9.6
    vitest: latest => 0.10.0

Used Package Manager

pnpm

Validations

@sheremet-va
Copy link
Member

Well, we also run tests on windows in our CI 🤔
@userquin can you help with this issue?

@sheremet-va sheremet-va added bug help wanted Extra attention is needed labels Apr 29, 2022
@pYr0x
Copy link
Author

pYr0x commented May 5, 2022

Hey guys, any progress with this issue?
@sheremet-va @userquin

@pYr0x
Copy link
Author

pYr0x commented May 5, 2022

@sheremet-va i found the problem.
i have a whitespace in my directoryname. my project is under:
C:/Users/xxx/Desktop/Neuer Ordner/vitest_mock/
the regex for parsing the stacktrace in

const stackFnCallRE = /at (.*) \((.+):(\d+):(\d+)\)$/
const stackBarePathRE = /at ?(.*) (.+):(\d+):(\d+)$/
does not correct match.

a stacktrace line line at C:/Users/xxx/Desktop/Neuer Ordner/vitest_mock/test/foo.test.js:3:26 will be matched into

{
  method: 'C:/Users/xxx/Desktop/Neuer',
  file: 'Ordner/vitest_mock/test/foo.test.js',
  line: 3,
  column: 26
}

i would prefer:

const stackFnCallRE = /at ([\w\.]*\s?[\$\w\.]*) \((.+):(\d+):(\d+)\)$/;
const stackBarePathRE = /at ?([\w\.]*\s?[\$\w\.]*) (.+):(\d+):(\d+)$/;

@sheremet-va
Copy link
Member

Hm, how does it affect mocking tho? Or the problem is not about mocking?

@pYr0x
Copy link
Author

pYr0x commented May 5, 2022

mocking if working correctly. the problem is the whitespace in the directory name

@pYr0x pYr0x changed the title Mocking modules not working on Windows 10 Mocking modules not working with whitespace in project folder name May 5, 2022
@pYr0x pYr0x changed the title Mocking modules not working with whitespace in project folder name Mocking modules not working with whitespace in file path May 5, 2022
@userquin
Copy link
Member

userquin commented May 5, 2022

@pYr0x I'll check it in a few minutes...

@userquin
Copy link
Member

userquin commented May 5, 2022

@sheremet-va the mocking is not working on Windows when the path has some spaces, the same project just renaming from vitest_mock_issue_1210 to vitest mock issue 1210 fails.

On project with spaces in the path, the suite mocks are just: { '../src/timeout.ts': [Function (anonymous)] } while on the project without spaces returns : { '/src/timeout.ts': [Function (anonymous)] }

Just download the ZIP from the original and rename it: the problem should be on macosx/linux.

We have something strange using latest on vitest dep, I cannot find the regex for stackFnCallRE but the version is 0.10.0.

@userquin
Copy link
Member

userquin commented May 5, 2022

it seems not working on other OS when there are spaces on the path, I talk with @sheremet-va and we're working on a fix, the importer is not being resolved correctly

@pYr0x your regex works but we'll use similar approach from here: https://www.npmjs.com/package/error-stack-parser

The last source entry will be fixed on the PR:

{
  method: '',
  file: 'F:/work/projects/quini/GitHub/issue-repro/vitest mock issue 1210/test/foo.test.ts',
  line: '3',
  column: '30',
  source: '    at F:/work/projects/quini/GitHub/issue-repro/vitest mock issue 1210/test/foo.test.ts:3:30'
}

@pYr0x
Copy link
Author

pYr0x commented Jun 9, 2022

@userquin is this bug fixed?

@sheremet-va
Copy link
Member

@userquin is this bug fixed?

Should be fixed in #1457

@github-actions github-actions bot locked and limited conversation to collaborators Jun 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants