Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brzpegasus committed Mar 15, 2015
1 parent 8d2cf5b commit 55e9f8b
Show file tree
Hide file tree
Showing 14 changed files with 443 additions and 4 deletions.
5 changes: 2 additions & 3 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"predef": [
"document",
"window",
"-Promise"
],
"browser": true,
"browser": false,
"boss": true,
"curly": true,
"debug": false,
Expand All @@ -16,6 +14,7 @@
"laxbreak": false,
"newcap": true,
"noarg": true,
"node": true,
"noempty": false,
"nonew": false,
"nomen": false,
Expand Down
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: node_js

sudo: false

node_js:
- "0.10"
- "0.12"
- "iojs"

cache:
directories:
- node_modules

before_install:
- npm config set spin false
- npm install -g npm@^2

install:
- npm install

script:
- npm test
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
"rsvp": "^3.0.17"
},
"devDependencies": {
"ember-cli": "0.2.0-beta.1"
"chai": "^2.1.1",
"chai-as-promised": "^4.3.0",
"ember-cli": "0.2.0-beta.1",
"glob": "^5.0.3",
"mocha": "^2.2.1",
"mocha-jshint": "^1.0.0",
"mock-spawn": "^0.2.4",
"mockery": "^1.4.0"
},
"keywords": [
"ember-addon",
Expand Down
45 changes: 45 additions & 0 deletions tests/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"predef": [
"console",
"it",
"describe",
"beforeEach",
"afterEach",
"before",
"after",
"-Promise"
],
"expr": true,
"proto": true,
"strict": true,
"indent": 2,
"camelcase": true,
"node": true,
"browser": false,
"boss": true,
"curly": true,
"latedef": "nofunc",
"debug": false,
"devel": false,
"eqeqeq": true,
"evil": true,
"forin": false,
"immed": false,
"laxbreak": false,
"newcap": true,
"noarg": true,
"noempty": false,
"quotmark": true,
"nonew": false,
"nomen": false,
"onevar": false,
"plusplus": false,
"regexp": false,
"undef": true,
"unused": true,
"sub": true,
"trailing": true,
"white": false,
"eqnull": true,
"esnext": true
}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions tests/helpers/expect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');

chai.use(chaiAsPromised);

module.exports = chai.expect;
3 changes: 3 additions & 0 deletions tests/mocha-jshint-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var mochaJSHint = require('mocha-jshint');

mochaJSHint(['lib']);
22 changes: 22 additions & 0 deletions tests/runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

var glob = require('glob');
var Mocha = require('mocha');

var mocha = new Mocha({
reporter: 'spec'
});

var root = 'tests/';

function addFiles(mocha, files) {
glob.sync(root + files).forEach(mocha.addFile.bind(mocha));
}

addFiles(mocha, '/**/*-test.js');

mocha.run(function(failures) {
process.on('exit', function() {
process.exit(failures);
});
});
167 changes: 167 additions & 0 deletions tests/unit/commands/nw-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
'use strict';

var path = require('path');
var mockery = require('mockery');
var mockSpawn = require('mock-spawn');
var Command = require('ember-cli/lib/models/command');
var Task = require('ember-cli/lib/models/task');
var MockUI = require('ember-cli/tests/helpers/mock-ui');
var MockAnalytics = require('ember-cli/tests/helpers/mock-analytics');
var RSVP = require('rsvp');
var expect = require('../../helpers/expect');

describe("ember nw command", function() {
var NWCommand, ui, analytics, project, spawn, _envNW;

beforeEach(function() {
spawn = mockSpawn();
mockery.enable({ useCleanCache: true });
mockery.registerMock('child_process', { spawn: spawn });
mockery.warnOnUnregistered(false);

_envNW = process.env.NW_PATH;
delete process.env.NW_PATH;

var nwObject = require('../../../lib/commands/nw');
NWCommand = Command.extend(nwObject);

ui = new MockUI();
analytics = new MockAnalytics();

project = {
isEmberCLIProject: function() {
return true;
},
root: path.join(__dirname, '..', '..', 'fixtures', 'project-empty')
};
});

afterEach(function() {
process.env.NW_PATH = _envNW;

mockery.deregisterAll();
mockery.resetCache();
mockery.disable();
});

it("should build the project before running nw.js", function() {
var tasks = [];

var command = new NWCommand({
ui: ui,
analytics: analytics,
project: project,
settings: {},
buildWatch: function() {
tasks.push('buildWatch');
return RSVP.resolve();
},
runNW: function() {
tasks.push('runNW');
return RSVP.resolve();
}
}).validateAndRun();

return expect(command).to.be.fulfilled
.then(function() {
expect(tasks).to.deep.equal(['buildWatch', 'runNW']);
});
});

it("should not run nw.js when the build fails", function() {
var tasks = [];

var command = new NWCommand({
ui: ui,
analytics: analytics,
project: project,
settings: {},
buildWatch: function() {
tasks.push('buildWatch');
return RSVP.reject();
},
runNW: function() {
tasks.push('runNW');
return RSVP.resolve();
}
}).validateAndRun();

return expect(command).to.be.rejected
.then(function() {
expect(tasks).to.deep.equal(['buildWatch']);
});
});

it("should not keep watching if nw.js fails to run", function() {
var tasks = [];

var command = new NWCommand({
ui: ui,
analytics: analytics,
project: project,
settings: {},
buildWatch: function() {
tasks.push('buildWatch');
return RSVP.resolve();
},
runNW: function() {
tasks.push('runNW');
return RSVP.reject();
}
}).validateAndRun();

return expect(command).to.be.rejected
.then(function() {
expect(tasks).to.deep.equal(['buildWatch', 'runNW']);
});
});

it("should spawn a 'nw' process with the right arguments", function() {
var command = new NWCommand({
ui: ui,
analytics: analytics,
project: project,
settings: {},
buildWatch: function() {
return RSVP.resolve();
}
}).validateAndRun();

return expect(command).to.be.fulfilled
.then(function() {
expect(spawn.calls.length).to.equal(1);
expect(spawn.calls[0].command).to.equal('nw');
expect(spawn.calls[0].args).to.deep.equal(['.']);

expect(ui.output).to.contain("Starting nw.js...");
expect(ui.output).to.contain("nw.js exited.");
});
});

it("should print a friendly message when the 'nw' command cannot be found", function() {
var command = new NWCommand({
ui: ui,
analytics: analytics,
project: project,
settings: {},
buildWatch: function() {
return RSVP.resolve();
}
}).validateAndRun();

spawn.sequence.add(function() {
this.emit('error', { code: 'ENOENT' });
});

return expect(command).to.be.rejected
.then(function() {
expect(spawn.calls.length).to.equal(1);
expect(spawn.calls[0].command).to.equal('nw');
expect(spawn.calls[0].args).to.deep.equal(['.']);

expect(ui.output).to.contain("Starting nw.js...");
expect(ui.output).to.contain("Error running the following command: nw");
expect(ui.output).to.contain("re-run the blueprint");
});
});
});
Loading

0 comments on commit 55e9f8b

Please sign in to comment.