diff --git a/package.json b/package.json index 09252f93..496cb443 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/tests/index.js b/tests/index.js deleted file mode 100644 index e9c1c42d..00000000 --- a/tests/index.js +++ /dev/null @@ -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')() diff --git a/tests/scenarios/custom-analyzer.js b/tests/scenarios/custom-analyzer.js index aa38ce55..6a1f53be 100644 --- a/tests/scenarios/custom-analyzer.js +++ b/tests/scenarios/custom-analyzer.js @@ -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) })) -} +}) diff --git a/tests/scenarios/custom-verification.js b/tests/scenarios/custom-verification.js index 4f7b9f3f..e9b9df88 100644 --- a/tests/scenarios/custom-verification.js +++ b/tests/scenarios/custom-verification.js @@ -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') + }) }) })) -} +}) diff --git a/tests/scenarios/ignore.js b/tests/scenarios/ignore.js index 6190be7b..c92e063d 100644 --- a/tests/scenarios/ignore.js +++ b/tests/scenarios/ignore.js @@ -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') + }) + }) } diff --git a/tests/scenarios/postpublish.js b/tests/scenarios/postpublish.js index 739fd186..0f5096cc 100644 --- a/tests/scenarios/postpublish.js +++ b/tests/scenarios/postpublish.js @@ -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() diff --git a/tests/scenarios/prepublish.js b/tests/scenarios/prepublish.js index bda3d788..fdaf6aea 100644 --- a/tests/scenarios/prepublish.js +++ b/tests/scenarios/prepublish.js @@ -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) })) -} +}) diff --git a/tests/scenarios/publish.js b/tests/scenarios/publish.js index 9fd03029..e7901774 100644 --- a/tests/scenarios/publish.js +++ b/tests/scenarios/publish.js @@ -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') + }) + }) + })) + } +}) diff --git a/tests/scenarios/setup.js b/tests/scenarios/setup.js index 01befe6e..c82107b1 100644 --- a/tests/scenarios/setup.js +++ b/tests/scenarios/setup.js @@ -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') + }) }) })) -} +}) diff --git a/tests/scenarios/verify.js b/tests/scenarios/verify.js index a1b86b61..ab679b18 100644 --- a/tests/scenarios/verify.js +++ b/tests/scenarios/verify.js @@ -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') + }) + }) + })) +}) diff --git a/tests/tap/npm-info.js b/tests/tap/npm-info.js index 732dcc5d..ca3b8e25 100644 --- a/tests/tap/npm-info.js +++ b/tests/tap/npm-info.js @@ -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() + }) + }) +})