Skip to content

Commit

Permalink
fix(test): add a test for lock
Browse files Browse the repository at this point in the history
  • Loading branch information
watilde committed Jul 28, 2017
1 parent 0aa9b30 commit de8ecaa
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
2 changes: 0 additions & 2 deletions test/00-clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ const fixtures = fs.readdirSync(path.join(__dirname, 'fixtures'))

test((t) => {
var count = fixtures.length
t.plan(count)
fixtures.forEach(fixture => {
const modules = path.join(__dirname, 'fixtures', fixture, 'node_modules')
rimraf(modules, _ => {
count -= 1
t.pass()
if (count === 0) t.end()
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/install.js → test/10-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test((t) => {
const pkg = path.join(__dirname, 'fixtures', fixture)
const pkgJSON = require(path.join(pkg, 'package.json'))
exec(`node ${bin} install`, {cwd: pkg}, (err, stdout, stderr) => {
t.ifError(err, `${pkgJSON.name}: dep ran without error`)
t.ifError(err, `${pkgJSON.name}: install ran without error`)
tree.read(pkg, (err, out) => {
t.ifError(err, `${pkgJSON.name}: tree could be read`)
const deps = out.dependencies
Expand Down
23 changes: 23 additions & 0 deletions test/20-lock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const fs = require('fs')
const path = require('path')
const exec = require('child_process').exec
const test = require('tap').test
const fixtures = fs.readdirSync(path.join(__dirname, 'fixtures'))

test((t) => {
var items = 2
var count = fixtures.length * items
t.plan(count)
fixtures.forEach(fixture => {
const bin = path.join(__dirname, '..', 'bin', 'dep.js')
const pkg = path.join(__dirname, 'fixtures', fixture)
const pkgJSON = require(path.join(pkg, 'package.json'))
exec(`node ${bin} lock`, {cwd: pkg}, (err, stdout, stderr) => {
t.ifError(err, `${pkgJSON.name}: lock ran without error`)
const lock = require(path.join(pkg, 'node_modules.json'))
const deps = lock.dependencies
t.is(Object.keys(deps).length, 2, `${pkgJSON.name}: two deps are installed`)
if (count === 0) t.end()
})
})
})
11 changes: 5 additions & 6 deletions test/zz-cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ const fixtures = fs.readdirSync(path.join(__dirname, 'fixtures'))

test((t) => {
var count = fixtures.length
t.plan(count)
fixtures.forEach(fixture => {
const modules = path.join(__dirname, 'fixtures', fixture, 'node_modules')
rimraf(modules, _ => {
count -= 1
t.pass()
if (count === 0) t.end()
})
const lock = path.join(__dirname, 'fixtures', fixture, 'node_modules.json')
rimraf.sync(modules)
rimraf.sync(lock)
count -= 1
if (count === 0) t.end()
})
})

0 comments on commit de8ecaa

Please sign in to comment.