Skip to content

Commit

Permalink
New tap and various test tweaks
Browse files Browse the repository at this point in the history
This also splits the scope-in-config into two, since init() doesn't
reload the package.json on each call, so it can really only be done once
per process.
  • Loading branch information
isaacs committed May 31, 2015
1 parent b747e9f commit 257c414
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -25,7 +25,7 @@
"devDependencies": {
"npm": "^2",
"rimraf": "^2.1.4",
"tap": "^0.7.1"
"tap": "^1.2.0"
},
"keywords": [
"init",
Expand Down
2 changes: 2 additions & 0 deletions test/basic.js
Expand Up @@ -6,6 +6,7 @@ var test = require('tap').test

test('the basics', function (t) {
var i = path.join(__dirname, 'basic.input')
rimraf.sync(__dirname + '/package.json')
init(__dirname, i, { foo: 'bar' }, function (er, data) {
if (er) throw er
var expect = {
Expand All @@ -18,6 +19,7 @@ test('the basics', function (t) {
config: { foo: 'bar' },
package: {}
}
console.log('')
t.same(data, expect)
t.end()
})
Expand Down
7 changes: 5 additions & 2 deletions test/license.js
Expand Up @@ -5,7 +5,9 @@ var common = require('./lib/common')

test('license', function (t) {
init(__dirname, '', {}, function (er, data) {
t.ok(!er, 'should not error')
if (er)
throw er

var wanted = {
name: 'the-name',
version: '1.0.0',
Expand All @@ -15,7 +17,8 @@ test('license', function (t) {
author: '',
main: 'basic.js'
}
t.same(data, wanted)
console.log('')
t.has(data, wanted)
t.end()
})
common.drive([
Expand Down
7 changes: 5 additions & 2 deletions test/name-spaces.js
Expand Up @@ -4,8 +4,10 @@ var rimraf = require('rimraf')
var common = require('./lib/common')

test('spaces', function (t) {
rimraf.sync(__dirname + '/package.json')
init(__dirname, '', {}, function (er, data) {
t.ok(!er, 'should not error')
if (er)
throw er
var wanted = {
name: 'the-name',
version: '1.0.0',
Expand All @@ -15,7 +17,8 @@ test('spaces', function (t) {
author: '',
main: 'basic.js'
}
t.same(data, wanted)
console.log('')
t.has(data, wanted)
t.end()
})
common.drive([
Expand Down
7 changes: 5 additions & 2 deletions test/name-uppercase.js
Expand Up @@ -5,7 +5,9 @@ var common = require('./lib/common')

test('uppercase', function (t) {
init(__dirname, '', {}, function (er, data) {
t.ok(!er, 'should not error')
if (er)
throw er

var wanted = {
name: 'the-name',
version: '1.0.0',
Expand All @@ -15,7 +17,8 @@ test('uppercase', function (t) {
author: '',
main: 'basic.js'
}
t.same(data, wanted)
console.log('')
t.has(data, wanted)
t.end()
})
common.drive([
Expand Down
30 changes: 30 additions & 0 deletions test/scope-in-config-existing-name.js
@@ -0,0 +1,30 @@
var fs = require('fs')
var path = require('path')

var rimraf = require('rimraf')
var tap = require('tap')

var init = require('../')

var json = {
name: '@already/scoped',
version: '1.0.0'
}

tap.test('with existing package.json', function (t) {
fs.writeFileSync(path.join(__dirname, 'package.json'), JSON.stringify(json, null, 2))
console.log(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'))
console.error('wrote json', json)
init(__dirname, __dirname, { yes: 'yes', scope: '@still' }, function (er, data) {
if (er) throw er

console.log('')
t.equal(data.name, '@still/scoped', 'new scope is added, basic name is kept')
t.end()
})
})

tap.test('teardown', function (t) {
rimraf.sync(path.join(__dirname, 'package.json'))
t.end()
})
18 changes: 2 additions & 16 deletions test/scope-in-config.js
Expand Up @@ -21,22 +21,8 @@ tap.test('--yes with scope', function (t) {
init(__dirname, __dirname, { yes: 'yes', scope: '@scoped' }, function (er, data) {
if (er) throw er

t.same(EXPECT, data)
t.end()
})
})

var json = {
name: '@already/scoped',
version: '1.0.0'
}

tap.test('with existing package.json', function (t) {
fs.writeFileSync(path.join(__dirname, 'package.json'), JSON.stringify(json, null, 2))
init(__dirname, __dirname, { yes: 'yes', scope: '@still' }, function (er, data) {
if (er) throw er

t.equal(data.name, '@still/scoped', 'new scope is added, basic name is kept')
console.log('')
t.has(data, EXPECT)
t.end()
})
})
Expand Down
3 changes: 2 additions & 1 deletion test/scope.js
Expand Up @@ -19,7 +19,8 @@ tap.test('the scope', function (t) {
init(dir, i, {scope: '@foo'}, function (er, data) {
if (er) throw er

t.same(EXPECT, data)
console.log('')
t.has(data, EXPECT)
t.end()
})
setTimeout(function () {
Expand Down
2 changes: 1 addition & 1 deletion test/yes-defaults.js
Expand Up @@ -17,7 +17,7 @@ tap.test('--yes defaults', function (t) {
init(__dirname, __dirname, {yes: 'yes'}, function (er, data) {
if (er) throw er

t.same(EXPECT, data, 'used the default data')
t.has(data, EXPECT, 'used the default data')
t.end()
})
})
Expand Down

2 comments on commit 257c414

@michaelnisi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between same() and has()?

@michaelnisi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To answer myself, has() is synonymous with match() which allows additional fields.

Please sign in to comment.