Skip to content

Commit

Permalink
test: Rewrite shrinkwrap-version-match to use tacks
Browse files Browse the repository at this point in the history
Rewritten while extracting the test from the PR into its own thing.

Credit: @iarna
PR-URL: npm#12290
  • Loading branch information
iarna committed May 13, 2016
1 parent d0c6d19 commit b020127
Showing 1 changed file with 58 additions and 66 deletions.
124 changes: 58 additions & 66 deletions test/tap/shrinkwrap-version-match.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict'
var test = require('tap').test
var Tacks = require('tacks')
var File = Tacks.File
var Dir = Tacks.Dir
var fs = require('fs')
var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var path = require('path')
var common = require('../common-tap.js')

Expand All @@ -11,77 +12,68 @@ var modAdir = path.resolve(testdir, 'modA')
var modB1dir = path.resolve(testdir, 'modB@1')
var modB2dir = path.resolve(testdir, 'modB@2')
var modCdir = path.resolve(testdir, 'modC')
var testjson = {
dependencies: {
modA: 'file://' + modAdir,
modC: 'file://' + modCdir
}
}
var testshrinkwrap = {
dependencies: {
modA: {

var fixture = new Tacks(Dir({
'package.json': File({
dependencies: {
modA: 'file://' + modAdir,
modC: 'file://' + modCdir
}
}),
'npm-shrinkwrap.json': File({
dependencies: {
modA: {
version: '1.0.0',
from: 'modA',
resolved: 'file://' + modAdir
},
modB: {
version: '1.0.0',
from: 'modB@1',
resolved: 'file://' + modB1dir
}
}
}),
'modA': Dir({
'package.json': File({
name: 'modA',
version: '1.0.0',
from: 'modA',
resolved: 'file://' + modAdir
},
modB: {
dependencies: {
'modB': 'file://' + modB1dir
}
})
}),
'modB@1': Dir({
'package.json': File({
name: 'modB',
version: '1.0.0'
}),
'B1': File('')
}),
'modB@2': Dir({
'package.json': File({
name: 'modB',
version: '2.0.0'
}),
'B2': File('')
}),
'modC': Dir({
'package.json': File({
name: 'modC',
version: '1.0.0',
from: 'modB@1',
resolved: 'file://' + modB1dir
}
}
}
var modAjson = {
name: 'modA',
version: '1.0.0',
dependencies: {
'modB': 'file://' + modB1dir
}
}
var modCjson = {
name: 'modC',
version: '1.0.0',
dependencies: {
'modB': 'file://' + modB2dir
}
}
var modB1json = {
name: 'modB',
version: '1.0.0'
}
var modB2json = {
name: 'modB',
version: '2.0.0'
}

function writepjson (dir, content) {
writejson(dir, 'package.json', content)
}
function writejson (dir, file, content) {
writefile(dir, file, JSON.stringify(content, null, 2))
}
function writefile (dir, file, content) {
fs.writeFileSync(path.join(dir, file), content)
}
dependencies: {
'modB': 'file://' + modB2dir
}
})
})
}))

function setup () {
mkdirp.sync(testdir)
writepjson(testdir, testjson)
writejson(testdir, 'npm-shrinkwrap.json', testshrinkwrap)
mkdirp.sync(modAdir)
writepjson(modAdir, modAjson)
mkdirp.sync(modB1dir)
writepjson(modB1dir, modB1json)
writefile(modB1dir, 'B1', '')
mkdirp.sync(modB2dir)
writepjson(modB2dir, modB2json)
writefile(modB2dir, 'B2', '')
mkdirp.sync(modCdir)
writepjson(modCdir, modCjson)
fixture.create(testdir)
}

function cleanup () {
rimraf.sync(testdir)
fixture.remove(testdir)
}

test('setup', function (t) {
Expand Down

0 comments on commit b020127

Please sign in to comment.