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
|
var join = require('path').join
var statSync = require('graceful-fs').statSync
var writeFileSync = require('graceful-fs').writeFileSync
var mkdirp = require('mkdirp')
var mr = require('npm-registry-mock')
var osenv = require('osenv')
var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap')
var pkg = join(__dirname, 'run-script')
var installed = join(pkg, 'node_modules', 'underscore', 'package.json')
var json = {
name: 'npm-it-test',
dependencies: {
underscore: '1.5.1'
},
scripts: {
test: 'echo hax'
}
}
var server
test('run up the mock registry', function (t) {
mr({ port: common.port }, function (err, s) {
if (err) throw err
server = s
t.end()
})
})
test('npm install-test', function (t) {
setup()
common.npm(['install-test', '--registry=' + common.registry], { cwd: pkg }, function (err, code, stdout, stderr) {
if (err) throw err
t.equal(code, 0, 'command ran without error')
t.ok(statSync(installed), 'package was installed')
t.equal(require(installed).version, '1.5.1', 'underscore got installed as expected')
t.match(stdout, /hax/, 'found expected test output')
t.notOk(stderr, 'stderr should be empty')
t.end()
})
})
test('npm it (the form most people will use)', function (t) {
setup()
common.npm(['it', '--registry=' + common.registry], { cwd: pkg }, function (err, code, stdout, stderr) {
if (err) throw err
t.equal(code, 0, 'command ran without error')
t.ok(statSync(installed), 'package was installed')
t.equal(require(installed).version, '1.5.1', 'underscore got installed as expected')
t.match(stdout, /hax/, 'found expected test output')
t.notOk(stderr, 'stderr should be empty')
t.end()
})
})
test('cleanup', function (t) {
process.chdir(osenv.tmpdir())
server.close()
cleanup()
t.end()
})
function cleanup () {
rimraf.sync(pkg)
}
function setup () {
cleanup()
mkdirp.sync(pkg)
writeFileSync(join(pkg, 'package.json'), JSON.stringify(json, null, 2))
}
|