Testing guide article

This is the comment thread for the Testing article in the Meteor Guide.

Read the article: http://guide.meteor.com/testing.html

The comment thread for each article appears at the very bottom of the page. Use this thread to post:

  • Interesting articles related to the content
  • New ways to do things that aren’t covered in the Guide
  • Suggestions for Guide improvements

Or anything else related to this topic that people could find useful!

3 Likes

When running meteor test --full-app --driver=practicalmeteor:mocha, your client side DOM is inside a frame with 0px height.

That means that the jquery selector :visible is not usable anymore.

So this is not working anymore:

    chai.expect($('#foo:visible')[0]).to.not.be.undefined; // always undefined
1 Like

Yes, this is one downside of the approach of running the reporter in the same app as the “full application”. It was a tradeoff between doing this and the complexity of running multiple Meteor apps in test mode (as velocity did).

I’m hopeful that just doing existence (rather than visibility) based checks on the DOM will be enough—if you want to check visibility etc, perhaps an acceptance test using a external driver makes more sense?

1 Like

Since Gagarin is a superset of Mocha and supports external drivers like chromedriver and phantoms, we should be able to get chai.expect($('#foo:visible')[0]).to.not.be.undefined; style syntax working by combining practicalmeteor:mocha and Gagarin.

We should log tickets with both projects about incorporating the other one.

Has anyone else experienced that tests simply don’t show up in the testrunner, when hidden erros occur.

I am running my tests from within imports/modules/* and right now a lot of tests do not show up.
I am sure that I have an error somewhere in my code BUT I would still expect the testrunner to run all tests.

Anyone else having that issue?

I seperated my question into a seperate topic ``meteor test`` NOT running some tests and NOT throwing errors

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/...')
1 Like

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!

2 Likes

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

1 Like

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:

  • chimp #204: in the thread they advise updating the dev_bundle to a later release, I assume that would cause issues. They also refer to older versions of selinium, I don’t see any reference to selenium in my error output.
  • meteor #5124: Looks like node will start to get back on track sometime soon.

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 :slight_smile:! 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

@hwillson feel like sending a PR to the guide?

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!

1 Like

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.