test: convert from tape to tap

This commit is contained in:
Stephan Bönnemann 2015-06-11 17:07:09 -07:00
parent 649af78c56
commit 4e90e4b98b
11 changed files with 241 additions and 273 deletions

View File

@ -31,8 +31,7 @@
"nock": "^2.2.0",
"sinopia": "^1.0.0",
"standard": "^4.0.1",
"tap-spec": "^4.0.0",
"tape": "^4.0.0"
"tap": "^1.2.0"
},
"engines": {
"iojs": "^1",
@ -69,7 +68,7 @@
"prepublish": "npm run build && ./bin/semantic-release.js pre",
"pretest": "npm run build",
"test": "./bin/test",
"test:integration": "node tests | tap-spec",
"test:integration": "tap tests/{scenarios,tap}/*.js",
"test:style": "standard"
}
}

View File

@ -1,11 +0,0 @@
'use strict'
require('./tap/npm-info')()
require('./scenarios/custom-analyzer')()
require('./scenarios/custom-verification')()
require('./scenarios/ignore')()
require('./scenarios/prepublish')()
require('./scenarios/postpublish')()
require('./scenarios/publish')()
require('./scenarios/verify')()
require('./scenarios/setup')()

View File

@ -3,23 +3,21 @@
var path = require('path')
var efh = require('error-first-handler')
var test = require('tape')
var test = require('tap').test
var createModule = require('../lib/create-module')
var commitToVersionTest = require('../lib/commit-to-version-test')
module.exports = function () {
test('custom-analyzer', function (t) {
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)
})
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)
}))
}
})

View File

