How should I test meteor apps with package architecture? - javascript

I noticed that Vulan.js (one that implements package architecture) doesn't have tests. I tried to do it on my own, by adding practicalmeteor:mocha and adding Package.onTest to package.js that is in my package
Package.onTest(function(api) {
api.use([
'myapp:package-that-i-wanna-test',
'practicalmeteor:mocha',
'practicalmeteor:chai'
])
api.addFiles('somefile.test.js', 'server');
})
And then running meteor test-packages --driver-package practicalmeteor:mocha mypackage
Is it a right solution?
I've also tried running meteor test --driver-package=practicalmeteor:mocha, but got 0 tests even though I have them in my package named as *.test.js (so, it seems that this command does not look for test files in packages folder)
So, my question is what is the proper way of testing meteor app with Vulcan.js architecture and how should I perform running all tests in Vulcan.js

Related

Different jest results when running via npm/package.json

Can anyone help me to understand that behaviour:
when I ran in terminal jest command: all my tests passed
I have also defined package.json script where I do exactly the same command jest and when i run npm run tests jest command is executed and all my tests passed.
BUT:
I run it on dockerimage. I have copy all project files to Docker, install all depend. and run tests.
npm run tests - failed
jest - passed
I am on the build docker image, in terminal run both commands. I see that they are giving different results. I know that it different OS. maybe different libraries, but npm, node and jest versions are identical.
Looks like running npm run tests behave differently. I'm stuck, don't know what to check, and how to debug it. Where the problem might be?

Meteor: using npm packages for unit testing (instead of atmosphere packages)

I want to test my meteor app. Initially I wanted to use some atmosphere package, but it turns out that a lot (almost all of them) are no longer maintained.
Is there a way to use "pure" npm packages (like mocha or jest) in meteor app.
My initial logic for this is to npm install --save-dev what I need (e.g. mocha & chai) and then add a script in package.json that would perform the testing.
You can indeed do this. The only atmosphere package you need is dispatch:mocha. This is used by the standard meteor test framework (eg when running meteor test).
Mocha itself is an npm package, and whatever others you need such as enzyme, jest etc
Have a read of the Meteor guide on testing https://guide.meteor.com/testing.html
It explains the various kinds of testing available and how to run them.

How can I use Mocha without removing Ava?

One of my co-workers added this Ava package to our setup, and it's done something I've never seen a Node package do before: interfere with other packages! Now when I try to run Mocha I get:
$ node_modules/mocha/bin/mocha test/
Test files must be run with the AVA CLI:
$ ava node_modules/mocha/bin/_mocha
I get that Ava would like to run my Mocha tests, but if I wanted that I'd run ava mocha not mocha. And because a co-worker is using it I can't simply uninstall the package.
Is there any way I can run plain Mocha tests on a machine with Ava installed?
One of the files in test/ imports ava and the imported code will recognise that it's not being run with the correct tooling and throw an error.
Might be worth subdividing your test/ directory to keep tests associated with their respective runners.
test/
ava/
SomeAvaTests.js
mocha/
SomeMochaTests.js
This way you can safely run mocha test/mocha/ and vice versa without worrying about treading on each other's toes.

Dummying an Electron session for Mocha/Chai tests

I've built a single-page app off of chentsulin's electron/react boilerplate, which comes with the following node script for testing:
"test": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 mocha --compilers js:babel-register --recursive --require ./test/setup.js test/**/*.spec.js"
The boilerplate comes with a number of generic tests that are runnable at the outset (I confirmed this myself). It also comes with a number of webpack configs to suit different environments.
The app is fairly far along now, and is using electron-json-storage to handle local storage. I just went back to writing tests, and when I run the test node script (with or without --renderer) I get the following:
[dirpath]/node_modules/electron-json-storage/lib/utils.js:30
const app = electron.app || electron.remote.app;
^
TypeError: Cannot read property 'app' of undefined
I've tried using webpack.IgnorePlugin to ignore electron-json-storage, but that doesn't do anything. My guess is that electron-json-storage is trying to refer to an instantiated electron session that doesn't exist. What's the easiest way of dummying this up?
The problem was that I was using mocha (which came as part of the Electron-React boilerplate). Installing electron-mocha and changing the test script in the package.json resolved this problem immediately.

Run and add unit tests to nodejs project

I want to run the tests related to this project on github, see folder test on https://github.com/node-opcua/node-opcua . Unfortunately I have no idea which testing framework was used and how to run all the tests?
First, run npm install
This will install the required dependencies.
You can then use
npm test
See here:
https://github.com/node-opcua/node-opcua/blob/master/package.json#L15
That will run the tests using Mocha.

Categories

Resources