style: use es6 in tests
This commit is contained in:
parent
191ae78a9f
commit
889f5f4360
@ -1,34 +1,32 @@
|
||||
'use strict'
|
||||
const fs = require('fs')
|
||||
const exec = require('child_process').exec
|
||||
|
||||
var fs = require('fs')
|
||||
var exec = require('child_process').exec
|
||||
|
||||
var nixt = require('nixt')
|
||||
const nixt = require('nixt')
|
||||
|
||||
module.exports = function (t, message, version, code, name, cwd) {
|
||||
t.test(name, function (t) {
|
||||
t.test(name, (t) => {
|
||||
t.plan(3)
|
||||
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
.env('CI', true)
|
||||
.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')
|
||||
.code(code)
|
||||
.stdout(/semantic-release.js pre\n\nDetermining new version\n/m)
|
||||
.end(function (err) {
|
||||
.end((err) => {
|
||||
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')
|
||||
|
||||
if (code === 1) {
|
||||
return t.error(null, 'no publish')
|
||||
}
|
||||
|
||||
exec('npm publish --ignore-scripts', {cwd: cwd}, function (err) {
|
||||
setTimeout(function () {
|
||||
exec('npm publish --ignore-scripts', {cwd}, (err) => {
|
||||
setTimeout(() => {
|
||||
t.error(err, 'publish')
|
||||
}, 300)
|
||||
})
|
||||
|
@ -1,16 +1,14 @@
|
||||
'use strict'
|
||||
const exec = require('child_process').exec
|
||||
const join = require('path').join
|
||||
|
||||
var exec = require('child_process').exec
|
||||
var join = require('path').join
|
||||
|
||||
var efh = require('error-first-handler')
|
||||
var defaults = require('lodash.defaults')
|
||||
var uid = require('nano-uid')()
|
||||
const efh = require('error-first-handler')
|
||||
const defaults = require('lodash.defaults')
|
||||
const uid = require('nano-uid')()
|
||||
|
||||
module.exports = function (input) {
|
||||
var cb = Array.prototype.pop.call(arguments)
|
||||
uid.generate(5, efh(cb)(function (id) {
|
||||
var pkg = defaults((typeof input === 'object' ? input : {}), {
|
||||
const cb = Array.prototype.pop.call(arguments)
|
||||
uid.generate(5, efh(cb)((id) => {
|
||||
const pkg = defaults((typeof input === 'object' ? input : {}), {
|
||||
name: id,
|
||||
version: '0.0.0',
|
||||
scripts: {
|
||||
@ -23,18 +21,18 @@ module.exports = function (input) {
|
||||
})
|
||||
|
||||
id = pkg.name
|
||||
var cwd = join(__dirname, '../../.tmp/modules', id)
|
||||
const cwd = join(__dirname, '../../.tmp/modules', id)
|
||||
|
||||
exec(
|
||||
'mkdir ' + cwd + ' && ' +
|
||||
'cd ' + cwd + ' && ' +
|
||||
'git init && ' +
|
||||
'echo \'' + JSON.stringify(pkg, null, 2) + '\' >> package.json && ' +
|
||||
'git add . && ' +
|
||||
'git config user.email "integration@test" && ' +
|
||||
'git config user.name "Integration Test" && ' +
|
||||
'git commit -m "initial"'
|
||||
, efh(cb)(function (stdout) {
|
||||
`mkdir ${cwd} &&
|
||||
cd ${cwd} &&
|
||||
git init &&
|
||||
echo '${JSON.stringify(pkg, null, 2)}' >> package.json &&
|
||||
git add . &&
|
||||
git config user.email "integration@test" &&
|
||||
git config user.name "Integration Test" &&
|
||||
git commit -m "initial"`
|
||||
, efh(cb)((stdout) => {
|
||||
cb(null, id, cwd)
|
||||
}))
|
||||
}))
|
||||
|
@ -1,9 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = function (commits) {
|
||||
var type = null
|
||||
let type = null
|
||||
|
||||
commits.every(function (commit) {
|
||||
commits.every((commit) => {
|
||||
if (/FOO/.test(commit.message)) {
|
||||
type = 'major'
|
||||
return false
|
||||
|
@ -1,5 +1,3 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = function (cb) {
|
||||
cb(null, 'custom log')
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = function (opts, cb) {
|
||||
cb(null, !(opts.commits.length % 2))
|
||||
}
|
||||
|
@ -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')
|
||||
var test = require('tap').test
|
||||
const createModule = require('../lib/create-module')
|
||||
const commitToVersionTest = require('../lib/commit-to-version-test')
|
||||
|
||||
var createModule = require('../lib/create-module')
|
||||
var commitToVersionTest = require('../lib/commit-to-version-test')
|
||||
|
||||
test('custom-analyzer', function (t) {
|
||||
test('custom-analyzer', (t) => {
|
||||
createModule({
|
||||
release: {
|
||||
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, 'BAZ', '1.0.0', 0, 'release 1.0.0 if unpublished', cwd)
|
||||
commitToVersionTest(t, 'BAZ', '1.0.1', 0, 'bump patch for fix', cwd)
|
||||
|
@ -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')
|
||||
var nixt = require('nixt')
|
||||
var test = require('tap').test
|
||||
const createModule = require('../lib/create-module')
|
||||
|
||||
var createModule = require('../lib/create-module')
|
||||
|
||||
test('custom-verification', function (t) {
|
||||
test('custom-verification', (t) => {
|
||||
createModule({
|
||||
release: {
|
||||
verification: path.join(__dirname, '../lib/custom-verification')
|
||||
}
|
||||
}, efh()(function (name, cwd) {
|
||||
t.test('even commit count', function (t) {
|
||||
}, efh()((name, cwd) => {
|
||||
t.test('even commit count', (t) => {
|
||||
t.plan(1)
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
@ -23,12 +21,10 @@ test('custom-verification', function (t) {
|
||||
.exec('git commit --allow-empty -m "feat: commit"')
|
||||
.run('npm run prepublish')
|
||||
.code(0)
|
||||
.end(function (err) {
|
||||
t.error(err, 'nixt')
|
||||
})
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
|
||||
t.test('odd commit count', function (t) {
|
||||
t.test('odd commit count', (t) => {
|
||||
t.plan(1)
|
||||
nixt()
|
||||
.cwd(cwd)
|
||||
@ -38,9 +34,7 @@ test('custom-verification', function (t) {
|
||||
.run('npm run prepublish')
|
||||
.code(1)
|
||||
.stdout(/Verification failed/)
|
||||
.end(function (err) {
|
||||
t.error(err, 'nixt')
|
||||
})
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
@ -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')
|
||||
var nixt = require('nixt')
|
||||
var test = require('tap').test
|
||||
const createModule = require('../lib/create-module')
|
||||
|
||||
var createModule = require('../lib/create-module')
|
||||
|
||||
test('ignore', function (t) {
|
||||
createModule(efh()(function (name, cwd) {
|
||||
test('ignore', (t) => {
|
||||
createModule(efh()((name, cwd) => {
|
||||
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')
|
||||
@ -20,18 +18,18 @@ test('ignore', function (t) {
|
||||
})
|
||||
|
||||
function ignoreTest (t, cwd, command, name) {
|
||||
t.test(name, function (t) {
|
||||
t.test(name, (t) => {
|
||||
t.plan(2)
|
||||
|
||||
var pkg = fs.readFileSync(cwd + '/package.json')
|
||||
const pkg = String(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')
|
||||
.end((err) => {
|
||||
t.is(pkg, String(fs.readFileSync(`${cwd}/package.json`)), 'package')
|
||||
t.error(err, 'nixt')
|
||||
})
|
||||
})
|
||||
|
@ -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')
|
||||
var GitHubApi = require('github')
|
||||
var nixt = require('nixt')
|
||||
var test = require('tap').test
|
||||
const createModule = require('../lib/create-module')
|
||||
|
||||
var createModule = require('../lib/create-module')
|
||||
|
||||
var github = new GitHubApi({
|
||||
const github = new GitHubApi({
|
||||
version: '3.0.0',
|
||||
port: 4343,
|
||||
protocol: 'http',
|
||||
@ -21,44 +19,40 @@ github.authenticate({
|
||||
token: '***'
|
||||
})
|
||||
|
||||
test('postpublish', function (t) {
|
||||
test('postpublish', (t) => {
|
||||
createModule({
|
||||
version: '2.0.0',
|
||||
repository: {
|
||||
type: 'git',
|
||||
url: 'http://github.com/user/repo'
|
||||
}
|
||||
}, efh()(function (name, cwd) {
|
||||
var base = getBase(cwd)
|
||||
}, efh()((name, 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)
|
||||
|
||||
base.clone()
|
||||
.stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m)
|
||||
.run('npm run postpublish')
|
||||
.end(function (err) {
|
||||
t.error(err, 'nixt')
|
||||
})
|
||||
.end((err) => 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)
|
||||
|
||||
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')
|
||||
})
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
|
||||
t.test('correct data published', function (t) {
|
||||
t.test('correct data published', (t) => {
|
||||
t.plan(4)
|
||||
|
||||
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, function (err, raw) {
|
||||
var res = JSON.parse(raw)
|
||||
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, (err, raw) => {
|
||||
const res = JSON.parse(raw)
|
||||
t.error(err, 'github')
|
||||
t.is(res.tag_name, 'v2.0.0', 'version')
|
||||
t.is(res.author.login, 'user', 'user')
|
||||
@ -76,24 +70,22 @@ test('postpublish', function (t) {
|
||||
release: {
|
||||
notes: path.join(__dirname, '../lib/custom-release-notes')
|
||||
}
|
||||
}, efh()(function (name, cwd) {
|
||||
var base = getBase(cwd)
|
||||
}, efh()((name, 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)
|
||||
|
||||
base.clone()
|
||||
.run('npm run postpublish')
|
||||
.end(function (err) {
|
||||
t.error(err, 'nixt')
|
||||
})
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
|
||||
t.test('custom notes published', function (t) {
|
||||
t.test('custom notes published', (t) => {
|
||||
t.plan(4)
|
||||
|
||||
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 3}, function (err, raw) {
|
||||
var res = JSON.parse(raw)
|
||||
github.releases.getRelease({ owner: 'user', repo: 'repo', id: 3}, (err, raw) => {
|
||||
const res = JSON.parse(raw)
|
||||
t.error(err, 'github')
|
||||
t.is(res.tag_name, 'v2.0.0', 'version')
|
||||
t.is(res.author.login, 'user', 'user')
|
||||
|
@ -1,13 +1,11 @@
|
||||
'use strict'
|
||||
const efh = require('error-first-handler')
|
||||
const test = require('tap').test
|
||||
|
||||
var efh = require('error-first-handler')
|
||||
var test = require('tap').test
|
||||
const createModule = require('../lib/create-module')
|
||||
const commitToVersionTest = require('../lib/commit-to-version-test')
|
||||
|
||||
var createModule = require('../lib/create-module')
|
||||
var commitToVersionTest = require('../lib/commit-to-version-test')
|
||||
|
||||
test('prepublish', function (t) {
|
||||
createModule(efh()(function (name, cwd) {
|
||||
test('prepublish', (t) => {
|
||||
createModule(efh()((name, 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)
|
||||
|
@ -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')
|
||||
var nixt = require('nixt')
|
||||
var test = require('tap').test
|
||||
const createModule = require('../lib/create-module')
|
||||
|
||||
var createModule = require('../lib/create-module')
|
||||
|
||||
test('publish', function (t) {
|
||||
test('publish', (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')
|
||||
|
||||
@ -16,8 +14,8 @@ test('publish', function (t) {
|
||||
type: 'git',
|
||||
url: 'http://github.com/user/repo'
|
||||
}
|
||||
}, efh()(function (name, cwd) {
|
||||
t.test(testname, function (t) {
|
||||
}, efh()((name, cwd) => {
|
||||
t.test(testname, (t) => {
|
||||
t.plan(1)
|
||||
|
||||
nixt()
|
||||
@ -29,9 +27,7 @@ test('publish', function (t) {
|
||||
.run(command)
|
||||
.code(1)
|
||||
.stdout(/Everything is alright/)
|
||||
.end(function (err) {
|
||||
t.error(err, 'nixt')
|
||||
})
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
@ -1,22 +1,20 @@
|
||||
'use strict'
|
||||
const join = require('path').join
|
||||
const readFile = require('fs').readFileSync
|
||||
|
||||
var join = require('path').join
|
||||
var readFile = require('fs').readFileSync
|
||||
const efh = require('error-first-handler')
|
||||
const nixt = require('nixt')
|
||||
const test = require('tap').test
|
||||
|
||||
var efh = require('error-first-handler')
|
||||
var nixt = require('nixt')
|
||||
var test = require('tap').test
|
||||
const createModule = require('../lib/create-module')
|
||||
|
||||
var createModule = require('../lib/create-module')
|
||||
|
||||
test('setup', function (t) {
|
||||
test('setup', (t) => {
|
||||
createModule({
|
||||
repository: {},
|
||||
scripts: {
|
||||
postpublish: 'npm run gh-pages'
|
||||
}
|
||||
}, efh()(function (name, cwd) {
|
||||
t.test('setup "package.json"', function (t) {
|
||||
}, efh()((name, cwd) => {
|
||||
t.test('setup "package.json"', (t) => {
|
||||
t.plan(5)
|
||||
|
||||
nixt()
|
||||
@ -24,10 +22,10 @@ test('setup', function (t) {
|
||||
.exec('git remote add origin git@github.com:user/repo.git')
|
||||
.run('../../../bin/semantic-release.js setup')
|
||||
.code(0)
|
||||
.end(function (err) {
|
||||
.end((err) => {
|
||||
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.repository.url, 'https://github.com/user/repo', 'repo')
|
||||
|
@ -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')
|
||||
var nixt = require('nixt')
|
||||
var test = require('tap').test
|
||||
const createModule = require('../lib/create-module')
|
||||
|
||||
var createModule = require('../lib/create-module')
|
||||
|
||||
test('verify', function (t) {
|
||||
test('verify', (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) {
|
||||
}, efh()((name, cwd) => {
|
||||
t.test('verify package and options before publishing', (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"\.'
|
||||
`You must define a GitHub token\.
|
||||
You must define your GitHub "repository" inside the "package.json"\.
|
||||
You must define your "scripts" inside the "package.json"\.`
|
||||
, 'm'
|
||||
))
|
||||
.code(1)
|
||||
.end(function (err) {
|
||||
t.error(err, 'nixt')
|
||||
})
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
}))
|
||||
|
||||
createModule({
|
||||
version: '1.0.0-semantically-released'
|
||||
}, efh()(function (name, cwd) {
|
||||
t.test('not publishing placeholder versions', function (t) {
|
||||
}, efh()((name, cwd) => {
|
||||
t.test('not publishing placeholder versions', (t) => {
|
||||
t.plan(1)
|
||||
|
||||
nixt()
|
||||
@ -43,9 +39,7 @@ test('verify', function (t) {
|
||||
.env('CI', true)
|
||||
.run('npm publish --semantic-release-rerun')
|
||||
.code(1)
|
||||
.end(function (err) {
|
||||
t.error(err, 'nixt')
|
||||
})
|
||||
.end((err) => t.error(err, 'nixt'))
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
@ -1,13 +1,11 @@
|
||||
'use strict'
|
||||
const test = require('tap').test
|
||||
const nock = require('nock')
|
||||
|
||||
var test = require('tap').test
|
||||
var nock = require('nock')
|
||||
const npmInfo = require('../../dist/lib/npm-info.js')
|
||||
|
||||
var npmInfo = require('../../dist/lib/npm-info.js')
|
||||
const registry = 'http://registry.npmjs.org/'
|
||||
|
||||
var registry = 'http://registry.npmjs.org/'
|
||||
|
||||
var defaultModule = {
|
||||
const defaultModule = {
|
||||
'dist-tags': {
|
||||
latest: '1.0.0'
|
||||
},
|
||||
@ -20,8 +18,8 @@ var defaultModule = {
|
||||
|
||||
process.env.npm_config_registry = registry
|
||||
|
||||
test('npm-info', function (t) {
|
||||
var regMock = nock(registry, {
|
||||
test('npm-info', (t) => {
|
||||
const regMock = nock(registry, {
|
||||
reqheaders: {
|
||||
'authorization': 'Bearer testtoken'
|
||||
}
|
||||
@ -31,17 +29,17 @@ test('npm-info', function (t) {
|
||||
.get('/@user%2Fmodule')
|
||||
.reply(200, defaultModule)
|
||||
|
||||
t.test('get unscoped module', function (t) {
|
||||
t.test('get unscoped module', (t) => {
|
||||
t.plan(3)
|
||||
npmInfo('express', function (err, info) {
|
||||
npmInfo('express', (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.test('get scoped module', (t) => {
|
||||
t.plan(3)
|
||||
npmInfo('@user/module', function (err, info) {
|
||||
npmInfo('@user/module', (err, info) => {
|
||||
t.error(err, 'error')
|
||||
t.is(info.version, '1.0.0', 'version')
|
||||
t.is(info.gitHead, 'HEAD', 'gitHead')
|
||||
|
Loading…
x
Reference in New Issue
Block a user