-
Notifications
You must be signed in to change notification settings - Fork 0
Testing with npm
This article shows how to get three.js into a node.js environment so that you can execute automated tests. Tests can be run on the command line, or by automated CI tools like Travis.
If you're comfortable with node and npm,
-
$ npm install three --save-dev, and - Add
var THREE = require('three');to your test.
If you're not familiar with these tools, here's a quick guide.
-
Install npm and nodejs. The shortest path typically looks something like
$ sudo apt-get install -y npm nodejs-legacy # fix any problems with SSL in the default registry URL $ npm config set registry http://registry.npmjs.org/ -
Make a new project directory,
$ mkdir test-example; cd test-example -
Ask npm to create a new project file for you:
$ npm initand accept all defaults by hitting Enter on all the prompts. This will createpackage.json. -
Try and start the test feature with
$ npm test. This will fail, which is expected. If you look in thepackage.json, the definition of the test script is"test": "echo \"Error: no test specified\" && exit 1"
We're going to use mocha.
-
Install mocha with
$ npm install mocha --save-dev. Notice thatnode_modules/is created and your dependencies appear in there. Also notice that yourpackage.jsonhas been updated: the propertydevDependenciesis added and updated by the use of--save-dev. -
Edit
package.jsonto use mocha for testing. When test is invoked, we just want to run mocha and specify a verbose reporter. By default this will run anything intest/."test": "mocha --reporter list" -
Rerun the test with
$ npm test. This should now succeed, reporting0 passing (1ms)or similar.