This directory contains the scripts used to automate YUI's Node.js testing with TravisCI.
before.sh
- Runs in thebefore_install
build step to create the YUI npm packageinstall.sh
- Runs in theinstall
build step to do annpm install
inbuild-npm
(created from the above step)test.sh
- Runs in thetest
build step. It fetches the list of tests to execute, then executes YUITest on them.travis.sh
- Runs the travis tests locally for testing, not used in the Travis build.
There is a JSON file in this directory called tests.json
, add your relative path to it and run the
test locally. Commit and push and it will be in the next build.
Clone the repo, then:
cd yui3;
./src/common/travis/travis.sh
- Break out your tests into a separate module to load
- Ensure that your tests don't require a DOM, if they do add them to the ignore list against
Y.UA.nodejs
- If you are requiring external dependencies (files, modules) make sure the paths are changed to disk locations and not relative.
You should avoid wrapping assertions with Y.UA.nodejs
inside your tests. The recommended approach is
to use YUITest's _should
feature to ignore tests that are not applicable inside of Node.js.
var testCase = new Y.Test.Case({
name: 'My Test Case',
_should: {
ignore: {
'test that requires a DOM': Y.UA.nodejs,
'test that does not work in Node.js': Y.UA.nodejs
}
}
});
- Create a directory called
tests/cli
- Create a
run.js
in there like this:
#!/usr/bin/env node
process.chdir(__dirname);
var YUITest = require('yuitest'),
path = require('path'),
fs = require('fs'),
//This loads the path to the NPM module
dir = path.join(__dirname, '../../../../build-npm/'),
YUI = require(dir).YUI;
YUI({useSync: true }).use('test', function(Y) {
//This maps the internal YUITest to the included module
Y.Test.Runner = YUITest.TestRunner;
Y.Test.Case = YUITest.TestCase;
Y.Test.Suite = YUITest.TestSuite;
Y.Assert = YUITest.Assert;
});
YUI.add('my-nodejs-module', function(Y) {
var suite = new Y.Test.Suite('My Node.js Module');
// Insert tests here
Y.Test.Runner.add(suite);
});
Setup your HTML page as usual:
YUI({
modules: {
'my-nodejs-module': {
fullpath: './my-nodejs-module.js',
requires: [ 'test', 'oop' ]
}
}
}).use('my-nodejs-module', function(Y) {
Y.Test.Runner.run();
});
Now add the same module to your run.js
script:
#!/usr/bin/env node
process.chdir(__dirname);
var YUITest = require('yuitest'),
path = require('path'),
fs = require('fs'),
dir = path.join(__dirname, '../../../../build-npm/'),
YUI = require(dir).YUI;
YUI({useSync: true }).use('test', function(Y) {
Y.Test.Runner = YUITest.TestRunner;
Y.Test.Case = YUITest.TestCase;
Y.Test.Suite = YUITest.TestSuite;
Y.Assert = YUITest.Assert;
Y.applyConfig({
modules: {
'my-nodejs-module': {
fullpath: path.join(__dirname, '../my-nodejs-module.js'),
requires: ['test', 'oop']
}
}
});
Y.use('my-nodejs-module');
Y.Test.Runner.setName('cli tests');
});