diff --git a/.travis.yml b/.travis.yml index 0391af3b..aeab0700 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,14 @@ node_js: git: depth: 1 +matrix: + include: + - node_js: '0.10' + env: TEST_VERSION=compat + - node_js: '0.12' + env: TEST_VERSION=compat + - node_js: '4' + env: TEST_VERSION=compat #matrix: #fast_finish: true #allow_failures: diff --git a/Readme.md b/Readme.md index 74e2e898..80555d7a 100644 --- a/Readme.md +++ b/Readme.md @@ -422,6 +422,17 @@ To see the output from all of Socket.IO's debugging scopes you can use: DEBUG=socket.io* node myapp ``` +## Testing + +``` +npm test +``` +This runs the `gulp` task `test`. By default the test will be run with the source code in `lib` directory. + +Set the environmental variable `TEST_VERSION` to `compat` to test the transpiled es5-compat version of the code. + +The `gulp` task `test` will always transpile the source code into es5 and export to `dist` first before running the test. + ## License MIT diff --git a/gulpfile.js b/gulpfile.js index c0788c8d..c3734898 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -22,14 +22,15 @@ gulp.task('clean', function () { return del([TRANSPILE_DEST_DIR]); }) -gulp.task('test', function(){ +gulp.task('test', ['transpile'], function(){ return gulp.src('test/socket.io.js', {read: false}) .pipe(mocha({ slow: 200, - reporter: 'dot', + reporter: 'spec', bail: true })) - .once('error', function () { + .once('error', function (err) { + console.error(err.stack); process.exit(1); }) .once('end', function () { @@ -37,6 +38,12 @@ gulp.task('test', function(){ }); }); +gulp.task('set-compat-node-env', function() { + process.env.TEST_VERSION = 'compat'; +}); + +gulp.task('test-compat', ['set-compat-node-env', 'test']); + gulp.task('istanbul-pre-test', function () { return gulp.src(['lib/**/*.js']) // Covering files @@ -51,7 +58,8 @@ gulp.task('test-cov', ['istanbul-pre-test'], function(){ reporter: 'dot' })) .pipe(istanbul.writeReports()) - .once('error', function (){ + .once('error', function (err){ + console.error(err.stack); process.exit(1); }) .once('end', function (){ diff --git a/test/socket.io.js b/test/socket.io.js index eb1a8308..e9864746 100644 --- a/test/socket.io.js +++ b/test/socket.io.js @@ -1,6 +1,12 @@ - +var testVersion = process.env.TEST_VERSION; var http = require('http').Server; -var io = require('..'); +var io; +if (testVersion === 'compat') { + console.log('testing compat version'); + io = require('../dist'); +} else { + io = require('../lib'); +} var fs = require('fs'); var join = require('path').join; var exec = require('child_process').exec; @@ -426,9 +432,18 @@ describe('socket.io', function(){ }); describe('namespaces', function(){ - var Socket = require('../lib/socket'); - var Namespace = require('../lib/namespace'); - + var Socket; + if (testVersion === 'compat') { + Socket = require('../dist/socket'); + } else { + Socket = require('../lib/socket'); + } + var Namespace; + if (testVersion === 'compat') { + Namespace = require('../dist/namespace'); + } else { + Namespace = require('../lib/namespace'); + } it('should be accessible through .sockets', function(){ var sio = io(); expect(sio.sockets).to.be.a(Namespace); @@ -651,7 +666,7 @@ describe('socket.io', function(){ var clientSocket2 = client(srv); sio.on('connection', function() { connections++; - if(connections === 2) { + if (connections === 2) { done(); } }); @@ -2036,7 +2051,12 @@ describe('socket.io', function(){ }); describe('middleware', function(done){ - var Socket = require('../lib/socket'); + var Socket; + if (testVersion === 'compat') { + Socket = require('../dist/socket'); + } else { + Socket = require('../lib/socket'); + } it('should call functions', function(done){ var srv = http();