@ -4,45 +4,43 @@ var path = require('path')
var efh = require('error-first-handler')
var nixt = require('nixt')
var test = require('tape')
var test = require('tap').test
var createModule = require('../lib/create-module')
module.exports = function () {
test('custom-verification', function (t) {
createModule({
release: {
verification: path.join(__dirname, '../lib/custom-verification')
}
}, efh()(function (name, cwd) {
test('custom-verification', function (t) {
t.test('even commit count', function (t) {
t.plan(1)
nixt()
.cwd(cwd)
.env('CI', true)
.env('npm_config_registry', 'http://127.0.0.1:4873/')
.exec('git commit --allow-empty -m "feat: commit"')
.run('npm run prepublish')
.code(0)
.end(function (err) {
t.error(err, 'nixt')
})
})
t.test('even commit count', function (t) {
t.plan(1)
nixt()
.cwd(cwd)
.env('CI', true)
.env('npm_config_registry', 'http://127.0.0.1:4873/')
.exec('git commit --allow-empty -m "feat: commit"')
.run('npm run prepublish')
.code(0)
.end(function (err) {
t.error(err, 'nixt')
})
})
t.test('odd commit count', function (t) {
t.plan(1)
nixt()
.cwd(cwd)
.env('CI', true)
.env('npm_config_registry', 'http://127.0.0.1:4873/')
.exec('git commit --allow-empty -m "feat: commit"')
.run('npm run prepublish')
.code(1)
.stdout(/Verification failed/)
.end(function (err) {
t.error(err, 'nixt')
})
})
t.test('odd commit count', function (t) {
t.plan(1)
nixt()
.cwd(cwd)
.env('CI', true)
.env('npm_config_registry', 'http://127.0.0.1:4873/')
.exec('git commit --allow-empty -m "feat: commit"')
.run('npm run prepublish')
.code(1)
.stdout(/Verification failed/)
.end(function (err) {
t.error(err, 'nixt')
})
})
}))
}
})

View File

@ -4,37 +4,35 @@ var fs = require('fs')
var efh = require('error-first-handler')
var nixt = require('nixt')
var test = require('tape')
var test = require('tap').test
var createModule = require('../lib/create-module')
module.exports = function () {
test('ignore', function (t) {
createModule(efh()(function (name, cwd) {
test('ignore', function (t) {
ignoreTest(t, 'npm install', 'not doing anything when the module is installed')
ignoreTest(t, 'npm i', 'not doing anything when the module is installed with abbrevd command')
ignoreTest(t, 'npm link', 'not doing anything when the module is linked')
ignoreTest(t, 'npm lin', 'not doing anything when the module is linked with abbrevd command')
ignoreTest(t, 'npm pack', 'not doing anything when the module is packed')
ignoreTest(t, 'npm pa', 'not doing anything when the module is packed with abbrevd command')
})
function ignoreTest (t, command, name, last) {
t.test(name, function (t) {
t.plan(2)
var pkg = fs.readFileSync(cwd + '/package.json')
nixt()
.cwd(cwd)
.run(command)
.code(0)
.stdout(/semantic-release.js pre\n$/m)
.end(function (err) {
t.is(pkg + '', fs.readFileSync(cwd + '/package.json') + '', 'package')
t.error(err, 'nixt')
})
})
}
ignoreTest(t, cwd, 'npm install', 'not doing anything when the module is installed')
ignoreTest(t, cwd, 'npm i', 'not doing anything when the module is installed with abbrevd command')
ignoreTest(t, cwd, 'npm link', 'not doing anything when the module is linked')
ignoreTest(t, cwd, 'npm lin', 'not doing anything when the module is linked with abbrevd command')
ignoreTest(t, cwd, 'npm pack', 'not doing anything when the module is packed')
ignoreTest(t, cwd, 'npm pa', 'not doing anything when the module is packed with abbrevd command')
}))
})
function ignoreTest (t, cwd, command, name) {
t.test(name, function (t) {
t.plan(2)
var pkg = fs.readFileSync(cwd + '/package.json')
nixt()
.cwd(cwd)
.run(command)
.code(0)
.stdout(/semantic-release.js pre\n$/m)
.end(function (err) {
t.is(pkg + '', fs.readFileSync(cwd + '/package.json') + '', 'package')
t.error(err, 'nixt')
})
})
}

View File

@ -5,7 +5,7 @@ var path = require('path')
var efh = require('error-first-handler')
var GitHubApi = require('github')
var nixt = require('nixt')
var test = require('tape')
var test = require('tap').test
var createModule = require('../lib/create-module')
@ -21,7 +21,7 @@ github.authenticate({
token: '***'
})
module.exports = function () {
test('postpublish', function (t) {
createModule({
version: '2.0.0',
repository: {
@ -29,42 +29,40 @@ module.exports = function () {
url: 'http://github.com/user/repo'
}
}, efh()(function (name, cwd) {
test('postpublish', function (t) {
var base = getBase(cwd)
var base = getBase(cwd)
t.test('publish new version to github releases', function (t) {
t.plan(1)
t.test('publish new version to github releases', function (t) {
t.plan(1)
base.clone()
.stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m)
.run('npm run postpublish')
.end(function (err) {
t.error(err, 'nixt')
})
})
t.test('publish new version (with detached HEAD) to github releases', function (t) {
t.plan(1)
base.clone()
.stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m)
.exec('git checkout `git rev-parse HEAD`')
.run('npm run postpublish')
.end(function (err) {
t.error(err, 'nixt')
})
})
t.test('correct data published', function (t) {
t.plan(4)
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, function (err, raw) {
var res = JSON.parse(raw)
t.error(err, 'github')
t.is(res.tag_name, 'v2.0.0', 'version')
t.is(res.author.login, 'user', 'user')
t.ok(/\n\n\n#### Features\n\n\* \*\*cool:\*\*\n.*the next big thing/.test(res.body), 'body')
base.clone()
.stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m)
.run('npm run postpublish')
.end(function (err) {
t.error(err, 'nixt')
})
})
t.test('publish new version (with detached HEAD) to github releases', function (t) {
t.plan(1)
base.clone()
.stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m)
.exec('git checkout `git rev-parse HEAD`')
.run('npm run postpublish')
.end(function (err) {
t.error(err, 'nixt')
})
})
t.test('correct data published', function (t) {
t.plan(4)
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, function (err, raw) {
var res = JSON.parse(raw)
t.error(err, 'github')
t.is(res.tag_name, 'v2.0.0', 'version')
t.is(res.author.login, 'user', 'user')
t.ok(/\n\n\n#### Features\n\n\* \*\*cool:\*\*\n.*the next big thing/.test(res.body), 'body')
})
})
}))
@ -79,33 +77,31 @@ module.exports = function () {
notes: path.join(__dirname, '../lib/custom-release-notes')
}
}, efh()(function (name, cwd) {
test('custom-release-notes', function (t) {
var base = getBase(cwd)
var base = getBase(cwd)
t.test('publish new version (with custom notes) to github releases', function (t) {
t.plan(1)
t.test('publish new version (with custom notes) to github releases', function (t) {
t.plan(1)
base.clone()
.run('npm run postpublish')
.end(function (err) {
t.error(err, 'nixt')
})
})
t.test('custom notes published', function (t) {
t.plan(4)
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 3}, function (err, raw) {
var res = JSON.parse(raw)
t.error(err, 'github')
t.is(res.tag_name, 'v2.0.0', 'version')
t.is(res.author.login, 'user', 'user')
t.ok(/custom log/.test(res.body), 'body')
base.clone()
.run('npm run postpublish')
.end(function (err) {
t.error(err, 'nixt')
})
})
t.test('custom notes published', function (t) {
t.plan(4)
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 3}, function (err, raw) {
var res = JSON.parse(raw)
t.error(err, 'github')
t.is(res.tag_name, 'v2.0.0', 'version')
t.is(res.author.login, 'user', 'user')
t.ok(/custom log/.test(res.body), 'body')
})
})
}))
}
})
function getBase (cwd) {
return nixt()

View File

@ -1,19 +1,17 @@
'use strict'
var efh = require('error-first-handler')
var test = require('tape')
var test = require('tap').test
var createModule = require('../lib/create-module')
var commitToVersionTest = require('../lib/commit-to-version-test')
module.exports = function () {
test('prepublish', function (t) {
createModule(efh()(function (name, cwd) {
test('prepublish', function (t) {
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)
})
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)
}))
}
})

View File

@ -2,39 +2,37 @@
var efh = require('error-first-handler')
var nixt = require('nixt')
var test = require('tape')
var test = require('tap').test
var createModule = require('../lib/create-module')
module.exports = function () {
test('publish', function (t) {
publishTest(t, 'npm publish', 'pre and post hooks work as a part of publish')
publishTest(t, 'npm pub', 'pre and post hooks work as a part of publish with abbrevd command')
test('publish', function (t) {
publishTest(t, 'npm publish', 'pre and post hooks work as a part of publish')
publishTest(t, 'npm pub', 'pre and post hooks work as a part of publish with abbrevd command')
function publishTest (t, command, testname, last) {
createModule({
repository: {
type: 'git',
url: 'http://github.com/user/repo'
}
}, efh()(function (name, cwd) {
t.test(testname, function (t) {
t.plan(1)
function publishTest (t, command, testname, last) {
createModule({
repository: {
type: 'git',
url: 'http://github.com/user/repo'
}
}, efh()(function (name, cwd) {
t.test(testname, function (t) {
t.plan(1)
nixt()
.cwd(cwd)
.env('CI', true)
.env('GH_URL', 'http://127.0.0.1:4343/')
.env('GH_TOKEN', '***')
.exec('git commit --allow-empty -m "feat: super"')
.run(command)
.code(1)
.stdout(/Everything is alright/)
.end(function (err) {
t.error(err, 'nixt')
})
})
}))
}
})
}
nixt()
.cwd(cwd)
.env('CI', true)
.env('GH_URL', 'http://127.0.0.1:4343/')
.env('GH_TOKEN', '***')
.exec('git commit --allow-empty -m "feat: super"')
.run(command)
.code(1)
.stdout(/Everything is alright/)
.end(function (err) {
t.error(err, 'nixt')
})
})
}))
}
})

View File

@ -5,37 +5,35 @@ var readFile = require('fs').readFileSync
var efh = require('error-first-handler')
var nixt = require('nixt')
var test = require('tape')
var test = require('tap').test
var createModule = require('../lib/create-module')
module.exports = function () {
test('setup', function (t) {
createModule({
repository: {},
scripts: {
postpublish: 'npm run gh-pages'
}
}, efh()(function (name, cwd) {
test('setup', function (t) {
t.test('setup "package.json"', function (t) {
t.plan(5)
t.test('setup "package.json"', function (t) {
t.plan(5)
nixt()
.cwd(cwd)
.exec('git remote add origin git@github.com:user/repo.git')
.run('../../../bin/semantic-release.js setup')
.code(0)
.end(function (err) {
t.error(err, 'nixt')
nixt()
.cwd(cwd)
.exec('git remote add origin git@github.com:user/repo.git')
.run('../../../bin/semantic-release.js setup')
.code(0)
.end(function (err) {
t.error(err, 'nixt')
var pkg = JSON.parse(readFile(join(cwd, 'package.json')))
var pkg = JSON.parse(readFile(join(cwd, 'package.json')))
t.is(pkg.version, '0.0.0-semantically-released', 'version')
t.is(pkg.repository.url, 'https://github.com/user/repo', 'repo')
t.is(pkg.scripts.prepublish, 'semantic-release pre', 'pre')
t.is(pkg.scripts.postpublish, 'npm run gh-pages && semantic-release post', 'post')
})
})
t.is(pkg.version, '0.0.0-semantically-released', 'version')
t.is(pkg.repository.url, 'https://github.com/user/repo', 'repo')
t.is(pkg.scripts.prepublish, 'semantic-release pre', 'pre')
t.is(pkg.scripts.postpublish, 'npm run gh-pages && semantic-release post', 'post')
})
})
}))
}
})

View File

@ -2,52 +2,50 @@
var efh = require('error-first-handler')
var nixt = require('nixt')
var test = require('tape')
var test = require('tap').test
var createModule = require('../lib/create-module')
module.exports = function () {
test('verify', function (t) {
createModule({
repository: {},
scripts: {
prepublish: '../../../bin/semantic-release.js pre'
}
}, efh()(function (name, cwd) {
t.test('verify package and options before publishing', function (t) {
t.plan(1)
nixt()
.cwd(cwd)
.env('CI', true)
.run('npm publish')
.stderr(new RegExp(
'You must define a GitHub token\.\n' +
'You must define your GitHub "repository" inside the "package.json"\.\n' +
'You must define your "scripts" inside the "package.json"\.'
, 'm'
))
.code(1)
.end(function (err) {
t.error(err, 'nixt')
})
})
}))
test('verify', function (t) {
createModule({
repository: {},
scripts: {
prepublish: '../../../bin/semantic-release.js pre --no-token'
}
}, efh()(function (name, cwd) {
t.test('verify package and options before publishing', function (t) {
t.plan(1)
nixt()
.cwd(cwd)
.env('CI', true)
.run('npm publish')
.stderr(new RegExp(
'You must define a GitHub token\.\n' +
'You must define your GitHub "repository" inside the "package.json"\.\n' +
'You must define your "scripts" inside the "package.json"\.'
, 'm'
))
.code(1)
.end(function (err) {
t.error(err, 'nixt')
})
})
}))
createModule({
version: '1.0.0-semantically-released'
}, efh()(function (name, cwd) {
t.test('not publishing placeholder versions', function (t) {
t.plan(1)
createModule({
version: '1.0.0-semantically-released'
}, efh()(function (name, cwd) {
t.test('not publishing placeholder versions', function (t) {
t.plan(1)
nixt()
.cwd(cwd)
.env('CI', true)
.run('npm publish --semantic-release-rerun')
.code(1)
.end(function (err) {
t.error(err, 'nixt')
})
})
}))
})
}
nixt()
.cwd(cwd)
.env('CI', true)
.run('npm publish --semantic-release-rerun')
.code(1)
.end(function (err) {
t.error(err, 'nixt')
})
})
}))
})

View File

@ -1,6 +1,6 @@
'use strict'
var test = require('tape')
var test = require('tap').test
var nock = require('nock')
var npmInfo = require('../../dist/lib/npm-info.js')
@ -20,34 +20,32 @@ var defaultModule = {
process.env.npm_config_registry = registry
module.exports = function () {
test('npm-info', function (t) {
var regMock = nock(registry, {
reqheaders: {
'authorization': 'Bearer testtoken'
}
})
.get('/express')
.reply(200, defaultModule)
.get('/@user%2Fmodule')
.reply(200, defaultModule)
test('npm-info', function (t) {
var regMock = nock(registry, {
reqheaders: {
'authorization': 'Bearer testtoken'
}
})
.get('/express')
.reply(200, defaultModule)
.get('/@user%2Fmodule')
.reply(200, defaultModule)
t.test('get unscoped module', function (t) {
t.plan(3)
npmInfo('express', function (err, info) {
t.error(err, 'error')
t.is(info.version, '1.0.0', 'version')
t.is(info.gitHead, 'HEAD', 'gitHead')
})
})
t.test('get scoped module', function (t) {
t.plan(3)
npmInfo('@user/module', function (err, info) {
t.error(err, 'error')
t.is(info.version, '1.0.0', 'version')
t.is(info.gitHead, 'HEAD', 'gitHead')
regMock.done()
})
t.test('get unscoped module', function (t) {
t.plan(3)
npmInfo('express', function (err, info) {
t.error(err, 'error')
t.is(info.version, '1.0.0', 'version')
t.is(info.gitHead, 'HEAD', 'gitHead')
})
})
}
t.test('get scoped module', function (t) {
t.plan(3)
npmInfo('@user/module', function (err, info) {
t.error(err, 'error')
t.is(info.version, '1.0.0', 'version')
t.is(info.gitHead, 'HEAD', 'gitHead')
regMock.done()
})
})
})