Karma Server Side
Ever wanted to interact with the host system when running karma tests? This module allows the tests running in your browser to do things on the server-side, that is, in node. This means you can run API or DB setup code from your tests inside karma.
Also, when you change your server-side files, they'll be reloaded on the next test run. No need to reload karma!
npm install karma-server-side
karma.conf.js to look like this, add
server-side to the
In your tests (in the browser):
var server = ;server;
run returns a promise which completes when the function has executed on the server.
You can require modules on the server side by using
require. Note that if you use
require and browserify, then browserify will try to resolve those modules and bundle them into the test code in the browser.
require requires files relative to the current working directory of karma, not from the current test file.
If you return a promise from the function passed to
run() will wait for it to complete.
You can pass arguments to the function:
this inside the function can be used to store values between calls to
karma-server-side uses debug so you can see debug information by running karma with a
DEBUG=karma-server-side karma start