1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
var fs = require('fs')
var path = require('path')
var mkdirp = require('mkdirp')
var osenv = require('osenv')
var rimraf = require('rimraf')
var test = require('tap').test
var npm = require('../../')
var common = require('../common-tap.js')
var pkg = path.resolve(__dirname, 'version-shrinkwrap')
var cache = path.resolve(pkg, 'cache')
test('npm version <semver> updates shrinkwrap - no git', function (t) {
setup()
npm.load({ cache: pkg + '/cache', registry: common.registry }, function () {
npm.commands.version(['patch'], function (err) {
if (err) return t.fail('Error perform version patch')
var shrinkwrap = require(path.resolve(pkg, 'npm-shrinkwrap.json'))
t.equal(shrinkwrap.version, '0.0.1', 'got expected version')
t.end()
})
})
})
test('npm version <semver> updates git works with no shrinkwrap', function (t) {
setup()
rimraf.sync(path.resolve(pkg, 'npm-shrinkwrap.json'))
npm.config.set('sign-git-tag', false)
common.makeGitRepo({
path: pkg,
added: ['package.json']
}, version)
function version (er, stdout, stderr) {
t.ifError(er, 'git repo initialized without issue')
t.notOk(stderr, 'no error output')
npm.commands.version(['patch'], checkCommit)
}
function checkCommit (er) {
t.ifError(er, 'version command ran without error')
var shrinkwrap = require(path.resolve(pkg, 'npm-shrinkwrap.json'))
t.equal(shrinkwrap.version, '0.0.1', 'got expected version')
var opts = { cwd: pkg, env: { PATH: process.env.PATH } }
var git = require('../../lib/utils/git.js')
git.whichAndExec(
['show', 'HEAD', '--name-only'],
opts,
function (er, stdout, stderr) {
t.ifError(er, 'git show ran without issues')
t.notOk(stderr, 'no error output')
var lines = stdout.split('\n')
t.notEqual(lines.indexOf('package.json'), -1, 'package.json commited')
t.equal(lines.indexOf('npm-shrinkwrap.json'), -1, 'npm-shrinkwrap.json not present')
t.end()
}
)
}
})
test('npm version <semver> updates shrinkwrap and updates git', function (t) {
setup()
npm.config.set('sign-git-tag', false)
common.makeGitRepo({
path: pkg,
added: ['package.json', 'npm-shrinkwrap.json']
}, version)
function version (er, stdout, stderr) {
t.ifError(er, 'git repo initialized without issue')
t.notOk(stderr, 'no error output')
npm.commands.version(['patch'], checkCommit)
}
function checkCommit (er) {
t.ifError(er, 'version command ran without error')
var shrinkwrap = require(path.resolve(pkg, 'npm-shrinkwrap.json'))
t.equal(shrinkwrap.version, '0.0.1', 'got expected version')
var git = require('../../lib/utils/git.js')
var opts = { cwd: pkg, env: { PATH: process.env.PATH } }
git.whichAndExec(
['show', 'HEAD', '--name-only'],
opts,
function (er, stdout, stderr) {
t.ifError(er, 'git show ran without issues')
t.notOk(stderr, 'no error output')
var lines = stdout.split('\n')
t.notEqual(lines.indexOf('package.json'), -1, 'package.json commited')
t.notEqual(lines.indexOf('npm-shrinkwrap.json'), -1, 'npm-shrinkwrap.json commited')
t.end()
}
)
}
})
test('cleanup', function (t) {
// windows fix for locked files
process.chdir(osenv.tmpdir())
rimraf.sync(pkg)
t.end()
})
function setup () {
rimraf.sync(pkg)
mkdirp.sync(pkg)
mkdirp.sync(cache)
var contents = {
author: 'Nathan Bowser && Faiq Raza',
name: 'version-with-shrinkwrap-test',
version: '0.0.0',
description: 'Test for version with shrinkwrap update'
}
fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify(contents), 'utf8')
fs.writeFileSync(path.resolve(pkg, 'npm-shrinkwrap.json'), JSON.stringify(contents), 'utf8')
process.chdir(pkg)
}
|