refactor(mocks): extract from specs

This commit is contained in:
Stephan Bönnemann 2015-06-14 21:07:39 -07:00
parent a405021d08
commit 66bf8ff710
5 changed files with 49 additions and 47 deletions

View File

@ -0,0 +1,16 @@
const rawCommits = [
'hash-one==SPLIT==commit-one==END==\n',
'hash-two==SPLIT==commit-two==END==\n'
]
module.exports = {
exec: (command, cb) => {
cb(
null,
/\.\.HEAD/.test(command) ?
rawCommits[0] :
rawCommits.join()
)
},
'@noCallThru': true
}

20
test/mocks/registry.js Normal file
View File

@ -0,0 +1,20 @@
const nock = require('nock')
const availableModule = {
'dist-tags': {
latest: '1.33.7'
},
versions: {
'1.33.7': {
gitHead: 'HEAD'
}
}
}
module.exports = nock('http://registry.npmjs.org')
.get('/available')
.reply(200, availableModule)
.get('/@scoped/available')
.reply(200, availableModule)
.get('/unavailable')
.reply(404, {})

View File

@ -1,22 +1,8 @@
const test = require('tap').test
const proxyquire = require('proxyquire')
const rawCommits = [
'hash-one==SPLIT==commit-one==END==\n',
'hash-two==SPLIT==commit-two==END==\n'
]
const commits = proxyquire('../../dist/lib/commits.js', {
'child_process': {
exec: (command, cb) => {
cb(
null,
/\.\.HEAD/.test(command) ?
rawCommits[0] :
rawCommits.join()
)
},
'@noCallThru': true
}
const commits = proxyquire('../../dist/lib/commits', {
'child_process': require('../mocks/child-process')
})
test('commits since last release', (t) => {

View File

@ -1,35 +1,18 @@
const test = require('tap').test
const nock = require('nock')
const lastRelease = require('../../dist/lib/last-release.js')
require('../mocks/registry')
const lastRelease = require('../../dist/lib/last-release')
const availableModule = {
'dist-tags': {
latest: '1.33.7'
},
versions: {
'1.33.7': {
gitHead: 'HEAD'
const npmConfig = {
registry: 'http://registry.npmjs.org'
}
}
}
const registry = 'http://registry.npmjs.org'
const regMock = nock(registry)
.get('/available')
.reply(200, availableModule)
.get('/@scoped/available')
.reply(200, availableModule)
.get('/unavailable')
.reply(404, {})
test('last release from registry', (t) => {
t.test('get release from package name', (t) => {
lastRelease({
name: 'available'
}, {
registry
}, (err, release) => {
}, npmConfig,
(err, release) => {
t.error(err)
t.is(release.version, '1.33.7', 'version')
t.is(release.gitHead, 'HEAD', 'gitHead')
@ -39,9 +22,8 @@ test('last release from registry', (t) => {
t.test('get release from scoped package name', (t) => {
lastRelease({
name: '@scoped/available'
}, {
registry
}, (err, release) => {
}, npmConfig,
(err, release) => {
t.error(err)
t.is(release.version, '1.33.7', 'version')
t.is(release.gitHead, 'HEAD', 'gitHead')
@ -51,12 +33,10 @@ test('last release from registry', (t) => {
t.test('get nothing from not yet published package name', (t) => {
lastRelease({
name: 'unavailable'
}, {
registry
}, (err, release) => {
}, npmConfig,
(err, release) => {
t.error(err)
t.is(release.version, undefined, 'no version')
regMock.done()
})
})
})

View File

@ -1,6 +1,6 @@
const test = require('tap').test
const type = require('../../dist/lib/type.js')
const type = require('../../dist/lib/type')
test('get type from commits', (t) => {
t.test('get type from plugin', (t) => {