When in need to conditionally import via a require, p.e. in a test-file for a collection, you can do something like:
if (Meteor.isServer) {
// deconstruct
const { ObjectName1, functionName } = require('/imports/usecase/server/...')
When in need to conditionally import via a require, p.e. in a test-file for a collection, you can do something like:
if (Meteor.isServer) {
// deconstruct
const { ObjectName1, functionName } = require('/imports/usecase/server/...')
When running Acceptance Tests using Chimp and Mocha (as described in the guide), how do you load a supporting js file?
For example, I have a user and login function defined in /tests/setup.js that I’d like to use in many of my Chimp test files.
The Chimp docs seem to support doing this with Jasmine, but not Mocha from what I can see.
Any tips on how to make it work?
While happily using the mocha / chai guidance above, I was using the official chai documentation for guidance on supported asserts. So, I wrote some code using isAtLeast. I was very surprised to eventually figure out that the version of chai in practicalmeteor:mocha hasn’t been updated since the middle of last year and doesn’t support isAtLeast.
So, in keeping with new meteor 1.3 guidance, I’m happy to report that simply running meteor npm install chai
, adding import { assert } from 'chai';
in the test file and removing the import for practicalmeteor:chai solved my problem!
Hopefully, we’ll see many of these modules that are simple wrappers around well-maintained npm modules rapidly disappearing over the next few weeks!
As testing and debug go hand-in-hand, perhaps the debug-port option to the meteor test command should be mentioned in this guide. Could be sleep deprivation, but it took me way too long to figure out that the server-side debugging I normally do using ‘meteor debug’ is available via the debug-port option when testing.
meteor test --debug-port 5858 --driver-package practicalmeteor:mocha
Hello,
I attempted to install chimp per instructions: meteor npm install --global chimp
. This install appears to fail for me because chimp has dependencies that require updated versions of node. Am I correct in assuming that chimp is not usable until this is resolved?
I have a 5.11 version of node on my machine and chimp can install in there. I have never used chimp before and I am not really clear on how it works. But I assume that it needs to be installed in the meteor version of node and I cannot use chimp installed in my version of node?
Related issues:
Environment:
Windows 10
Meteor v1.3.2.4
Error output:
npm WARN engine deep-extend@0.4.1: wanted: {"node":">=0.12.0","iojs":">=1.0.0"} (current: {"node":"0.10.43","npm":"2.14.22"})
npm WARN engine webdriverio@4.0.5: wanted: {"node":">= 0.12.0"} (current: {"node":"0.10.43","npm":"2.14.22"})
npm WARN optional dep failed, continuing fsevents@0.3.8
npm WARN engine is-buffer@1.1.3: wanted: {"node":">=0.12"} (current: {"node":"0.10.43","npm":"2.14.22"})
npm WARN deprecated graceful-fs@3.0.8: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possible.
npm WARN deprecated jade@0.26.3: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated graceful-fs@2.0.3: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possible.
\
\> fibers@1.0.10 install C:\Users\admin\AppData\Local\.meteor\packages\meteor-tool\1.3.2_4\mt-os.windows.x86_32\dev_bundle\bin\node_modules\chimp\node_modules\fibers
\> node build.js || nodejs build.js
C:\Users\admin\AppData\Local\.meteor\packages\meteor-tool\1.3.2_4\mt-os.windows.x86_32\dev_bundle\bin\node_modules\chimp\node_modules\fibers>if not defined npm_config_node_gyp (node "C:\Users\admin\AppData\Local\.meteor\packages\meteor-tool\1.3.2_4\mt-os.windows.x86_32\dev_bundle\lib\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild --release ) else (node "" rebuild --release )
gyp ERR! configure error
gyp ERR! stack Error: Command failed: ImportError: No module named site
gyp ERR! stack
gyp ERR! stack at ChildProcess.exithandler (child_process.js:658:15)
gyp ERR! stack at ChildProcess.emit (events.js:98:17)
gyp ERR! stack at maybeClose (child_process.js:766:16)
gyp ERR! stack at Socket.<anonymous> (child_process.js:979:11)
gyp ERR! stack at Socket.emit (events.js:95:17)
gyp ERR! stack at Pipe.close (net.js:466:12)
gyp ERR! System Windows_NT 10.0.10240
gyp ERR! command "node" "C:\\Users\\admin\\AppData\\Local\\.meteor\\packages\\meteor-tool\\1.3.2_4\\mt-os.windows.x86_32\\dev_bundle\\lib\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--release"
gyp ERR! cwd C:\Users\admin\AppData\Local\.meteor\packages\meteor-tool\1.3.2_4\mt-os.windows.x86_32\dev_bundle\bin\node_modules\chimp\node_modules\fibers
gyp ERR! node -v v0.10.43
gyp ERR! node-gyp -v v3.3.0
gyp ERR! not ok
Build failed
'nodejs' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Windows_NT 10.0.10240
npm ERR! argv "C:\\Users\\admin\\AppData\\Local\\.meteor\\packages\\meteor-tool\\1.3.2_4\\mt-os.windows.x86_32\\dev_bundle\\bin\\\\node.exe" "C:\\Users\\admin\\AppData\\Local\\.meteor\\packages\\meteor-tool\\1.3.2_4\\mt-os.windows.x86_32\\dev_bundle\\lib\\node_modules\\npm\\bin\\npm-cli.js" "install" "--global" "chimp"
npm ERR! node v0.10.43
npm ERR! npm v2.14.22
npm ERR! code ELIFECYCLE
npm ERR! fibers@1.0.10 install: `node build.js || nodejs build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fibers@1.0.10 install script 'node build.js || nodejs build.js'.
npm ERR! This is most likely a problem with the fibers package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node build.js || nodejs build.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs fibers
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls fibers
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! e:\MERIS\npm-debug.log
I don’t believe this is the case. I think you could happily install chimp with whatever version of node/npm.
I just noticed the use of arrow functions with describe and it in the guide. This is discouraged by mocha in calling these functions. See https://mochajs.org/#arrow-functions.
Thanks @tmeasday! I have chimp working fine against my running meteor instance. And I am starting to understand what chimp does ! I am pretty new to all of the web development and trying to assemble all the pieces has been challenging (in a good way).
I think the documentation should change from:
meteor npm install --global chimp
to:
npm install -g chimp
assuming there is a valid instance of node installed chimp works fine as you noted.
I answered my own noob question! Darn noobness.
In the Mocking the database section, it says todo app has an internal package stub-collection.
It looks like they just changed to hwillson:stub-collections (right now package is 2 days old, and the change on meteor/todo 23hrs old).
Since I’ve lost some time to figure it out, I decided to drop a note, if not as a reminder to update the guides, at least some guidance for those searching for stub-collections while the guide is outdated.
PS: The Todo also change the import style and some of the api:
https://atmospherejs.com/hwillson/stub-collections
Sure thing, I’m on it.
The API itself hasn’t changed (the same StubCollections functions are available), but the package has been updated to leverage ES2015 support (no more globals). If you notice any issues @fabs definitely let me know here. Thanks!
Sorry, I was not that precise. I think the code sample need some minor changes since the package is now out of the todo, and imported in a different way.
without the deconstruction and with the correct package name:
import StubCollections from 'meteor/hwillson:stub-collections';
instead of :
import { StubCollections } from 'meteor/stub-collections';
Also, I got a little confused with the .add() and .stub() [that made me think the API changed], so maybe it could read StubCollections.stub([Todos]) so I know I can pass a list of collections to be stubbed, or even:
StubCollections.add([Todos]); StubCollections.stub();
I’m having same issue.
It’s true one can install chimp in whatever version of node.js, but chimp cannot be executed from meteor (for node version incompatibility mentioned above). That is, the command from the testing guide:
meteor npm run chimp-watch
cannot work because it uses meteor’s node which is (for what I know) 0.10, far behind chimp’s requirement (4+).
I’m resolving installing chimp with plain npm, as stated here, then running chimp from the command line, for example:
chimp --jasmine --path=tests
For me, the current testing guide is not working without these changes.
Would love to see a PR to the testing guide to fix this!
That’s exactly the reason why I held off doing chimp testing on my boilerplate code.
Let’s say I’m writing a unit test for a Blaze component based on the section A Simple Unit Test in the guide, using the withRenderedTemplate()
helper from the test-helpers.js
provided in that section.
Let’s also say my component has some internal state that I want to write an assertion against (the example test only shows how to write assertions against the rendered DOM result).
In other words, I’m trying to get a hold of the component’s state (or at least its Template
instance) from the callback inside the withRenderedTemplate()
helper.
I tried multiple different ways, including passing a callback that is called (using this.autorun()
) whenever the internal state that I want to observe has changed.
For the sake of staying close to the example, let’s imagine I want to write a test in which I assert that onEditingChange()
is actually called. So I want to trigger the 'focus
event on the <input>
and then ensure the callback is called.
How would I accomplish that?
EDIT: Here’s some code for what I am trying to accomplish:
it('calls onEditingChange when input is focused', function (done) {
const todo = Factory.build('todo');
const data = {
todo,
editing: true,
onEditingChange: (state) => {
// ensure `onEditingChange` is called
chai.assert.equal(state, true);
done();
},
};
withRenderedTemplate('Todos_item', data, el => {
// find input and place focus on it
$(el).find('input[type=text]').focus();
});
});
And the result:
That looks conceptually pretty good. It’s not clear to me what’s going wrong. Is the callback ever called? Does this line of code run when you do $(..).focus()
?
I cannot run tests in CircleCI because the package dispatch:mocha-phantomjs
recommended in the guide is throwingerrors when I try to run them:
? MochaRunner.runServerTests: Starting server side tests with run id Q67uyntpZBJ4izAkC
I20160603-00:03:15.383(2)? ClientServerReporter.constructor: Missing reporter to run tests. Use MochaRunner.setReporter(reporter) to set one.
I20160603-00:03:15.383(2)?
I20160603-00:03:15.383(2)? phantomjs://code/phantomjsScript.js:15 in onError
I20160603-00:03:15.384(2)? http://localhost:3000/packages/dispatch_mocha-phantomjs.js?hash=019974c286d86870150433903c12317cf464f435: 258
I20160603-00:03:15.384(2)?
I20160603-00:03:15.384(2)? phantomjs://code/phantomjsScript.js:17
I20160603-00:03:15.529(2)? All client and server tests finished!
I’ve seen that there are some tickets in github, but I want to ask: Has anybody solved that?
I also get this error when removing practicalmeteor:mocha
meteor test --once --driver-package dispatch:mocha-phantomjs returned exit code 130