Skip to content

Commit

Permalink
test(libprecious): add test for git dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Feb 27, 2018
1 parent 279e2cd commit 963dcf1
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/libprecious/.gitignore
Expand Up @@ -3,3 +3,4 @@
/bin/node_modules
/.nyc_output
/test/cache
/test/bin-stubs/
Empty file.
71 changes: 71 additions & 0 deletions packages/libprecious/test/index.js
@@ -1,4 +1,7 @@
'use strict'
// This needs to be added to access our git binstub
const path = require('path')
process.env.PATH = path.resolve(__dirname, 'bin-stubs') + ':' + process.env.PATH

const BB = require('bluebird')

Expand Down Expand Up @@ -203,6 +206,74 @@ test('it does not archive devdeps with `only=production` config', t => {
})
})

test('it works with git dependencies', t => {
return mockTar({
// This makes a tarball so we can get an integrity hash for it
'package.json': JSON.stringify({
name: 'bar',
version: '1.0.1'
}),
'index.js': 'hi'
}, {gzip: false})
.then(tarData => ssri.fromData(tarData).toString())
.then(integrity => {
fs.writeFileSync(path.resolve(__dirname, 'bin-stubs/git'), [
'#!/usr/bin/env bash',
'echo \'{"name":"bar","version":"1.0.1"}\' > package.json',
'echo hi > index.js'
].join('\n'))
const fixture = new Tacks(Dir({
'package.json': File({
name: 'foo',
version: '1.2.3',
dependencies: {
bar: 'github:npm/bar#6d75a6a'
}
}),
'package-lock.json': File({
name: 'foo',
lockfileVersion: 1,
requires: true,
dependencies: {
bar: {
version: 'github:npm/bar#6d75a6a'
}
}
})
}))
fixture.create(testDir)
const config = mockConfig(testDir, {registry: REGISTRY})
const archivedResolved = `file:archived-packages/bar-github-npm-bar-6d75a6a.tar`
return new MyPrecious({log: npmlog, config})
.run()
.then(() => fs.readFileAsync('package-lock.json', 'utf8'))
.then(JSON.parse)
.then(pkgLock => {
t.equal(
pkgLock.dependencies.bar.resolved,
archivedResolved,
'resolved field updated in npm-shrinkwrap'
)
return fs.readFileAsync(archivedResolved.substr(5))
.then(tarData => {
const newSri = pkgLock.dependencies.bar.integrity
t.ok(
ssri.checkData(tarData, newSri),
'archived tarball passes integrity check'
)
t.ok(
ssri.checkData(tarData, newSri),
'updated integrity field still matches old tgzData'
)
t.notOk(
ssri.checkData('blah', newSri),
'updated integrity field is actually checking data at all'
)
})
})
})
})

test('it works with npm-shrinkwrap files', t => {
return mockTar({
// This makes the tarball for `bar` itself, to be hosted by tnock
Expand Down

0 comments on commit 963dcf1

Please sign in to comment.