Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Weird stuff (unmocking might be broken) with Node.js 8 #24

Closed
mightyiam opened this issue Sep 29, 2017 · 12 comments
Closed

Weird stuff (unmocking might be broken) with Node.js 8 #24

mightyiam opened this issue Sep 29, 2017 · 12 comments

Comments

@mightyiam
Copy link
Contributor

My reproduction code is here.

Here is a screencast of me debugging the issue. I hope you enjoy it rather than swear at me for it.

So am I using it wrong or what?

@zakgrant
Copy link

I too am finding that with node 8 the mocks are not being reset on calling stop / stopAll

@boblauer
Copy link
Owner

@zakgrant Node 8 or 8.5? I'm seeing a big difference between how require works internally from 8 to 8.5.

@zakgrant
Copy link

@boblauer yeah I am using node 8.5

@alexpchin
Copy link

I've got a similar issue... but I don't think it's with my version of node. I have something going on where some of the files stop mocking and some don't?

I use setup my mocks in a spec_helper file that gets loaded before running my express app, like so:

mock('../../lib/docusign', '../../libmocks/docusign_mock');

and then in the test for the that specific lib file, I do:

  before(() => {
    mock.stop('../../lib/docusign');
    docusign = require('../../lib/docusign');
  });

  after(() => {
    mock('../../lib/docusign', '../../libmocks/docusign_mock');
  });

With the goal of mocking with fixtures for everything apart from testing the file itself.
It seems to work with some of the lib files but not others?

@robertmain
Copy link

Not sure if it's related or not, but I'm finding that it's not catching module import statements if I import * as fs from 'fs'. Is it supposed to work with import as well?

@boblauer
Copy link
Owner

@alexpchin I think you're right that that is unrelated. Do you mind opening a new issue, with possibly a sample project that reproduces the issue?

@robertmain It does not work with native import statements. If your code is being transpiled by babel, for example, then it should work, because those import statements actually get converted to require statements. However, it's a bit more complex than that.

I would recommend you take a look at https://babeljs.io/repl/#?babili=false&browsers=&build=&builtIns=false&code_lz=Q&debug=false&circleciRepo=&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&targets=&version=6.26.0 to see what your code is actually being converted to, I suspect the issue might be in the conversion itself.

@robertmain
Copy link

Well my code is TypeScript so, it is running through a transpiler(just not Babel). However it seems not to be working with that.

@bobbyg603
Copy link

I'm also having this issue in node 8.5 :/. Anyone have a workaround?

@robertmain
Copy link

@bobbyg603 I ended up using a different package(mock-fs) instead`

@mightyiam
Copy link
Contributor Author

This is still an issue with latest version, 3.0.1.
https://travis-ci.org/mightyiam/mock-path-with-simple-spy/jobs/328199961#L1872

@mightyiam
Copy link
Contributor Author

Still an issue. See failing CI here:
mightyiam/mock-path-with-simple-spy#29

@patrick99e99
Copy link

Still an issue for me as well...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants