Comments (4)
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.
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.
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.
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)
- Custom jasmine
- Project does not run HOT 1
- Build failure on Circle CI.
- good article about testing global meteor state (methods, onCreated, helpers)
- Why is Lodash required? HOT 1
- Absolute include paths do not work HOT 4
- wallaby on server cannot understand meteor style es6 imports HOT 2
- Attempting to import from src/node_modules directory doesn't work
- Can't import { Meteor } from 'meteor/meteor'. HOT 2
- update README to reflect that Meteor 1.3 has been released
- are you leaving meteor? HOT 2
- Chrome or firefox can't find selenium on second time run HOT 7
- why mocha and not jasmine, in the dev branch? HOT 2
- Change phantomjs reference to phantom-prebuilt HOT 1
- nested imports HOT 2
- Linting issues HOT 1
- wallaby.js with meteor 1.5 HOT 3
- Meteor 1.5 problem with duplicated method and collection names
- wallaby.js with meteor 1.6 HOT 4
- update circle.yml to show v2 example
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qualityfaster.