This commit does a lot but it's all connected and tries to make everything more extensible and future proof. 1. CLI arguments and options from the "package.json" are no longer treated as two different things. You can now pass options either way. BREAKING CHANGE: cli arguments are now normalized to camelCase, so e.g. `options['github-url']` is now `options.githubUrl` 2. Plugins no longer receive config they need one by one, but in one huge object. This way it's easier to pass more info in the future w/o breaking existing plugins that rely on the position of the callback in the arguments array. BREAKING CHANGE: Plugins now need to read their passed options from one huge config object. Old: ```js module.exports = function (pluginConfig, foo, bar, cb) {…} ``` New: ```js // ES5 module.exports = function(pluginConfig, config, cb) { var foo = config.foo var bar = config.bar … } // ES6 module.exports = function (pluginConfig, {foo, bar}, cb) {…} ```
69 lines
1.4 KiB
JavaScript
69 lines
1.4 KiB
JavaScript
const { defaults } = require('lodash')
|
|
const test = require('tap').test
|
|
const proxyquire = require('proxyquire')
|
|
|
|
const post = proxyquire('../../dist/post', {
|
|
'git-head': require('../mocks/git-head'),
|
|
github: require('../mocks/github')
|
|
})
|
|
|
|
const pkg = {
|
|
version: '1.0.0',
|
|
repository: {url: 'http://github.com/whats/up.git'}
|
|
}
|
|
|
|
const plugins = {generateNotes: (pkg, cb) => cb(null, 'the log')}
|
|
|
|
const defaultRelease = {
|
|
owner: 'whats',
|
|
repo: 'up',
|
|
name: 'v1.0.0',
|
|
tag_name: 'v1.0.0',
|
|
target_commitish: 'bar',
|
|
body: 'the log'
|
|
}
|
|
|
|
test('full post run', (t) => {
|
|
t.test('in debug mode w/o token', (tt) => {
|
|
post({
|
|
options: {debug: true},
|
|
pkg,
|
|
plugins
|
|
}, (err, published, release) => {
|
|
tt.error(err)
|
|
tt.is(published, false)
|
|
tt.match(release, defaults({draft: true}, defaultRelease))
|
|
|
|
tt.end()
|
|
})
|
|
})
|
|
|
|
t.test('in debug mode w/token', (tt) => {
|
|
post({
|
|
options: {debug: true, githubToken: 'yo'},
|
|
pkg,
|
|
plugins
|
|
}, (err, published, release) => {
|
|
tt.error(err)
|
|
tt.is(published, true)
|
|
tt.match(release, defaults({draft: true}, defaultRelease))
|
|
|
|
tt.end()
|
|
})
|
|
})
|
|
|
|
t.test('production', (tt) => {
|
|
post({
|
|
options: {githubToken: 'yo'},
|
|
pkg,
|
|
plugins
|
|
}, (err, published, release) => {
|
|
tt.error(err)
|
|
tt.is(published, true)
|
|
tt.match(release, defaultRelease)
|
|
|
|
tt.end()
|
|
})
|
|
})
|
|
})
|