Use jasmine-node to test meteor application with auto-test - node.js

I'm using jasmine-node to test my Meteor application and I want to use the auto-test feature so I don't have to rerun the tests all the time by myself.
My meteor application folder structure is like this:
server
foo.coffee
tests
foo.spec.coffee
And with the spec file I want to test code which is located in foo.coffee. I start jasmine-node with this args:
jasmine-node ./ --autotest --coffee --test-dir tests
And now I would assume that the autotest feature will react on all changes in the root folder but it just reacts on changes in the test folder. And I can't start it in the root folder because I get an error in the .meteor files (and I don't want to have jasmine testing/including the meteor code anyway).
So I want to have jasmine rerun the tests even if I change code in the server folder. How can I achieve that?

Use the --watch parameter along with --autotest and specify the directories that contain whatever files you want to have watched.

Related

How do I generate code coverage for some Node.JS code without tests?

I have a build/ folder that gets autogenerated by a babel process in a package.json. It has several .js files, including in sub-folders. In the root is a file, main.js, which is something of a demo / testbed for the project, that instantiates various ES6 classes and tries out various functions. It currently runs without crashing.
Call it a poor man's end-2-end test. I'm trying to move quickly with what could be throw away code.
I don't have any formal tests. I don't want to write any formal tests for this codebase. But I am interested in knowing how much of the code in build/ is being touched currently by my demo, main.js.
How can I generate a code coverage report for this scenario, using nyc?
If that's not actually easy (all tutorials I see seem to involve instrumenting pre-existing unit tests from a mainstream testing framework), what nyc alternative would make this easy?
I tried
npm install nyc --save-dev
npx nyc node build/main.js
but it claimed 0 lines/files.
With thanks to What is instrumentation in nyc istanbul?, it was actually simple. From the root, where my package.json and build/ folder were:
npx nyc instrument build coverage
npx nyc --reporter=text --report-dir=./nyc_output node build/main.js
all necessary folders (coverage, nyc_output) were auto-created (though it made .nyc_output/ for some reason)

Setup jest multi projects with create-react-app and node

My projects uses a /server folder for my backend code and /react-ui for my client side code. There's a package.json in each folder. I can run test separately in the cmd line, but I would like to run both at the same time. I know about the multi projects feature of jest, but it doesn't seem to work with create-react-app. I'm trying to setup jest with babel as if I was not using create-react-app, but it seems like the wrong approach considering jest is already setup in CRA.
My current setup runs from the /server jest installation. With projects: ['<rootDir>', '<rootDir>/../react-ui']. The jest documentation isn't clear how I could direct it to run npm test in /react-ui
My only goal is to be able to watch both at the same time and I would like to not eject from CRA.
You can have (gulp) scripts on the main level that run each tests separately, but using same configs.

Run lab test for all test subfolders

I'm refactoring one backend at my company and I'm modularizing it as much as possible. My structure can be defined as a monorepo composed of several local submodules and one or two main modules that requires them(the submodules). Let's illustrate this:
root
main
package.json
stuff that uses submoduleA
stuff that uses submoduleB
test
modules
submoduleA
package.json
code
test
submoduleB
package.json
test
As you can see, each module has it's own tests, package.json, and dependencies. Everything works flawlessly within them (running npm test inside the folder of a module, for example). I'm using lab and code for testing.
What I want is to be able to do is going to the root of the project, run npm test and run all the tests for all the submodules and the main module. Basically run all the test under any test folder in one go.
The problems that I found so far are:
- Currently only the files under the target test directory are being run. I don't even know how to run all the test at once. My command looks like lab src/main/test --reporter console --threshold 100 --assert code
What I'm doing now is putting all the test under the same test directory and make relative requirements for everything. This is very inconvenient because makes test fragile with all those ../../../some/away/path requires and that stuff.
Any advice for keeping the code modular, and being able to run all the test at once will be very welcome. Thank you very much.
I asked this a week ago on hapijs repository, so if you want to answer there too it would be fine: https://github.com/hapijs/discuss/issues/397
I would suggest making submoduleA and submoduleB stand alone node modules, then you can install and use with the main module when required. This way you are testing each part in isolation and then together which should yield the same outcome and will enable you to run tests more easier.

How to run npm tests from a single folder?

Currently I am testing a React node application, and have all my tests in the root/tests folder, with components in separate folders pertaining to their function.
I have 10+ folders and 100+ tests, and would like to 'watch' a single folder while I write a test for a new component.
Currently, I am using
npm run test:watch
Which is working brilliantly, however, not only is there a lot of overhead re-running the 100 other tests not related to my new component, it's also hard to weed through all the feedback to see the results of my current test.
Is there a nice command to only watch the directory of my new test, or even the test file?
You can pass mocha test directory to the npm command:
npm run test:watch -- root/tests/subfolder
However it might depend on how your test script test:watch is defined.

Temporary files on Travis

I have a Javascript project which uses Grunt for build process, QUnit for tests, Blanket for code coverage and a custom Grunt task to convert coverage results into LCOV files, sended to Coveralls. Everything running on TravisCI.
the project : https://github.com/mistic100/jQuery-QueryBuilder
my Grunt task : https://github.com/mistic100/grunt-qunit-blanket-lcov
So what should happen is that npm test runs QUnit+Blanket tests in a PhantomJS process and in the meanwhile, coverage results are saved in .coverage-results/all.lcov.
After a successfull build, grunt coveralls sends this file to Coveralls.
And my problem is here, the task does not find the file, although when I test on my computer it does.
see the last Travis log: https://travis-ci.org/mistic100/jQuery-QueryBuilder#L389
The only thing I can think about is that the file, for some reason, is deleted once npm test is finished. Is it possible ?
edit
so this has nothing to do with Travis but with my Grunt task where I use absolute paths thinking it's relative paths (I still don't know why it doesn't append on Windows though)
The only thing I can think about is that the file, for some reason, is deleted once npm test is finished. Is it possible ?
No, lifecycle-wise the build artefacts are still present, when running after_success commands.
The gruntfile.js configures force true and defines path - no issue here.
This should work.
I would suggest to throw in some commands to check the folders and files on Travis.
- sudo ls -alh /home/travis/build/mistic100/jQuery-QueryBuilder/*
- sudo ls -alh /home/travis/build/mistic100/jQuery-QueryBuilder/.coverage-results/*
Maybe you spot a permission issue during folder and file creation.
But that's my only guess.

Resources