-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from lukemelia/test-coverage
Add test coverage and willDeploy config validation
- Loading branch information
Showing
7 changed files
with
281 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var Promise = require('ember-cli/lib/ext/promise'); | ||
|
||
var chalk = require('chalk'); | ||
var yellow = chalk.yellow; | ||
var blue = chalk.blue; | ||
|
||
function applyDefaultConfigIfNecessary(config, prop, defaultConfig, ui){ | ||
if (!config[prop]) { | ||
var value = defaultConfig[prop]; | ||
config[prop] = value; | ||
ui.write(blue('| ')); | ||
ui.writeLine(yellow('- Missing config: `' + prop + '`, using default: `' + value + '`')); | ||
} | ||
} | ||
|
||
module.exports = function(ui, config) { | ||
ui.write(blue('| ')); | ||
ui.writeLine(blue('- validating config')); | ||
|
||
var defaultConfig = { | ||
buildEnv: 'production', | ||
buildPath: 'tmp/dist-deploy' | ||
}; | ||
['buildEnv', 'buildPath'].forEach(function(propName){ | ||
applyDefaultConfigIfNecessary(config, propName, defaultConfig, ui); | ||
}); | ||
|
||
return Promise.resolve(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/*jshint globalstrict: true*/ | ||
'use strict'; | ||
|
||
var glob = require('glob'); | ||
var Mocha = require('mocha'); | ||
|
||
var mocha = new Mocha({ | ||
reporter: 'spec' | ||
}); | ||
|
||
var arg = process.argv[2]; | ||
var root = 'tests/'; | ||
|
||
function addFiles(mocha, files) { | ||
glob.sync(root + files).forEach(mocha.addFile.bind(mocha)); | ||
} | ||
|
||
addFiles(mocha, '/**/*-nodetest.js'); | ||
|
||
if (arg === 'all') { | ||
addFiles(mocha, '/**/*-nodetest-slow.js'); | ||
} | ||
|
||
mocha.run(function(failures) { | ||
process.on('exit', function() { | ||
process.exit(failures); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/*jshint globalstrict: true*/ | ||
'use strict'; | ||
|
||
var RSVP = require('ember-cli/lib/ext/promise'); | ||
|
||
var assert = require('ember-cli/tests/helpers/assert'); | ||
|
||
describe('build plugin', function() { | ||
var subject; | ||
|
||
before(function() { | ||
subject = require('../../index'); | ||
}); | ||
|
||
it('has a name', function() { | ||
var result = subject.createDeployPlugin({ | ||
name: 'test-plugin' | ||
}); | ||
|
||
assert.equal(result.name, 'test-plugin'); | ||
}); | ||
|
||
it('implements the correct hooks', function() { | ||
var result = subject.createDeployPlugin({ | ||
name: 'test-plugin' | ||
}); | ||
|
||
assert.equal(typeof result.willDeploy, 'function'); | ||
assert.equal(typeof result.build, 'function'); | ||
}); | ||
|
||
describe('willDeploy hook', function() { | ||
it('resolves if config is ok', function() { | ||
var plugin = subject.createDeployPlugin({ | ||
name: 'build' | ||
}); | ||
|
||
var context = { | ||
deployment: { | ||
ui: { write: function() {}, writeLine: function() {} }, | ||
config: { | ||
} | ||
} | ||
}; | ||
return assert.isFulfilled(plugin.willDeploy.call(plugin, context)); | ||
}); | ||
}); | ||
|
||
describe('build hook', function() { | ||
var plugin; | ||
var context; | ||
|
||
beforeEach(function() { | ||
plugin = subject.createDeployPlugin({ | ||
name: 'build' | ||
}); | ||
|
||
context = { | ||
redisClient: { | ||
upload: function() { | ||
return RSVP.resolve('redis-key'); | ||
} | ||
}, | ||
tag: 'some-tag', | ||
deployment: { | ||
ui: { write: function() {}, writeLine: function() {} }, | ||
project: { name: function() { return 'test-project'; }, addons: [], root: 'tests/dummy' }, | ||
config: { | ||
build: { | ||
buildEnv: 'development', | ||
buildPath: 'tmp/dist-deploy', | ||
} | ||
} | ||
} | ||
}; | ||
}); | ||
|
||
it('builds the app and returns distDir and distFiles', function(done) { | ||
this.timeout(50000); | ||
return assert.isFulfilled(plugin.build.call(plugin, context)) | ||
.then(function(result) { | ||
assert.deepEqual(result, { | ||
distDir: 'dist', | ||
distFiles: [ | ||
'assets/dummy.css', | ||
'assets/dummy.js', | ||
'assets/dummy.map', | ||
'assets/ember-data.js.map', | ||
'assets/failed.png', | ||
'assets/passed.png', | ||
'assets/test-loader.js', | ||
'assets/test-support.css', | ||
'assets/test-support.js', | ||
'assets/test-support.map', | ||
'assets/vendor.css', | ||
'assets/vendor.js', | ||
'assets/vendor.map', | ||
'crossdomain.xml', | ||
'index.html', | ||
'robots.txt', | ||
'testem.js', | ||
'tests/index.html' | ||
] | ||
}); | ||
done(); | ||
}).catch(function(reason){ | ||
console.log(reason.actual.stack); | ||
done(reason.actual); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* node:true */ | ||
var assert = require('ember-cli/tests/helpers/assert'); | ||
|
||
describe('validate-config', function() { | ||
var subject; | ||
var config; | ||
var mockUi; | ||
|
||
before(function() { | ||
subject = require('../../../../lib/utilities/validate-config'); | ||
}); | ||
|
||
beforeEach(function() { | ||
mockUi = { | ||
messages: [], | ||
write: function() { }, | ||
writeLine: function(message) { | ||
this.messages.push(message); | ||
} | ||
}; | ||
}); | ||
|
||
describe('without providing config', function () { | ||
beforeEach(function() { | ||
config = { }; | ||
}); | ||
it('warns about missing optional config', function() { | ||
return assert.isFulfilled(subject(mockUi, config)) | ||
.then(function() { | ||
var messages = mockUi.messages.reduce(function(previous, current) { | ||
if (/- Missing config:\s.*, using default:\s/.test(current)) { | ||
previous.push(current); | ||
} | ||
|
||
return previous; | ||
}, []); | ||
|
||
assert.equal(messages.length, 2); | ||
}); | ||
}); | ||
|
||
it('adds default config to the config object', function() { | ||
return assert.isFulfilled(subject(mockUi, config)) | ||
.then(function() { | ||
assert.isDefined(config.buildEnv); | ||
assert.isDefined(config.buildPath); | ||
}); | ||
}); | ||
|
||
it('resolves', function() { | ||
return assert.isFulfilled(subject(mockUi, config)); | ||
}); | ||
}); | ||
|
||
describe('with a buildEnv and buildPath provided', function () { | ||
beforeEach(function() { | ||
config = { | ||
buildEnv: 'development', | ||
buildPath: 'tmp/dist-deploy' | ||
}; | ||
}); | ||
it('does not warns about missing optional config', function() { | ||
return assert.isFulfilled(subject(mockUi, config)) | ||
.then(function() { | ||
var messages = mockUi.messages.reduce(function(previous, current) { | ||
if (/- Missing config:\s.*, using default:\s/.test(current)) { | ||
previous.push(current); | ||
} | ||
|
||
return previous; | ||
}, []); | ||
|
||
assert.equal(messages.length, 0); | ||
}); | ||
}); | ||
|
||
it('resolves', function() { | ||
return assert.isFulfilled(subject(mockUi, config)); | ||
}); | ||
}); | ||
}); |