chore: remove babel, fix integration tests

This commit removes babel/es6 from all source and test files, because it was introducing a lot of overhead and only little gain.
This commit fixes and enables integration tests on Travis.
This commit fixes #153 and #151 along the way.

_Originally this commit should have only removed babel, but without working tests that's a bit too hairy._
_I only realized that half way into removing babel/es6, so things are all over the place now._

Closes #153, Closes #151
This commit is contained in:
Stephan Bönnemann
2015-12-31 15:11:54 +01:00
parent 88334523e4
commit 5cdc732b68
29 changed files with 474 additions and 461 deletions
+13 -10
View File
@@ -1,13 +1,16 @@
const test = require('tap').test
const proxyquire = require('proxyquire')
var test = require('tap').test
var proxyquire = require('proxyquire')
const commits = proxyquire('../../dist/lib/commits', {
var commits = proxyquire('../../src/lib/commits', {
'npmlog': {
error: function () {}
},
'child_process': require('../mocks/child-process')
})
test('commits since last release', (t) => {
t.test('get all commits', (tt) => {
commits({lastRelease: {}, options: {branch: 'master'}}, (err, commits) => {
test('commits since last release', function (t) {
t.test('get all commits', function (tt) {
commits({lastRelease: {}, options: {branch: 'master'}}, function (err, commits) {
tt.error(err)
tt.is(commits.length, 2, 'all commits')
tt.is(commits[0].hash, 'hash-one', 'parsed hash')
@@ -17,8 +20,8 @@ test('commits since last release', (t) => {
})
})
t.test('get commits since hash', (tt) => {
commits({lastRelease: {gitHead: 'hash'}, options: {branch: 'master'}}, (err, commits) => {
t.test('get commits since hash', function (tt) {
commits({lastRelease: {gitHead: 'hash'}, options: {branch: 'master'}}, function (err, commits) {
tt.error(err)
tt.is(commits.length, 1, 'specified commits')
tt.is(commits[0].hash, 'hash-one', 'parsed hash')
@@ -28,8 +31,8 @@ test('commits since last release', (t) => {
})
})
t.test('get commits since hash', (tt) => {
commits({lastRelease: {gitHead: 'notinhistory'}, options: {branch: 'notmaster'}}, (err, commits) => {
t.test('get commits since hash', function (tt) {
commits({lastRelease: {gitHead: 'notinhistory'}, options: {branch: 'notmaster'}}, function (err, commits) {
tt.ok(err)
tt.is(err.code, 'ENOTINHISTORY')
tt.end()
+21 -7
View File
@@ -1,8 +1,8 @@
const test = require('tap').test
const getRegistry = require('../../dist/lib/get-registry')
const getRegistry = require('../../src/lib/get-registry')
test('get correct registry', (t) => {
test('get correct registry', function (t) {
t.is(getRegistry({
name: 'publish-config',
publishConfig: {
@@ -10,20 +10,34 @@ test('get correct registry', (t) => {
}},
{}), 'a')
t.is(getRegistry({name: 'normal'}, {get: () => 'b'}), 'b')
t.is(getRegistry({name: 'normal'}, {
get: function () {
return 'b'
}
}), 'b')
t.is(getRegistry({name: 'normal'}, {get: () => null}), 'https://registry.npmjs.org/')
t.is(getRegistry({name: 'normal'}, {
get: function () {
return null
}
}), 'https://registry.npmjs.org/')
t.is(getRegistry({name: '@scoped/foo'}, {
get: (input) => input === '@scoped/registry' ? 'c' : 'd'
get: function (input) {
return input === '@scoped/registry' ? 'c' : 'd'
}
}), 'c')
t.is(getRegistry({name: '@scoped/bar'}, {
get: () => 'e'
get: function () {
return 'e'
}
}), 'e')
t.is(getRegistry({name: '@scoped/baz'}, {
get: () => null
get: function () {
return null
}
}), 'https://registry.npmjs.org/')
t.end()
+32 -32
View File
@@ -1,11 +1,11 @@
const test = require('tap').test
var test = require('tap').test
const plugins = require('../../dist/lib/plugins')
var plugins = require('../../src/lib/plugins')
test('export plugins', (t) => {
test('export plugins', function (t) {
t.plan(5)
const defaultPlugins = plugins({})
var defaultPlugins = plugins({})
t.is(typeof defaultPlugins.analyzeCommits, 'function')
t.is(typeof defaultPlugins.generateNotes, 'function')
@@ -14,51 +14,51 @@ test('export plugins', (t) => {
t.is(typeof defaultPlugins.getLastRelease, 'function')
})
test('plugin pipelines', (t) => {
test('plugin pipelines', function (t) {
t.plan(3)
t.test('get all results', (tt) => {
const pipelinePlugins = plugins({
t.test('get all results', function (tt) {
var pipelinePlugins = plugins({
verifyRelease: [
'./dist/lib/plugin-noop',
'./.test/mocks/plugin-result-a',
'./.test/mocks/plugin-result-b'
'./src/lib/plugin-noop',
'./test/mocks/plugin-result-a',
'./test/mocks/plugin-result-b'
]
})
pipelinePlugins.verifyRelease({}, (err, results) => {
pipelinePlugins.verifyRelease({}, function (err, results) {
tt.error(err)
tt.same(results, [undefined, 'a', 'b'])
tt.end()
})
})
t.test('get first error', (tt) => {
const pipelinePlugins = plugins({
t.test('get first error', function (tt) {
var pipelinePlugins = plugins({
verifyConditions: [
'./dist/lib/plugin-noop',
'./.test/mocks/plugin-error-a',
'./.test/mocks/plugin-error-b'
'./src/lib/plugin-noop',
'./test/mocks/plugin-error-a',
'./test/mocks/plugin-error-b'
]
})
pipelinePlugins.verifyConditions({}, (err) => {
pipelinePlugins.verifyConditions({}, function (err) {
tt.is(err.message, 'a')
tt.end()
})
})
t.test('get error and only results before', (tt) => {
const pipelinePlugins = plugins({
t.test('get error and only results before', function (tt) {
var pipelinePlugins = plugins({
verifyRelease: [
'./dist/lib/plugin-noop',
'./.test/mocks/plugin-result-a',
'./.test/mocks/plugin-error-b',
'./.test/mocks/plugin-result-b'
'./src/lib/plugin-noop',
'./test/mocks/plugin-result-a',
'./test/mocks/plugin-error-b',
'./test/mocks/plugin-result-b'
]
})
pipelinePlugins.verifyRelease({}, (err, results) => {
pipelinePlugins.verifyRelease({}, function (err, results) {
tt.is(err.message, 'b')
tt.same(results, [undefined, 'a', undefined])
tt.end()
@@ -66,18 +66,18 @@ test('plugin pipelines', (t) => {
})
})
test('normalize and load plugin', (t) => {
t.test('load from string', (tt) => {
const plugin = plugins.normalize('./dist/lib/plugin-noop')
test('normalize and load plugin', function (t) {
t.test('load from string', function (tt) {
var plugin = plugins.normalize('./src/lib/plugin-noop')
tt.is(typeof plugin, 'function')
tt.end()
})
t.test('load from object', (tt) => {
const plugin = plugins.normalize({
path: './dist/lib/plugin-noop'
t.test('load from object', function (tt) {
var plugin = plugins.normalize({
path: './src/lib/plugin-noop'
})
tt.is(typeof plugin, 'function')
@@ -85,8 +85,8 @@ test('normalize and load plugin', (t) => {
tt.end()
})
t.test('load from object', (tt) => {
const plugin = plugins.normalize(null, '../../dist/lib/plugin-noop')
t.test('load from fallback', function (tt) {
var plugin = plugins.normalize(null, '../../src/lib/plugin-noop')
tt.is(typeof plugin, 'function')
+24 -20
View File
@@ -1,20 +1,24 @@
const { defaults } = require('lodash')
const test = require('tap').test
const proxyquire = require('proxyquire')
var defaults = require('lodash').defaults
var test = require('tap').test
var proxyquire = require('proxyquire')
const post = proxyquire('../../dist/post', {
var post = proxyquire('../../src/post', {
'git-head': require('../mocks/git-head'),
github: require('../mocks/github')
})
const pkg = {
var pkg = {
version: '1.0.0',
repository: {url: 'http://github.com/whats/up.git'}
}
const plugins = {generateNotes: (pkg, cb) => cb(null, 'the log')}
var plugins = {
generateNotes: function (pkg, cb) {
cb(null, 'the log')
}
}
const defaultRelease = {
var defaultRelease = {
owner: 'whats',
repo: 'up',
name: 'v1.0.0',
@@ -23,13 +27,13 @@ const defaultRelease = {
body: 'the log'
}
test('full post run', (t) => {
t.test('in debug mode w/o token', (tt) => {
test('full post run', function (t) {
t.test('in debug mode w/o token', function (tt) {
post({
options: {debug: true},
pkg,
plugins
}, (err, published, release) => {
pkg: pkg,
plugins: plugins
}, function (err, published, release) {
tt.error(err)
tt.is(published, false)
tt.match(release, defaults({draft: true}, defaultRelease))
@@ -38,12 +42,12 @@ test('full post run', (t) => {
})
})
t.test('in debug mode w/token', (tt) => {
t.test('in debug mode w/token', function (tt) {
post({
options: {debug: true, githubToken: 'yo'},
pkg,
plugins
}, (err, published, release) => {
pkg: pkg,
plugins: plugins
}, function (err, published, release) {
tt.error(err)
tt.is(published, true)
tt.match(release, defaults({draft: true}, defaultRelease))
@@ -52,12 +56,12 @@ test('full post run', (t) => {
})
})
t.test('production', (tt) => {
t.test('production', function (tt) {
post({
options: {githubToken: 'yo'},
pkg,
plugins
}, (err, published, release) => {
pkg: pkg,
plugins: plugins
}, function (err, published, release) {
tt.error(err)
tt.is(published, true)
tt.match(release, defaultRelease)
+24 -20
View File
@@ -1,55 +1,59 @@
const test = require('tap').test
const proxyquire = require('proxyquire')
var test = require('tap').test
var proxyquire = require('proxyquire')
require('../mocks/registry')
const pre = proxyquire('../../dist/pre', {
'./lib/commits': proxyquire('../../dist/lib/commits', {
var pre = proxyquire('../../src/pre', {
'./lib/commits': proxyquire('../../src/lib/commits', {
'child_process': require('../mocks/child-process')
})
})
const versions = {
var versions = {
available: '1.0.0'
}
const plugins = {
verifyRelease: (release, cb) => cb(null, release),
analyzeCommits: (commits, cb) => cb(null, 'major'),
getLastRelease: ({ pkg }, cb) => {
cb(null, {version: versions[pkg.name] || null, gitHead: 'HEAD'})
var plugins = {
verifyRelease: function (release, cb) {
cb(null, release)
},
analyzeCommits: function (commits, cb) {
cb(null, 'major')
},
getLastRelease: function (config, cb) {
cb(null, {version: versions[config.pkg.name] || null, gitHead: 'HEAD'})
}
}
const npm = {
var npm = {
registry: 'http://registry.npmjs.org/',
tag: 'latest'
}
test('full pre run', (t) => {
t.test('increase version', (tt) => {
test('full pre run', function (t) {
t.test('increase version', function (tt) {
tt.plan(3)
pre({
options: {branch: 'master'},
npm,
npm: npm,
pkg: {name: 'available'},
plugins
}, (err, release) => {
plugins: plugins
}, function (err, release) {
tt.error(err)
tt.is(release.type, 'major')
tt.is(release.version, '2.0.0')
})
})
t.test('increase version', (tt) => {
t.test('increase version', function (tt) {
tt.plan(3)
pre({
options: {branch: 'master'},
npm,
npm: npm,
pkg: {name: 'unavailable'},
plugins
}, (err, release) => {
plugins: plugins
}, function (err, release) {
tt.error(err)
tt.is(release.type, 'initial')
tt.is(release.version, '1.0.0')
+24 -12
View File
@@ -1,9 +1,9 @@
const test = require('tap').test
var test = require('tap').test
const type = require('../../dist/lib/type')
var type = require('../../src/lib/type')
test('get type from commits', (t) => {
t.test('get type from plugin', (tt) => {
test('get type from commits', function (t) {
t.test('get type from plugin', function (tt) {
tt.plan(2)
type({
@@ -12,33 +12,45 @@ test('get type from commits', (t) => {
message: 'a'
}],
lastRelease: {version: '1.0.0'},
plugins: {analyzeCommits: (config, cb) => cb(null, 'major')}
}, (err, type) => {
plugins: {
analyzeCommits: function (config, cb) {
cb(null, 'major')
}
}
}, function (err, type) {
tt.error(err)
tt.is(type, 'major')
})
})
t.test('error when no changes', (tt) => {
t.test('error when no changes', function (tt) {
tt.plan(1)
type({
commits: [],
lastRelease: {},
plugins: {analyzeCommits: (config, cb) => cb(null, null)}
}, (err) => {
plugins: {
analyzeCommits: function (config, cb) {
cb(null, null)
}
}
}, function (err) {
tt.is(err.code, 'ENOCHANGE')
})
})
t.test('initial version', (tt) => {
t.test('initial version', function (tt) {
tt.plan(2)
type({
commits: [],
lastRelease: {},
plugins: {analyzeCommits: (config, cb) => cb(null, 'major')}
}, (err, type) => {
plugins: {
analyzeCommits: function (config, cb) {
cb(null, 'major')
}
}
}, function (err, type) {
tt.error(err)
tt.is(type, 'initial')
})
+10 -10
View File
@@ -1,10 +1,10 @@
const test = require('tap').test
var test = require('tap').test
const verify = require('../../dist/lib/verify')
var verify = require('../../src/lib/verify')
test('verify pkg, options and env', (t) => {
t.test('dry run verification', (tt) => {
const noErrors = verify({
test('verify pkg, options and env', function (t) {
t.test('dry run verification', function (tt) {
var noErrors = verify({
options: {debug: true},
pkg: {
name: 'package',
@@ -16,7 +16,7 @@ test('verify pkg, options and env', (t) => {
tt.is(noErrors.length, 0)
const errors = verify({
var errors = verify({
options: {debug: true},
pkg: {}
})
@@ -25,7 +25,7 @@ test('verify pkg, options and env', (t) => {
tt.is(errors[0].code, 'ENOPKGNAME')
tt.is(errors[1].code, 'ENOPKGREPO')
const errors2 = verify({
var errors2 = verify({
options: {debug: true},
pkg: {
name: 'package',
@@ -41,8 +41,8 @@ test('verify pkg, options and env', (t) => {
tt.end()
})
t.test('publish verification', (tt) => {
const noErrors = verify({
t.test('publish verification', function (tt) {
var noErrors = verify({
env: {NPM_TOKEN: 'yo'},
options: {githubToken: 'sup'},
pkg: {
@@ -55,7 +55,7 @@ test('verify pkg, options and env', (t) => {
tt.is(noErrors.length, 0)
const errors = verify({env: {}, options: {}, pkg: {}})
var errors = verify({env: {}, options: {}, pkg: {}})
tt.is(errors.length, 4)
tt.is(errors[0].code, 'ENOPKGNAME')