UPDATE-2:. After you run into lil bit, how long it takes to run unit test this way, I decided to create a module to load models and turn them into globals just like sails do, but without taking so much. Even when you take out each hook, but the orm loader is machine-specific, it can easily take a couple of seconds WITHOUT ANY TEST !, and as models are added, it becomes slower, so I created this module called waterline-loader so you can download only the basics (about 10 times faster), the module is unstable and needs testing, but you are welcome to use it or change it to suit your needs or help me improve it here → https://github.com/Zaggen / waterline-loader
UPDATE-1: I added information related to running your tests with mocha in the docs in the Running Tests section.
Just to expand on what others have said (especially what Alberto Souza said).
You need two steps to make mocha work with sails on your own. Firstly, as indicated in the sails.js Docs , you need to raise the server before running the test, and for this you create a file called bootstrap.test.js (you can call it whatever you like) in the root path (optional) of your tests (test / bootstrap.test.js), which will be called by mocha first, and then it will call your test files.
var Sails = require('sails'), sails; before(function(done) { Sails.lift({ // configuration for testing purposes }, function(err, server) { sails = server; if (err) return done(err); // here you can load fixtures, etc. done(err, sails); }); }); after(function(done) { // here you can clear fixtures, etc. sails.lower(done); });
Now in your .json package, in the script key, add this line (Ignore comments)
// package.json .... scripts": { // Some config "test": "mocha test/bootstrap.test.js test/**/*.test.js" }, // More config
This will download the bootstrap.test.js file, raise your sails server and then run all your tests that use the testname.test.js format, you can change it to .spec.js if you prefer.
Now you can use npm test to run the test.
Note that you can do the same without changing your package.json and typing mocha test/bootstrap.test.js test/**/*.test.js on the command line
PST: For more detailed configuration of bootstrap.test.js check the Alberto Souza answer or directly check this file in the hist github registry