tschaub / mock-fs

Configurable mock for the fs module
https://npmjs.org/package/mock-fs
Other
912 stars 86 forks source link

Windows issue with weird chars in path #118

Closed gyandeeps closed 8 years ago

gyandeeps commented 8 years ago

what i did:

        var finalMockDir = {};
        finalMockDir["eslint/fixtures"] = {'some-file.txt': 'file content here'};
        mockFs(finalMockDir, {
            createCwd: false,
            createTmp: true
        });

//somewhere else in code
// directory = "C:\Users\gs025879\AppData\Local\Temp\eslint\fixtures\config-hierarchy\broken"
fs.readdirSync(directory);

Error stack:

 Error: ENOENT, no such file or directory '\\?\C:\Users\gs025879\AppData\Local\Temp\eslint\fixtures\config-hierarchy\broken'
    at Binding.<anonymous> (C:\Users\gs025879\Documents\webstrom\eslint\node_modules\mock-fs\lib\binding.js:544:13)
    at maybeCallback (C:\Users\gs025879\Documents\webstrom\eslint\node_modules\mock-fs\lib\binding.js:41:17)
    at Binding.readdir (C:\Users\gs025879\Documents\webstrom\eslint\node_modules\mock-fs\lib\binding.js:536:10)
    at Object.fs.readdirSync (C:\Users\gs025879\Documents\webstrom\eslint\node_modules\mock-fs\node\fs-6.0.0.js:856:18)
    at getDirectoryEntries (C:\Users\gs025879\Documents\webstrom\eslint\lib\file-finder.js:28:19)
    at FileFinder.findAllInDirectoryAndParents (C:\Users\gs025879\Documents\webstrom\eslint\lib\file-finder.js:165:50)
    at Config.findLocalConfigFiles (C:\Users\gs025879\Documents\webstrom\eslint\lib\config.js:301:35)
    at Context.<anonymous> (C:\Users\gs025879\Documents\webstrom\eslint\tests\lib\config.js:226:39)
    at callFn (C:\Users\gs025879\Documents\webstrom\eslint\node_modules\mocha\lib\runnable.js:315:21)
    at Test.Runnable.run (C:\Users\gs025879\Documents\webstrom\eslint\node_modules\mocha\lib\runnable.js:308:7)
    at Runner.runTest (C:\Users\gs025879\Documents\webstrom\eslint\node_modules\mocha\lib\runner.js:422:10)
    at C:\Users\gs025879\Documents\webstrom\eslint\node_modules\mocha\lib\runner.js:533:12
    at next (C:\Users\gs025879\Documents\webstrom\eslint\node_modules\mocha\lib\runner.js:342:14)
    at C:\Users\gs025879\Documents\webstrom\eslint\node_modules\mocha\lib\runner.js:352:7
    at next (C:\Users\gs025879\Documents\webstrom\eslint\node_modules\mocha\lib\runner.js:284:14)
    at Immediate._onImmediate (C:\Users\gs025879\Documents\webstrom\eslint\node_modules\mocha\lib\runner.js:320:5)
    at tryOnImmediate (timers.js:543:15)
    at processImmediate [as _immediateCallback] (timers.js:523:5)

OS: Windows 7 Node: 6.0

TheHighriser commented 7 years ago

Why was this closed? How did you fix it? I have the exact same problem.

gyandeeps commented 7 years ago

I was trying to convert a real folder structure into a mock-fs compatible json structure so I ended up doing it like this https://gist.github.com/gyandeeps/23a4c836b54f91d9d3cfed7ab37e7a0b

tschaub commented 7 years ago

@TheHighriser can you provide an example that fails and describe what you are trying to do?

TheHighriser commented 7 years ago

@gyandeeps : Thanks for the example!

@tschaub : Basically I have set up a test via Mocha.

I tried to initialize one file by doing so:

mock({
   'C:/workspace/package.json' : 'My Content'
})

I tried to use this initialization pretty much everywhere but the error occurred anyways. (After using the module, before the test, exactly in the test, ..)

The error itself gets triggered by this function:

function checkIfFileExists(_file){
    return new Promise(function(resolve, reject){
        fs.stat(_file, function(err, stat) {
            if(err){
                reject("File not available: " + _file);
                return;
            }

            resolve(_file);
        });
    });
}

In the _file I have the same path as used above. But I also get those weird characters like above in the error message from @gyandeeps

Is there any initialization I forgot? Or is mock(filesConfig) everything I need? As It didn't work I ended up using Stubs with Sinon and overriding those methods instead of faking the file itself. I have tested with several node versions but none of them worked.

If there is anything I should add, tell me.