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

Problem in basic usage #33

Open
lazywithclass opened this issue Mar 16, 2016 · 13 comments
Open

Problem in basic usage #33

lazywithclass opened this issue Mar 16, 2016 · 13 comments
Labels

Comments

@lazywithclass
Copy link

Hello, thanks a lot for this library.

I am evaluating it to see if I could use for a mutation testing library I am writing, I've setup a basic scenario to see how it works:

// source.js
var lib = {};

lib.fn = function() {
  return true;
};

module.exports = lib;

// test.js
describe('fn', function() {

  var lib = require('./source'),
      expect = require('chai').expect;

  it('returns true', function() {
    expect(lib.fn()).to.be.true;
  });

});

// runner.js
require = require('really-need');
var foo = require('./test', {
  pre: function (source, filename) {
    return source;
  }
});

When I run it it gives me an error, it's quite long, I'll paste what I think it's relevant (here the whole thing https://gist.github.com/lazywithclass/93898774a3644be63c32)

patched compile has crashed
internalModule is not defined
ReferenceError: internalModule is not defined
    at Module.eval (eval at <anonymous> (/Users/lazywithclass/workspace/mutagen/node_modules/really-need/index.js:230:25), <anonymous>:30:19)
    at Module._compile (/Users/lazywithclass/workspace/mutagen/node_modules/really-need/index.js:251:29)
    at load (/Users/lazywithclass/workspace/mutagen/node_modules/really-need/index.js:73:12)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at loadRealModule (/Users/lazywithclass/workspace/mutagen/node_modules/really-need/index.js:133:23)
    at Module.reallyNeedRequire [as require] (/Users/lazywithclass/workspace/mutagen/node_modules/really-need/index.js:181:16)
    at Object.<anonymous> (/Users/lazywithclass/workspace/mutagen/test/mutation-true-false/mutator.js:24:11)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

I am running node 4.3.1and really-need 1.9.2.

Any hint / help would be greatly appreciated.

UPDATE: Using node 4.2.2 and fake seems to solve the issue... but still I am looking at your code to understand how can I use it with newer versions.

@clutteredmind
Copy link

I am also having this problem. I'm using really-need to test my express server with mocha like this:

'use strict';

require = require('really-need');

var uuid = require('node-uuid');
var request = require('supertest');
var chai = require('chai');

chai.use(require('chai-string'));
var expect = chai.expect;

describe('base server functionality', function () {
    var server;

    beforeEach(function () {
        server = require('../app.js', { bustCache: true });
    });

    it('responds to /', function (done) {
        this.slow(2000);
        request(server).get('/').expect(200, done);
    });

    it('returns a 404 response code for invalid URLs', function (done) {
        // use node-uuid to generate a basically-random URL that will fail
        request(server).get('/' + uuid.v1()).expect(404, done);
    });
});

I'm using Node 4.4.2 if that helps at all. The error message I get is identical to the one above.

@bahmutov bahmutov added the bug label Apr 10, 2016
@bahmutov
Copy link
Owner

I think this is due to the source for require changing in Node 4.4.2 - could you try earlier Node versions please?

@clutteredmind
Copy link

Sorry this took so long. I reverted back to 4.0.0 and it seems to be working fine there. 4.4.4, 4.4.2, and 4.3.2 don't seem to work, though.

@bahmutov
Copy link
Owner

Thanks for trying different versions - yes, the node module loading code has changed and really-need fails to properly replace it. I will take a look at this when I get a chance

@m-a-r-c-e-l-i-n-o
Copy link

Same issue here. Works in 4.0.X, 4.1.X, 5.0.X, 5.1.X, seems to fail for 4.2.6+, and 5.2.X+, didn't test all patch releases and also didn't test 3.X.X-. I really need this to work soon :D — building a test runner that depends on it. What's involved with fixing this? Maybe I can lend a hand.

@bahmutov
Copy link
Owner

Seems the problem is that different versions patched the module loading system, and the way I overloaded it using eval does not match the newer ones. Which specific Node version do you need? @m-a-r-c-e-l-i-n-o

@tcrall
Copy link

tcrall commented Jun 24, 2016

Same problem with node 4.4.0. Reverting Node to 4.0.0 seems to work. I'm quite sure that I was running okay with Node 4.4.0 previously, though. Was this error introduced in a specific really-need version? Tried rolling back really-need but ended up with the shebangRe error instead.

@m-a-r-c-e-l-i-n-o
Copy link

@bahmutov It might be a bit of a tall order, but I was thinking all versions 4.0.0 and above. However, I did manage to get my use case (4.0.0+) resolved with require-hacker. I still think that really-need is more ideal do to its cache management options, but I'm okay with this shortcoming, for now.

@clutteredmind
Copy link

Hello, I just wanted to check and see if there might be a fix for this in the works. I'd very much like to be able to use really-need in my testing. Thank you very much for your time.

@fishcharlie
Copy link

@bahmutov This package even maintained anymore??? This issue was opened in March 2016 and it's been almost 2 years without a fix.

@bahmutov
Copy link
Owner

bahmutov commented Feb 25, 2018 via email

@fishcharlie
Copy link

@bahmutov If that is the case you should archive the repo on GitHub or post a note in the README that this project is no longer actively maintained.

@bahmutov
Copy link
Owner

nope, if someone submits pull requests, the issue can be solved, new version can be released, etc.

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

No branches or pull requests

6 participants