refactor: use one config object instead of passing arguments to plugins on their own

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) {…}
```
This commit is contained in:
Stephan Bönnemann 2015-07-19 15:34:30 +02:00
parent 8892ec7f7a
commit d9eeb3fcae
16 changed files with 190 additions and 161 deletions

View File

@ -23,10 +23,10 @@
} }
}, },
"dependencies": { "dependencies": {
"@semantic-release/commit-analyzer": "^1.0.0", "@semantic-release/commit-analyzer": "^2.0.0",
"@semantic-release/condition-travis": "^3.0.0", "@semantic-release/condition-travis": "^4.0.0",
"@semantic-release/error": "^1.0.0", "@semantic-release/error": "^1.0.0",
"@semantic-release/release-notes-generator": "^1.0.0", "@semantic-release/release-notes-generator": "^2.0.0",
"git-head": "^1.2.1", "git-head": "^1.2.1",
"github": "^0.2.4", "github": "^0.2.4",
"lodash": "^3.9.3", "lodash": "^3.9.3",

View File

@ -1,27 +1,35 @@
const { readFileSync, writeFileSync } = require('fs') const { readFileSync, writeFileSync } = require('fs')
const path = require('path')
const _ = require('lodash') const _ = require('lodash')
const log = require('npmlog') const log = require('npmlog')
const nopt = require('nopt') const nopt = require('nopt')
const npmconf = require('npmconf') const npmconf = require('npmconf')
const PREFIX = 'semantic-release'
const env = process.env const env = process.env
const options = _.defaults(nopt({ const pkg = JSON.parse(readFileSync('./package.json'))
const knownOptions = {
branch: String,
debug: Boolean, debug: Boolean,
'github-token': String, 'github-token': String,
'github-url': String 'github-url': String,
}, { 'analyze-commits': [path, String],
token: 'github-token', 'generate-notes': [path, String],
dry: 'debug' 'verify-conditions': [path, String],
}), { 'verify-release': [path, String]
debug: !env.CI, }
'github-token': env.GH_TOKEN || env.GITHUB_TOKEN, const options = _.defaults(
'github-url': env.GH_URL _.mapKeys(nopt(knownOptions), (value, key) => _.camelCase(key)),
}) pkg.release,
const PREFIX = 'semantic-release' {
branch: 'master',
const pkg = JSON.parse(readFileSync('./package.json')) debug: !env.CI,
const plugins = require('./lib/plugins')(pkg.release || {}) githubToken: env.GH_TOKEN || env.GITHUB_TOKEN,
githubUrl: env.GH_URL
}
)
const plugins = require('./lib/plugins')(options)
npmconf.load({}, (err, conf) => { npmconf.load({}, (err, conf) => {
if (err) { if (err) {
@ -29,28 +37,41 @@ npmconf.load({}, (err, conf) => {
process.exit(1) process.exit(1)
} }
log.level = conf.get('loglevel') let npm = {
auth: {
token: env.NPM_TOKEN
},
loglevel: conf.get('loglevel'),
registry: conf.get('registry'),
tag: (pkg.publishConfig || {}).tag || conf.get('tag') || 'latest'
}
log.verbose(PREFIX, 'argv:', options) if (npm.registry[npm.registry.length - 1] !== '/') npm.registry += '/'
log.verbose(PREFIX, 'options:', pkg.release || 'no options')
log.verbose(PREFIX, 'Verifying pkg, options and env.')
const errors = require('./lib/verify')(pkg, options, env) log.level = npm.loglevel
const config = {PREFIX, log, env, pkg, options, plugins, npm}
log.verbose(PREFIX, 'options:', _.assign({
githubToken: options.githubToken ? '***' : undefined
}), options)
log.verbose(PREFIX, 'Verifying config.')
const errors = require('./lib/verify')(config)
errors.forEach((err) => log.error(PREFIX, `${err.message} ${err.code}`)) errors.forEach((err) => log.error(PREFIX, `${err.message} ${err.code}`))
if (errors.length) process.exit(1) if (errors.length) process.exit(1)
if (!options.argv.cooked.length || options.argv.cooked[0] === 'pre') { if (options.argv.remain[0] === 'pre') {
log.verbose(PREFIX, 'Running pre-script.') log.verbose(PREFIX, 'Running pre-script.')
log.verbose(PREFIX, 'Veriying conditions.') log.verbose(PREFIX, 'Veriying conditions.')
plugins.verifyConditions(pkg, options, env, (err) => { plugins.verifyConditions(config, (err) => {
if (err) { if (err) {
log[options.debug ? 'warn' : 'error'](PREFIX, err.message) log[options.debug ? 'warn' : 'error'](PREFIX, err.message)
if (!options.debug) process.exit(1) if (!options.debug) process.exit(1)
} }
const registry = conf.get('registry') const nerfDart = require('./lib/nerf-dart')(npm.registry)
const nerfDart = require('./lib/nerf-dart')(registry)
let wroteNpmRc = false let wroteNpmRc = false
if (env.NPM_TOKEN) { if (env.NPM_TOKEN) {
@ -69,19 +90,7 @@ npmconf.load({}, (err, conf) => {
if (wroteNpmRc) log.verbose(PREFIX, 'Wrote authToken to .npmrc.') if (wroteNpmRc) log.verbose(PREFIX, 'Wrote authToken to .npmrc.')
const npmConfig = { require('./pre')(config, (err, release) => {
auth: {
token: env.NPM_TOKEN
},
loglevel: log.level,
registry: registry + (registry[registry.length - 1] !== '/' ? '/' : ''),
tag: (pkg.publishConfig || {}).tag || conf.get('tag') || 'latest'
}
require('./pre')(pkg,
npmConfig,
plugins,
(err, release) => {
if (err) { if (err) {
log.error(PREFIX, 'Failed to determine new version.') log.error(PREFIX, 'Failed to determine new version.')
@ -91,7 +100,7 @@ npmconf.load({}, (err, conf) => {
process.exit(1) process.exit(1)
} }
const message = `Determined version ${release.version} as "${npmConfig.tag}".` const message = `Determined version ${release.version} as "${npm.tag}".`
log.verbose(PREFIX, message) log.verbose(PREFIX, message)
@ -108,10 +117,10 @@ npmconf.load({}, (err, conf) => {
}) })
}) })
}) })
} else if (options.argv.cooked[0] === 'post') { } else if (options.argv.remain[0] === 'post') {
log.verbose(PREFIX, 'Running post-script.') log.verbose(PREFIX, 'Running post-script.')
require('./post')(pkg, options, plugins, (err, published, release) => { require('./post')(config, (err, published, release) => {
if (err) { if (err) {
log.error(PREFIX, 'Failed to publish release notes.', err) log.error(PREFIX, 'Failed to publish release notes.', err)
process.exit(1) process.exit(1)
@ -120,6 +129,6 @@ npmconf.load({}, (err, conf) => {
log.verbose(PREFIX, `${published ? 'Published' : 'Generated'} release notes.`, release) log.verbose(PREFIX, `${published ? 'Published' : 'Generated'} release notes.`, release)
}) })
} else { } else {
log.error(PREFIX, `Command "${options.argv.cooked[0]}" not recognized. User either "pre" or "post"`) log.error(PREFIX, `Command "${options.argv.remain[0]}" not recognized. User either "pre" or "post"`)
} }
}) })

View File

@ -1,6 +1,6 @@
const { exec } = require('child_process') const { exec } = require('child_process')
module.exports = function (lastRelease, cb) { module.exports = function ({lastRelease}, cb) {
const from = lastRelease.gitHead const from = lastRelease.gitHead
const range = (from ? from + '..' : '') + 'HEAD' const range = (from ? from + '..' : '') + 'HEAD'

View File

@ -3,24 +3,24 @@ const SemanticReleaseError = require('@semantic-release/error')
const npmlog = require('npmlog') const npmlog = require('npmlog')
const RegClient = require('npm-registry-client') const RegClient = require('npm-registry-client')
module.exports = function (pkg, npmConfig, cb) { module.exports = function ({pkg, npm}, cb) {
npmlog.level = npmConfig.loglevel || 'error' npmlog.level = npm.loglevel || 'error'
const client = new RegClient({log: npmlog}) const client = new RegClient({log: npmlog})
client.get(`${npmConfig.registry}${pkg.name}`, { client.get(`${npm.registry}${pkg.name}`, {
auth: npmConfig.auth auth: npm.auth
}, (err, data) => { }, (err, data) => {
if (err && err.statusCode === 404) return cb(null, {}) if (err && err.statusCode === 404) return cb(null, {})
if (err) return cb(err) if (err) return cb(err)
const version = data['dist-tags'][npmConfig.tag] const version = data['dist-tags'][npm.tag]
if (!version) return cb(new SemanticReleaseError(`There is no release with the dist-tag "${npmConfig.tag}" yet. Tag a version first.`, 'ENODISTTAG')) if (!version) return cb(new SemanticReleaseError(`There is no release with the dist-tag "${npm.tag}" yet. Tag a version first.`, 'ENODISTTAG'))
cb(null, { cb(null, {
version, version,
gitHead: data.versions[version].gitHead, gitHead: data.versions[version].gitHead,
tag: npmConfig.tag tag: npm.tag
}) })
}) })
} }

View File

@ -1,4 +1,4 @@
/* istanbul ignore next */ /* istanbul ignore next */
module.exports = function (options, release, cb) { module.exports = function (config, options, cb) {
cb(null) cb(null)
} }

View File

@ -1,20 +1,20 @@
const relative = require('require-relative') const relative = require('require-relative')
let exports = module.exports = function (source) { let exports = module.exports = function (options) {
return { return {
analyzeCommits: exports.normalize(source.analyzeCommits, '@semantic-release/commit-analyzer'), analyzeCommits: exports.normalize(options.analyzeCommits, '@semantic-release/commit-analyzer'),
generateNotes: exports.normalize(source.generateNotes, '@semantic-release/release-notes-generator'), generateNotes: exports.normalize(options.generateNotes, '@semantic-release/release-notes-generator'),
verifyConditions: exports.normalize(source.verifyConditions, '@semantic-release/condition-travis'), verifyConditions: exports.normalize(options.verifyConditions, '@semantic-release/condition-travis'),
verifyRelease: exports.normalize(source.verifyRelease, './plugin-noop') verifyRelease: exports.normalize(options.verifyRelease, './plugin-noop')
} }
} }
exports.normalize = function (plugin, fallback) { exports.normalize = function (pluginConfig, fallback) {
if (typeof plugin === 'string') return relative(plugin).bind(null, {}) if (typeof pluginConfig === 'string') return relative(pluginConfig).bind(null, {})
if (plugin && (typeof plugin.path === 'string')) { if (pluginConfig && (typeof pluginConfig.path === 'string')) {
return relative(plugin.path).bind(null, plugin) return relative(pluginConfig.path).bind(null, pluginConfig)
} }
return require(fallback).bind(null, plugin) return require(fallback).bind(null, pluginConfig)
} }

View File

@ -1,7 +1,9 @@
const SemanticReleaseError = require('@semantic-release/error') const SemanticReleaseError = require('@semantic-release/error')
module.exports = function (plugins, commits, lastRelease, cb) { module.exports = function (config, cb) {
plugins.analyzeCommits(commits, (err, type) => { const { plugins, lastRelease } = config
plugins.analyzeCommits(config, (err, type) => {
if (err) return cb(err) if (err) return cb(err)
if (!type) { if (!type) {

View File

@ -2,7 +2,7 @@ const parseSlug = require('parse-github-repo-url')
const SemanticReleaseError = require('@semantic-release/error') const SemanticReleaseError = require('@semantic-release/error')
module.exports = function (pkg, options, env) { module.exports = function ({pkg, options, env}) {
let errors = [] let errors = []
if (!pkg.name) { if (!pkg.name) {
@ -26,7 +26,7 @@ module.exports = function (pkg, options, env) {
if (options.debug) return errors if (options.debug) return errors
if (!options['github-token']) { if (!options.githubToken) {
errors.push(new SemanticReleaseError( errors.push(new SemanticReleaseError(
'No github token specified.', 'No github token specified.',
'ENOGHTOKEN' 'ENOGHTOKEN'

View File

@ -4,17 +4,18 @@ const gitHead = require('git-head')
const GitHubApi = require('github') const GitHubApi = require('github')
const parseSlug = require('parse-github-repo-url') const parseSlug = require('parse-github-repo-url')
module.exports = function (pkg, argv, plugins, cb) { module.exports = function (config, cb) {
const config = argv['github-url'] ? url.parse(argv['github-url']) : {} const { pkg, options, plugins } = config
const ghConfig = options.githubUrl ? url.parse(options.githubUrl) : {}
const github = new GitHubApi({ const github = new GitHubApi({
version: '3.0.0', version: '3.0.0',
port: config.port, port: ghConfig.port,
protocol: (config.protocol || '').split(':')[0] || null, protocol: (ghConfig.protocol || '').split(':')[0] || null,
host: config.hostname host: ghConfig.hostname
}) })
plugins.generateNotes(pkg, (err, log) => { plugins.generateNotes(config, (err, log) => {
if (err) return cb(err) if (err) return cb(err)
gitHead((err, hash) => { gitHead((err, hash) => {
@ -27,17 +28,17 @@ module.exports = function (pkg, argv, plugins, cb) {
name: `v${pkg.version}`, name: `v${pkg.version}`,
tag_name: `v${pkg.version}`, tag_name: `v${pkg.version}`,
target_commitish: hash, target_commitish: hash,
draft: !!argv.debug, draft: !!options.debug,
body: log body: log
} }
if (argv.debug && !argv['github-token']) { if (options.debug && !options.githubToken) {
return cb(null, false, release) return cb(null, false, release)
} }
github.authenticate({ github.authenticate({
type: 'oauth', type: 'oauth',
token: argv['github-token'] token: options.githubToken
}) })
github.releases.createRelease(release, (err) => { github.releases.createRelease(release, (err) => {

View File

@ -1,3 +1,4 @@
const _ = require('lodash')
const auto = require('run-auto') const auto = require('run-auto')
const semver = require('semver') const semver = require('semver')
@ -5,28 +6,38 @@ const getLastRelease = require('./lib/last-release')
const getCommits = require('./lib/commits') const getCommits = require('./lib/commits')
const getType = require('./lib/type') const getType = require('./lib/type')
module.exports = function (pkg, npmConfig, plugins, cb) { module.exports = function (config, cb) {
const {plugins} = config
auto({ auto({
lastRelease: getLastRelease.bind(null, pkg, npmConfig), lastRelease: getLastRelease.bind(null, config),
commits: ['lastRelease', (cb, results) => { commits: ['lastRelease', (cb, results) => {
getCommits(results.lastRelease, cb) getCommits(_.assign({
lastRelease: results.lastRelease
}, config),
cb)
}], }],
type: ['commits', 'lastRelease', (cb, results) => { type: ['commits', 'lastRelease', (cb, results) => {
getType(plugins, results.commits, results.lastRelease, cb) getType(_.assign({
commits: results.commits,
lastRelease: results.lastRelease
}, config),
cb)
}] }]
}, (err, results) => { }, (err, results) => {
if (err) return cb(err) if (err) return cb(err)
const nextRelease = { const nextRelease = {
type: results.type, type: results.type,
commits: results.commits,
lastVersion: results.lastRelease.version,
version: results.type === 'initial' ? version: results.type === 'initial' ?
'1.0.0' : '1.0.0' :
semver.inc(results.lastRelease.version, results.type) semver.inc(results.lastRelease.version, results.type)
} }
plugins.verifyRelease(nextRelease, (err) => { plugins.verifyRelease(_.assign({
commits: results.commits,
lastRelease: results.lastRelease,
nextRelease
}, config), (err) => {
if (err) return cb(err) if (err) return cb(err)
cb(null, nextRelease) cb(null, nextRelease)
}) })

View File

@ -7,7 +7,7 @@ const commits = proxyquire('../../dist/lib/commits', {
test('commits since last release', (t) => { test('commits since last release', (t) => {
t.test('get all commits', (tt) => { t.test('get all commits', (tt) => {
commits({}, (err, commits) => { commits({lastRelease: {}}, (err, commits) => {
tt.error(err) tt.error(err)
tt.is(commits.length, 2, 'all commits') tt.is(commits.length, 2, 'all commits')
tt.is(commits[0].hash, 'hash-one', 'parsed hash') tt.is(commits[0].hash, 'hash-one', 'parsed hash')
@ -18,7 +18,7 @@ test('commits since last release', (t) => {
}) })
t.test('get commits since hash', (tt) => { t.test('get commits since hash', (tt) => {
commits({gitHead: 'hash'}, (err, commits) => { commits({lastRelease: {gitHead: 'hash'}}, (err, commits) => {
tt.error(err) tt.error(err)
tt.is(commits.length, 1, 'specified commits') tt.is(commits.length, 1, 'specified commits')
tt.is(commits[0].hash, 'hash-one', 'parsed hash') tt.is(commits[0].hash, 'hash-one', 'parsed hash')

View File

@ -4,7 +4,7 @@ const test = require('tap').test
require('../mocks/registry') require('../mocks/registry')
const lastRelease = require('../../dist/lib/last-release') const lastRelease = require('../../dist/lib/last-release')
const npmConfig = { const npm = {
registry: 'http://registry.npmjs.org/', registry: 'http://registry.npmjs.org/',
tag: 'latest' tag: 'latest'
} }
@ -14,10 +14,9 @@ test('last release from registry', (t) => {
t.test('get release from package name', (tt) => { t.test('get release from package name', (tt) => {
lastRelease({ lastRelease({
name: 'available' pkg: {name: 'available'},
}, npm
npmConfig, }, (err, release) => {
(err, release) => {
tt.error(err) tt.error(err)
tt.is(release.version, '1.33.7', 'version') tt.is(release.version, '1.33.7', 'version')
tt.is(release.gitHead, 'HEAD', 'gitHead') tt.is(release.gitHead, 'HEAD', 'gitHead')
@ -29,10 +28,9 @@ test('last release from registry', (t) => {
t.test('get release from a tagged package\'s name', (tt) => { t.test('get release from a tagged package\'s name', (tt) => {
lastRelease({ lastRelease({
name: 'tagged' pkg: {name: 'tagged'},
}, npm: defaults({tag: 'foo'}, npm)
defaults({tag: 'foo'}, npmConfig), }, (err, release) => {
(err, release) => {
tt.error(err) tt.error(err)
tt.is(release.version, '0.8.15', 'version') tt.is(release.version, '0.8.15', 'version')
tt.is(release.gitHead, 'bar', 'gitHead') tt.is(release.gitHead, 'bar', 'gitHead')
@ -44,10 +42,9 @@ test('last release from registry', (t) => {
t.test('get error from an untagged package\'s name', (tt) => { t.test('get error from an untagged package\'s name', (tt) => {
lastRelease({ lastRelease({
name: 'untagged' pkg: {name: 'untagged'},
}, npm: defaults({tag: 'bar'}, npm)
defaults({tag: 'bar'}, npmConfig), }, (err) => {
(err) => {
tt.is(err.code, 'ENODISTTAG', 'error') tt.is(err.code, 'ENODISTTAG', 'error')
tt.end() tt.end()
@ -56,10 +53,9 @@ test('last release from registry', (t) => {
t.test('get release from scoped package name', (tt) => { t.test('get release from scoped package name', (tt) => {
lastRelease({ lastRelease({
name: '@scoped/available' pkg: {name: '@scoped/available'},
}, npm
npmConfig, }, (err, release) => {
(err, release) => {
tt.error(err) tt.error(err)
tt.is(release.version, '1.33.7', 'version') tt.is(release.version, '1.33.7', 'version')
tt.is(release.gitHead, 'HEAD', 'gitHead') tt.is(release.gitHead, 'HEAD', 'gitHead')
@ -71,10 +67,9 @@ test('last release from registry', (t) => {
t.test('get nothing from not yet published package name', (tt) => { t.test('get nothing from not yet published package name', (tt) => {
lastRelease({ lastRelease({
name: 'unavailable' pkg: {name: 'unavailable'},
}, npm
npmConfig, }, (err, release) => {
(err, release) => {
tt.error(err) tt.error(err)
tt.is(release.version, undefined, 'no version') tt.is(release.version, undefined, 'no version')

View File

@ -9,14 +9,10 @@ const post = proxyquire('../../dist/post', {
const pkg = { const pkg = {
version: '1.0.0', version: '1.0.0',
repository: { repository: {url: 'http://github.com/whats/up.git'}
url: 'http://github.com/whats/up.git'
}
} }
const plugins = { const plugins = {generateNotes: (pkg, cb) => cb(null, 'the log')}
generateNotes: (pkg, cb) => cb(null, 'the log')
}
const defaultRelease = { const defaultRelease = {
owner: 'whats', owner: 'whats',
@ -29,7 +25,11 @@ const defaultRelease = {
test('full post run', (t) => { test('full post run', (t) => {
t.test('in debug mode w/o token', (tt) => { t.test('in debug mode w/o token', (tt) => {
post(pkg, {debug: true}, plugins, (err, published, release) => { post({
options: {debug: true},
pkg,
plugins
}, (err, published, release) => {
tt.error(err) tt.error(err)
tt.is(published, false) tt.is(published, false)
tt.match(release, defaults({draft: true}, defaultRelease)) tt.match(release, defaults({draft: true}, defaultRelease))
@ -38,8 +38,12 @@ test('full post run', (t) => {
}) })
}) })
t.test('in debug mode w token', (tt) => { t.test('in debug mode w/token', (tt) => {
post(pkg, {debug: true, 'github-token': 'yo'}, plugins, (err, published, release) => { post({
options: {debug: true, githubToken: 'yo'},
pkg,
plugins
}, (err, published, release) => {
tt.error(err) tt.error(err)
tt.is(published, true) tt.is(published, true)
tt.match(release, defaults({draft: true}, defaultRelease)) tt.match(release, defaults({draft: true}, defaultRelease))
@ -49,7 +53,11 @@ test('full post run', (t) => {
}) })
t.test('production', (tt) => { t.test('production', (tt) => {
post(pkg, {'github-token': 'yo'}, plugins, (err, published, release) => { post({
options: {githubToken: 'yo'},
pkg,
plugins
}, (err, published, release) => {
tt.error(err) tt.error(err)
tt.is(published, true) tt.is(published, true)
tt.match(release, defaultRelease) tt.match(release, defaultRelease)

View File

@ -11,7 +11,7 @@ const plugins = {
analyzeCommits: (commits, cb) => cb(null, 'major') analyzeCommits: (commits, cb) => cb(null, 'major')
} }
const npmConfig = { const npm = {
registry: 'http://registry.npmjs.org/', registry: 'http://registry.npmjs.org/',
tag: 'latest' tag: 'latest'
@ -22,11 +22,10 @@ test('full pre run', (t) => {
tt.plan(3) tt.plan(3)
pre({ pre({
name: 'available' npm,
}, pkg: {name: 'available'},
npmConfig, plugins
plugins, }, (err, release) => {
(err, release) => {
tt.error(err) tt.error(err)
tt.is(release.type, 'major') tt.is(release.type, 'major')
tt.is(release.version, '2.0.0') tt.is(release.version, '2.0.0')
@ -37,11 +36,10 @@ test('full pre run', (t) => {
tt.plan(3) tt.plan(3)
pre({ pre({
name: 'unavailable' npm,
}, pkg: {name: 'unavailable'},
npmConfig, plugins
plugins, }, (err, release) => {
(err, release) => {
tt.error(err) tt.error(err)
tt.is(release.type, 'initial') tt.is(release.type, 'initial')
tt.is(release.version, '1.0.0') tt.is(release.version, '1.0.0')

View File

@ -7,12 +7,12 @@ test('get type from commits', (t) => {
tt.plan(2) tt.plan(2)
type({ type({
analyzeCommits: (commits, cb) => cb(null, 'major') commits: [{
}, [{ hash: '0',
hash: '0', message: 'a'
message: 'a' }],
}], { lastRelease: {version: '1.0.0'},
version: '1.0.0' plugins: {analyzeCommits: (config, cb) => cb(null, 'major')}
}, (err, type) => { }, (err, type) => {
tt.error(err) tt.error(err)
tt.is(type, 'major') tt.is(type, 'major')
@ -23,9 +23,10 @@ test('get type from commits', (t) => {
tt.plan(1) tt.plan(1)
type({ type({
analyzeCommits: (commits, cb) => cb(null, null) commits: [],
}, [], {}, lastRelease: {},
(err) => { plugins: {analyzeCommits: (config, cb) => cb(null, null)}
}, (err) => {
tt.is(err.code, 'ENOCHANGE') tt.is(err.code, 'ENOCHANGE')
}) })
}) })
@ -34,9 +35,10 @@ test('get type from commits', (t) => {
tt.plan(2) tt.plan(2)
type({ type({
analyzeCommits: (commits, cb) => cb(null, 'major') commits: [],
}, [], {}, lastRelease: {},
(err, type) => { plugins: {analyzeCommits: (config, cb) => cb(null, 'major')}
}, (err, type) => {
tt.error(err) tt.error(err)
tt.is(type, 'initial') tt.is(type, 'initial')
}) })

View File

@ -5,32 +5,35 @@ const verify = require('../../dist/lib/verify')
test('verify pkg, options and env', (t) => { test('verify pkg, options and env', (t) => {
t.test('dry run verification', (tt) => { t.test('dry run verification', (tt) => {
const noErrors = verify({ const noErrors = verify({
name: 'package', options: {debug: true},
repository: { pkg: {
url: 'http://github.com/whats/up.git' name: 'package',
repository: {
url: 'http://github.com/whats/up.git'
}
} }
}, { })
debug: true
}, {})
tt.is(noErrors.length, 0) tt.is(noErrors.length, 0)
const errors = verify({}, { const errors = verify({
debug: true options: {debug: true},
}, {}) pkg: {}
})
tt.is(errors.length, 2) tt.is(errors.length, 2)
tt.is(errors[0].code, 'ENOPKGNAME') tt.is(errors[0].code, 'ENOPKGNAME')
tt.is(errors[1].code, 'ENOPKGREPO') tt.is(errors[1].code, 'ENOPKGREPO')
const errors2 = verify({ const errors2 = verify({
name: 'package', options: {debug: true},
repository: { pkg: {
url: 'lol' name: 'package',
repository: {
url: 'lol'
}
} }
}, { })
debug: true
}, {})
tt.is(errors2.length, 1) tt.is(errors2.length, 1)
tt.is(errors2[0].code, 'EMALFORMEDPKGREPO') tt.is(errors2[0].code, 'EMALFORMEDPKGREPO')
@ -40,19 +43,19 @@ test('verify pkg, options and env', (t) => {
t.test('publish verification', (tt) => { t.test('publish verification', (tt) => {
const noErrors = verify({ const noErrors = verify({
name: 'package', env: {NPM_TOKEN: 'yo'},
repository: { options: {githubToken: 'sup'},
url: 'http://github.com/whats/up.git' pkg: {
name: 'package',
repository: {
url: 'http://github.com/whats/up.git'
}
} }
}, {
'github-token': 'sup'
}, {
NPM_TOKEN: 'yo'
}) })
tt.is(noErrors.length, 0) tt.is(noErrors.length, 0)
const errors = verify({}, {}, {}) const errors = verify({env: {}, options: {}, pkg: {}})
tt.is(errors.length, 4) tt.is(errors.length, 4)
tt.is(errors[0].code, 'ENOPKGNAME') tt.is(errors[0].code, 'ENOPKGNAME')