test(pre): custom commit message analyzer

This commit is contained in:
Stephan Bönnemann
2015-04-22 17:52:45 +02:00
parent e445effdcf
commit 08ae05fb82
5 changed files with 88 additions and 40 deletions
+37
View File
@@ -0,0 +1,37 @@
'use strict'
var fs = require('fs')
var exec = require('child_process').exec
var nixt = require('nixt')
module.exports = function (t, message, version, code, name, cwd) {
t.test(name, function (t) {
t.plan(3)
nixt()
.cwd(cwd)
.env('CI', true)
.env('npm_config_registry', 'http://127.0.0.1:4873/')
.exec('git commit --allow-empty -m "' + message + '"')
.run('npm run prepublish')
.code(code)
.stdout(/> semantic-release pre\n\nDetermining new version\n/m)
.end(function (err) {
t.error(err, 'nixt')
var pkg = JSON.parse(fs.readFileSync(cwd + '/package.json'))
t.is(pkg.version, version, 'version')
if (code === 1) {
return t.error(null, 'no publish')
}
exec('npm publish --ignore-scripts', {cwd: cwd}, function (err) {
setTimeout(function () {
t.error(err, 'publish')
}, 300)
})
})
})
}
+20
View File
@@ -0,0 +1,20 @@
'use strict'
module.exports = function (commits) {
var type = null
commits.every(function (commit) {
if (/FOO/.test(commit.message)) {
type = 'major'
return false
}
if (/BAR/.test(commit.message)) type = 'minor'
if (!type && /BAZ/.test(commit.message)) type = 'patch'
return true
})
return type
}