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
+7 -9
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')
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)
+11 -17
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')
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'))
})
}))
})
+11 -13
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')
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')
})
})
+24 -32
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')
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')
+6 -8
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')
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)
+8 -12
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')
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'))
})
}))
}
+11 -13
View File
@@ -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')
+14 -20
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')
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'))
})
}))
})