style: use es6 in tests

This commit is contained in:
Stephan Bönnemann 2015-06-12 13:24:44 -07:00
parent 191ae78a9f
commit 889f5f4360
14 changed files with 132 additions and 176 deletions

View File

@ -1,34 +1,32 @@
'use strict' const fs = require('fs')
const exec = require('child_process').exec
var fs = require('fs') const nixt = require('nixt')
var exec = require('child_process').exec
var nixt = require('nixt')
module.exports = function (t, message, version, code, name, cwd) { module.exports = function (t, message, version, code, name, cwd) {
t.test(name, function (t) { t.test(name, (t) => {
t.plan(3) t.plan(3)
nixt() nixt()
.cwd(cwd) .cwd(cwd)
.env('CI', true) .env('CI', true)
.env('npm_config_registry', 'http://127.0.0.1:4873/') .env('npm_config_registry', 'http://127.0.0.1:4873/')
.exec('git commit --allow-empty -m "' + message + '"') .exec(`git commit --allow-empty -m "${message}"`)
.run('npm run prepublish') .run('npm run prepublish')
.code(code) .code(code)
.stdout(/semantic-release.js pre\n\nDetermining new version\n/m) .stdout(/semantic-release.js pre\n\nDetermining new version\n/m)
.end(function (err) { .end((err) => {
t.error(err, 'nixt') t.error(err, 'nixt')
var pkg = JSON.parse(fs.readFileSync(cwd + '/package.json')) const pkg = JSON.parse(fs.readFileSync(`${cwd}/package.json`))
t.is(pkg.version, version, 'version') t.is(pkg.version, version, 'version')
if (code === 1) { if (code === 1) {
return t.error(null, 'no publish') return t.error(null, 'no publish')
} }
exec('npm publish --ignore-scripts', {cwd: cwd}, function (err) { exec('npm publish --ignore-scripts', {cwd}, (err) => {
setTimeout(function () { setTimeout(() => {
t.error(err, 'publish') t.error(err, 'publish')
}, 300) }, 300)
}) })

View File

@ -1,16 +1,14 @@
'use strict' const exec = require('child_process').exec
const join = require('path').join
var exec = require('child_process').exec const efh = require('error-first-handler')
var join = require('path').join const defaults = require('lodash.defaults')
const uid = require('nano-uid')()
var efh = require('error-first-handler')
var defaults = require('lodash.defaults')
var uid = require('nano-uid')()
module.exports = function (input) { module.exports = function (input) {
var cb = Array.prototype.pop.call(arguments) const cb = Array.prototype.pop.call(arguments)
uid.generate(5, efh(cb)(function (id) { uid.generate(5, efh(cb)((id) => {
var pkg = defaults((typeof input === 'object' ? input : {}), { const pkg = defaults((typeof input === 'object' ? input : {}), {
name: id, name: id,
version: '0.0.0', version: '0.0.0',
scripts: { scripts: {
@ -23,18 +21,18 @@ module.exports = function (input) {
}) })
id = pkg.name id = pkg.name
var cwd = join(__dirname, '../../.tmp/modules', id) const cwd = join(__dirname, '../../.tmp/modules', id)
exec( exec(
'mkdir ' + cwd + ' && ' + `mkdir ${cwd} &&
'cd ' + cwd + ' && ' + cd ${cwd} &&
'git init && ' + git init &&
'echo \'' + JSON.stringify(pkg, null, 2) + '\' >> package.json && ' + echo '${JSON.stringify(pkg, null, 2)}' >> package.json &&
'git add . && ' + git add . &&
'git config user.email "integration@test" && ' + git config user.email "integration@test" &&
'git config user.name "Integration Test" && ' + git config user.name "Integration Test" &&
'git commit -m "initial"' git commit -m "initial"`
, efh(cb)(function (stdout) { , efh(cb)((stdout) => {
cb(null, id, cwd) cb(null, id, cwd)
})) }))
})) }))

View File

@ -1,9 +1,7 @@
'use strict'
module.exports = function (commits) { module.exports = function (commits) {
var type = null let type = null
commits.every(function (commit) { commits.every((commit) => {
if (/FOO/.test(commit.message)) { if (/FOO/.test(commit.message)) {
type = 'major' type = 'major'
return false return false

View File

@ -1,5 +1,3 @@
'use strict'
module.exports = function (cb) { module.exports = function (cb) {
cb(null, 'custom log') cb(null, 'custom log')
} }

View File

@ -1,5 +1,3 @@
'use strict'
module.exports = function (opts, cb) { module.exports = function (opts, cb) {
cb(null, !(opts.commits.length % 2)) cb(null, !(opts.commits.length % 2))
} }

View File

@ -1,19 +1,17 @@
'use strict' const path = require('path')
var path = require('path') const efh = require('error-first-handler')
const test = require('tap').test
var efh = require('error-first-handler') const createModule = require('../lib/create-module')
var test = require('tap').test const commitToVersionTest = require('../lib/commit-to-version-test')
var createModule = require('../lib/create-module') test('custom-analyzer', (t) => {
var commitToVersionTest = require('../lib/commit-to-version-test')
test('custom-analyzer', function (t) {
createModule({ createModule({
release: { release: {
analyzer: path.join(__dirname, '../lib/custom-analyzer') analyzer: path.join(__dirname, '../lib/custom-analyzer')
} }
}, efh()(function (name, cwd) { }, efh()((name, cwd) => {
commitToVersionTest(t, 'HO', '0.0.0', 1, 'abort publish w/o changes', 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.0', 0, 'release 1.0.0 if unpublished', cwd)
commitToVersionTest(t, 'BAZ', '1.0.1', 0, 'bump patch for fix', cwd) commitToVersionTest(t, 'BAZ', '1.0.1', 0, 'bump patch for fix', cwd)

View File

@ -1,20 +1,18 @@
'use strict' const path = require('path')
var path = require('path') const efh = require('error-first-handler')
const nixt = require('nixt')
const test = require('tap').test
var efh = require('error-first-handler') const createModule = require('../lib/create-module')
var nixt = require('nixt')
var test = require('tap').test
var createModule = require('../lib/create-module') test('custom-verification', (t) => {
test('custom-verification', function (t) {
createModule({ createModule({
release: { release: {
verification: path.join(__dirname, '../lib/custom-verification') verification: path.join(__dirname, '../lib/custom-verification')
} }
}, efh()(function (name, cwd) { }, efh()((name, cwd) => {
t.test('even commit count', function (t) { t.test('even commit count', (t) => {
t.plan(1) t.plan(1)
nixt() nixt()
.cwd(cwd) .cwd(cwd)
@ -23,12 +21,10 @@ test('custom-verification', function (t) {
.exec('git commit --allow-empty -m "feat: commit"') .exec('git commit --allow-empty -m "feat: commit"')
.run('npm run prepublish') .run('npm run prepublish')
.code(0) .code(0)
.end(function (err) { .end((err) => t.error(err, 'nixt'))
t.error(err, 'nixt')
})
}) })
t.test('odd commit count', function (t) { t.test('odd commit count', (t) => {
t.plan(1) t.plan(1)
nixt() nixt()
.cwd(cwd) .cwd(cwd)
@ -38,9 +34,7 @@ test('custom-verification', function (t) {
.run('npm run prepublish') .run('npm run prepublish')
.code(1) .code(1)
.stdout(/Verification failed/) .stdout(/Verification failed/)
.end(function (err) { .end((err) => t.error(err, 'nixt'))
t.error(err, 'nixt')
})
}) })
})) }))
}) })

View File

@ -1,15 +1,13 @@
'use strict' const fs = require('fs')
var fs = require('fs') const efh = require('error-first-handler')
const nixt = require('nixt')
const test = require('tap').test
var efh = require('error-first-handler') const createModule = require('../lib/create-module')
var nixt = require('nixt')
var test = require('tap').test
var createModule = require('../lib/create-module') test('ignore', (t) => {
createModule(efh()((name, cwd) => {
test('ignore', function (t) {
createModule(efh()(function (name, cwd) {
ignoreTest(t, cwd, 'npm install', 'not doing anything when the module is installed') 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 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 link', 'not doing anything when the module is linked')
@ -20,18 +18,18 @@ test('ignore', function (t) {
}) })
function ignoreTest (t, cwd, command, name) { function ignoreTest (t, cwd, command, name) {
t.test(name, function (t) { t.test(name, (t) => {
t.plan(2) t.plan(2)
var pkg = fs.readFileSync(cwd + '/package.json') const pkg = String(fs.readFileSync(cwd + '/package.json'))
nixt() nixt()
.cwd(cwd) .cwd(cwd)
.run(command) .run(command)
.code(0) .code(0)
.stdout(/semantic-release.js pre\n$/m) .stdout(/semantic-release.js pre\n$/m)
.end(function (err) { .end((err) => {
t.is(pkg + '', fs.readFileSync(cwd + '/package.json') + '', 'package') t.is(pkg, String(fs.readFileSync(`${cwd}/package.json`)), 'package')
t.error(err, 'nixt') t.error(err, 'nixt')
}) })
}) })

View File

@ -1,15 +1,13 @@
'use strict' const path = require('path')
var path = require('path') const efh = require('error-first-handler')
const GitHubApi = require('github')
const nixt = require('nixt')
const test = require('tap').test
var efh = require('error-first-handler') const createModule = require('../lib/create-module')
var GitHubApi = require('github')
var nixt = require('nixt')
var test = require('tap').test
var createModule = require('../lib/create-module') const github = new GitHubApi({
var github = new GitHubApi({
version: '3.0.0', version: '3.0.0',
port: 4343, port: 4343,
protocol: 'http', protocol: 'http',
@ -21,44 +19,40 @@ github.authenticate({
token: '***' token: '***'
}) })
test('postpublish', function (t) { test('postpublish', (t) => {
createModule({ createModule({
version: '2.0.0', version: '2.0.0',
repository: { repository: {
type: 'git', type: 'git',
url: 'http://github.com/user/repo' url: 'http://github.com/user/repo'
} }
}, efh()(function (name, cwd) { }, efh()((name, cwd) => {
var base = getBase(cwd) const base = getBase(cwd)
t.test('publish new version to github releases', function (t) { t.test('publish new version to github releases', (t) => {
t.plan(1) t.plan(1)
base.clone() base.clone()
.stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m) .stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m)
.run('npm run postpublish') .run('npm run postpublish')
.end(function (err) { .end((err) => t.error(err, 'nixt'))
t.error(err, 'nixt')
})
}) })
t.test('publish new version (with detached HEAD) to github releases', function (t) { t.test('publish new version (with detached HEAD) to github releases', (t) => {
t.plan(1) t.plan(1)
base.clone() base.clone()
.stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m) .stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m)
.exec('git checkout `git rev-parse HEAD`') .exec('git checkout `git rev-parse HEAD`')
.run('npm run postpublish') .run('npm run postpublish')
.end(function (err) { .end((err) => t.error(err, 'nixt'))
t.error(err, 'nixt')
})
}) })
t.test('correct data published', function (t) { t.test('correct data published', (t) => {
t.plan(4) t.plan(4)
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, function (err, raw) { github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, (err, raw) => {
var res = JSON.parse(raw) const res = JSON.parse(raw)
t.error(err, 'github') t.error(err, 'github')
t.is(res.tag_name, 'v2.0.0', 'version') t.is(res.tag_name, 'v2.0.0', 'version')
t.is(res.author.login, 'user', 'user') t.is(res.author.login, 'user', 'user')
@ -76,24 +70,22 @@ test('postpublish', function (t) {
release: { release: {
notes: path.join(__dirname, '../lib/custom-release-notes') notes: path.join(__dirname, '../lib/custom-release-notes')
} }
}, efh()(function (name, cwd) { }, efh()((name, cwd) => {
var base = getBase(cwd) const base = getBase(cwd)
t.test('publish new version (with custom notes) to github releases', function (t) { t.test('publish new version (with custom notes) to github releases', (t) => {
t.plan(1) t.plan(1)
base.clone() base.clone()
.run('npm run postpublish') .run('npm run postpublish')
.end(function (err) { .end((err) => t.error(err, 'nixt'))
t.error(err, 'nixt')
})
}) })
t.test('custom notes published', function (t) { t.test('custom notes published', (t) => {
t.plan(4) t.plan(4)
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 3}, function (err, raw) { github.releases.getRelease({ owner: 'user', repo: 'repo', id: 3}, (err, raw) => {
var res = JSON.parse(raw) const res = JSON.parse(raw)
t.error(err, 'github') t.error(err, 'github')
t.is(res.tag_name, 'v2.0.0', 'version') t.is(res.tag_name, 'v2.0.0', 'version')
t.is(res.author.login, 'user', 'user') t.is(res.author.login, 'user', 'user')

View File

@ -1,13 +1,11 @@
'use strict' const efh = require('error-first-handler')
const test = require('tap').test
var efh = require('error-first-handler') const createModule = require('../lib/create-module')
var test = require('tap').test const commitToVersionTest = require('../lib/commit-to-version-test')
var createModule = require('../lib/create-module') test('prepublish', (t) => {
var commitToVersionTest = require('../lib/commit-to-version-test') createModule(efh()((name, cwd) => {
test('prepublish', function (t) {
createModule(efh()(function (name, cwd) {
commitToVersionTest(t, 'refactor: change', '0.0.0', 1, 'abort publish w/o changes', 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.0', 0, 'release 1.0.0 if unpublished', cwd)
commitToVersionTest(t, 'fix: change', '1.0.1', 0, 'bump patch for fix', cwd) commitToVersionTest(t, 'fix: change', '1.0.1', 0, 'bump patch for fix', cwd)

View File

@ -1,12 +1,10 @@
'use strict' const efh = require('error-first-handler')
const nixt = require('nixt')
const test = require('tap').test
var efh = require('error-first-handler') const createModule = require('../lib/create-module')
var nixt = require('nixt')
var test = require('tap').test
var createModule = require('../lib/create-module') test('publish', (t) => {
test('publish', function (t) {
publishTest(t, 'npm publish', 'pre and post hooks work as a part of publish') 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') publishTest(t, 'npm pub', 'pre and post hooks work as a part of publish with abbrevd command')
@ -16,8 +14,8 @@ test('publish', function (t) {
type: 'git', type: 'git',
url: 'http://github.com/user/repo' url: 'http://github.com/user/repo'
} }
}, efh()(function (name, cwd) { }, efh()((name, cwd) => {
t.test(testname, function (t) { t.test(testname, (t) => {
t.plan(1) t.plan(1)
nixt() nixt()
@ -29,9 +27,7 @@ test('publish', function (t) {
.run(command) .run(command)
.code(1) .code(1)
.stdout(/Everything is alright/) .stdout(/Everything is alright/)
.end(function (err) { .end((err) => t.error(err, 'nixt'))
t.error(err, 'nixt')
})
}) })
})) }))
} }

View File

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

View File

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

View File

@ -1,13 +1,11 @@
'use strict' const test = require('tap').test
const nock = require('nock')
var test = require('tap').test const npmInfo = require('../../dist/lib/npm-info.js')
var nock = require('nock')
var npmInfo = require('../../dist/lib/npm-info.js') const registry = 'http://registry.npmjs.org/'
var registry = 'http://registry.npmjs.org/' const defaultModule = {
var defaultModule = {
'dist-tags': { 'dist-tags': {
latest: '1.0.0' latest: '1.0.0'
}, },
@ -20,8 +18,8 @@ var defaultModule = {
process.env.npm_config_registry = registry process.env.npm_config_registry = registry
test('npm-info', function (t) { test('npm-info', (t) => {
var regMock = nock(registry, { const regMock = nock(registry, {
reqheaders: { reqheaders: {
'authorization': 'Bearer testtoken' 'authorization': 'Bearer testtoken'
} }
@ -31,17 +29,17 @@ test('npm-info', function (t) {
.get('/@user%2Fmodule') .get('/@user%2Fmodule')
.reply(200, defaultModule) .reply(200, defaultModule)
t.test('get unscoped module', function (t) { t.test('get unscoped module', (t) => {
t.plan(3) t.plan(3)
npmInfo('express', function (err, info) { npmInfo('express', (err, info) => {
t.error(err, 'error') t.error(err, 'error')
t.is(info.version, '1.0.0', 'version') t.is(info.version, '1.0.0', 'version')
t.is(info.gitHead, 'HEAD', 'gitHead') t.is(info.gitHead, 'HEAD', 'gitHead')
}) })
}) })
t.test('get scoped module', function (t) { t.test('get scoped module', (t) => {
t.plan(3) t.plan(3)
npmInfo('@user/module', function (err, info) { npmInfo('@user/module', (err, info) => {
t.error(err, 'error') t.error(err, 'error')
t.is(info.version, '1.0.0', 'version') t.is(info.version, '1.0.0', 'version')
t.is(info.gitHead, 'HEAD', 'gitHead') t.is(info.gitHead, 'HEAD', 'gitHead')