Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joakimbeng committed Mar 9, 2014
1 parent 98c6be1 commit eeecc29
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/slush.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function getGenerator (name) {
}

function getAllGenerators () {
return findGenerators(require.main.paths);
return findGenerators(process.env.NODE_ENV === 'test' ? [path.join(__dirname, '..', 'test')] : require.main.paths);
}

function findGenerators (searchpaths) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"mkdirp": "^0.3.5"
},
"scripts": {
"test": "node gulpfile.js && mocha --reporter spec"
"test": "node gulpfile.js && NODE_ENV=test mocha --reporter spec"
},
"engineStrict": true,
"engines": {
Expand Down
10 changes: 10 additions & 0 deletions test/slush-test/slushfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
var gulp = require('gulp');

gulp.task('default', function () {
console.log('default');
});

gulp.task('app', function () {
console.log('app');
});
106 changes: 106 additions & 0 deletions test/slush.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
'use strict';
var spawn = require('child_process').spawn,
path = require('path');

describe('slush', function () {
it('should list installed generators', function (done) {
var slush = runSlush();
var data = '';
slush.stdout.on('data', function (chunk) {
data += chunk;
});
slush.on('close', function (code) {
code.should.equal(0);
data.should.match(/\[slush\] bad/);
data.should.match(/\[slush\] test/);
done();
});
});

it('should list tasks for given generator', function (done) {
var slush = runSlush(['test', '--tasks']);
var data = '';
slush.stdout.on('data', function (chunk) {
data += chunk;
});
slush.on('close', function (code) {
code.should.equal(0);
data.should.match(/\[gulp\] default/);
data.should.match(/\[gulp\] app/);
done();
});
});

it('should run `default` task in generator, when task is not provided', function (done) {
var slush = runSlush(['test']);
var data = '';
slush.stdout.on('data', function (chunk) {
data += chunk;
});
slush.on('close', function (code) {
code.should.equal(0);
data.should.match(/\ndefault\n/);
done();
});
});

it('should run provided task in generator', function (done) {
var slush = runSlush(['test', 'app']);
var data = '';
slush.stdout.on('data', function (chunk) {
data += chunk;
});
slush.on('close', function (code) {
code.should.equal(0);
data.should.match(/\napp\n/);
done();
});
});

it('should fail when running a non-existing task in a generator', function (done) {
var slush = runSlush(['test', 'noexist']);
var data = '';
slush.stdout.on('data', function (chunk) {
data += chunk;
});
slush.on('close', function (code) {
code.should.equal(1);
data.should.match(/\[slush\] Task 'noexist' was not defined in `slush-test`/);
done();
});
});

it('should fail when running a generator without slushfile', function (done) {
var slush = runSlush(['bad']);
var data = '';
slush.stdout.on('data', function (chunk) {
data += chunk;
});
slush.on('close', function (code) {
code.should.equal(1);
data.should.match(/\[slush\] No slushfile found/);
data.should.match(/\[slush\].+issue with.+`slush-bad`/);
done();
});
});

it('should fail trying to run a non-existing generator', function (done) {
var slush = runSlush(['noexist']);
var data = '';
slush.stdout.on('data', function (chunk) {
data += chunk;
});
slush.on('close', function (code) {
code.should.equal(1);
data.should.match(/\[slush\] No generator by name: "noexist" was found/);
done();
});
});
});

function runSlush (args) {
args = args || [];
var slush = spawn('node', [path.join(__dirname, '..', 'bin', 'slush.js')].concat(args), {cwd: __dirname});
slush.stdout.setEncoding('utf8');
return slush;
}

0 comments on commit eeecc29

Please sign in to comment.