test(pre): custom commit message analyzer
This commit is contained in:
parent
e445effdcf
commit
08ae05fb82
@ -4,6 +4,7 @@ var test = require('tape')
|
||||
|
||||
var createModule = require('./lib/create-module')
|
||||
|
||||
require('./scenarios/custom-analyzer')(test, createModule)
|
||||
require('./scenarios/ignore')(test, createModule)
|
||||
require('./scenarios/prepublish')(test, createModule)
|
||||
require('./scenarios/postpublish')(test, createModule)
|
||||
|
37
tests/lib/commit-to-version-test.js
Normal file
37
tests/lib/commit-to-version-test.js
Normal 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
tests/lib/custom-analyzer.js
Normal file
20
tests/lib/custom-analyzer.js
Normal 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
|
||||
}
|
23
tests/scenarios/custom-analyzer.js
Normal file
23
tests/scenarios/custom-analyzer.js
Normal file
@ -0,0 +1,23 @@
|
||||
'use strict'
|
||||
|
||||
var path = require('path')
|
||||
|
||||
var efh = require('error-first-handler')
|
||||
|
||||
var commitToVersionTest = require('../lib/commit-to-version-test')
|
||||
|
||||
module.exports = function (test, createModule) {
|
||||
createModule({
|
||||
release: {
|
||||
analyzer: path.join(__dirname, '../lib/custom-analyzer')
|
||||
}
|
||||
}, efh()(function (name, cwd) {
|
||||
test('custom-analyzer', function (t) {
|
||||
commitToVersionTest(t, 'HO', '0.0.0', 1, 'abort publish w/o changes', cwd)
|
||||
commitToVersionTest(t, 'BAZ', '1.0.0', 0, 'release 1.0.0 if unpublished', cwd)
|
||||
commitToVersionTest(t, 'BAZ', '1.0.1', 0, 'bump patch for fix', cwd)
|
||||
commitToVersionTest(t, 'BAR', '1.1.0', 0, 'bump minor for feature', cwd)
|
||||
commitToVersionTest(t, 'FOO', '2.0.0', 0, 'bump major for breaking change', cwd)
|
||||
})
|
||||
}))
|
||||
}
|
@ -1,50 +1,17 @@
|
||||
'use strict'
|
||||
|
||||
var fs = require('fs')
|
||||
var exec = require('child_process').exec
|
||||
|
||||
var efh = require('error-first-handler')
|
||||
var nixt = require('nixt')
|
||||
|
||||
var commitToVersionTest = require('../lib/commit-to-version-test')
|
||||
|
||||
module.exports = function (test, createModule) {
|
||||
createModule(efh()(function (name, cwd) {
|
||||
test('prepublish', function (t) {
|
||||
prepublishTest(t, 'refactor: change', '0.0.0', 1, 'abort publish w/o changes')
|
||||
prepublishTest(t, 'fix: change', '1.0.0', 0, 'release 1.0.0 if unpublished')
|
||||
prepublishTest(t, 'fix: change', '1.0.1', 0, 'bump patch for fix')
|
||||
prepublishTest(t, 'feat: change', '1.1.0', 0, 'bump minor for feature')
|
||||
prepublishTest(t, 'fix: BREAKING CHANGE: change', '2.0.0', 0, 'bump major for breaking change')
|
||||
commitToVersionTest(t, 'refactor: change', '0.0.0', 1, 'abort publish w/o changes', cwd)
|
||||
commitToVersionTest(t, 'fix: change', '1.0.0', 0, 'release 1.0.0 if unpublished', cwd)
|
||||
commitToVersionTest(t, 'fix: change', '1.0.1', 0, 'bump patch for fix', cwd)
|
||||
commitToVersionTest(t, 'feat: change', '1.1.0', 0, 'bump minor for feature', cwd)
|
||||
commitToVersionTest(t, 'fix: BREAKING CHANGE: change', '2.0.0', 0, 'bump major for breaking change', cwd)
|
||||
})
|
||||
|
||||
function prepublishTest (t, message, version, code, name) {
|
||||
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)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user