Giter Club home page Giter Club logo

Comments (4)

 avatar commented on June 14, 2024

This is indeed a limitation of the current implementation.

I think a reasonable solution would be to make the Node.js require aware of the Meteor packages by adding them to require.cache.

E.g.

const meteorRequire = meteorInstall();
require.cache['meteor/meteor'] = meteorRequire('meteor/meteor');

from qualityfaster.

jdrucza avatar jdrucza commented on June 14, 2024

Seemed like a good suggestion except it doesn't work because the cache key is the resolved filename not the string identifying the module.
So I tried to replace require.resolve with a function that would resolve anything starting with 'meteor' to the module name and pass everything else through but it seems that require doesn't actually use require.resolve, rather they both use Function.Module._resolveFilename but I haven't yet found a way to override this... any further suggestions?

At the moment I am going to try overriding or replacing 'require' with one that uses meteorRequire directly when possible.

from qualityfaster.

 avatar commented on June 14, 2024

Another approach would be to use proxyquire in the test files:

const meteorRequire = meteorInstall();
const proxyquire = require('proxyquire');

const stubs = {
  // meteor/meteor is not available in our testing environment, so we need `'@noCallThru': true`
  '@noCallThru': true,
  'meteor/meteor': meteorRequire('meteor/meteor')
};

proxyquire('./unit_under_test', stubs);

And yet another approach maybe is to load the app files that were compiled by the Meteor build tool by removing https://github.com/xolvio/automated-testing-best-practices/blob/master/wallaby_server.js#L235-L238 and using meteorRequire in your tests.

const meteorRequire = meteorInstall();
const unitUnderTest = meteorRequire('./unit_under_test');

from qualityfaster.

jdrucza avatar jdrucza commented on June 14, 2024

Thanks for the suggestions. I ended up going with a solution that replaced the use of require for all non-relative-path require statements with a function from an imported module at the root of the app that conditionally used meteorRequire, not ideal but solved a couple of require related challenges and is a fairly easy search and replace refactor if and when possible.

This worked well until trying to execute tests that involved running code from the meteor packages (the primary goal) which resulted in: "before all" hook: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment. because the before all contained resetDatabase() from xolvio cleaner. I tried the suggestion but then the test itself reported the same fiber related issue.

Is it correct and necessary to call Meteor.bindEnvironment for every describe / it / before block and if so will this also work when running under meteor test? Am I missing something else, like is there a way/need to tell wallaby to use the dispatch:mocha-phantomjs installation rather than its own mocha?

from qualityfaster.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.