/
ci-with-local-dependency.js
83 lines (70 loc) · 2.13 KB
/
ci-with-local-dependency.js
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
var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
var osenv = require('osenv')
var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
var pkg = common.pkg
var EXEC_OPTS = { cwd: pkg, stdio: [0, 1, 2] }
var localDependencyJson = {
name: 'local-dependency',
version: '0.0.0',
dependencies: {
underscore: '1.5.1'
}
}
var dependentJson = {
name: 'dependent',
version: '0.0.0',
dependencies: {
'local-dependency': '../local-dependency'
}
}
var target = path.resolve(pkg, '../local-dependency')
test('setup', function (t) {
cleanup()
t.end()
})
test('\'npm install\' should install local pkg from sub path', function (t) {
setup()
common.npm(['install', '--loglevel=silent'], EXEC_OPTS, function (err, code) {
if (err) throw err
t.equal(code, 0, 'npm install exited with code')
t.ok(fs.statSync(path.resolve(pkg, 'node_modules/local-dependency/package.json')).isFile(), 'local dependency package.json exists')
t.ok(fs.statSync(path.resolve(pkg, 'node_modules/local-dependency/node_modules/underscore')).isDirectory(), 'transitive dependency installed')
t.end()
})
})
test('\'npm ci\' should work', function (t) {
common.npm(['ci', '--loglevel=silent'], EXEC_OPTS, function (err, code) {
if (err) throw err
t.equal(code, 0, 'npm install exited with code')
t.ok(fs.statSync(path.resolve(pkg, 'node_modules/local-dependency/package.json')).isFile(), 'local dependency package.json exists')
t.ok(fs.statSync(path.resolve(pkg, 'node_modules/local-dependency/node_modules/underscore')).isDirectory(), 'transitive dependency installed')
t.end()
})
})
test('cleanup', function (t) {
cleanup()
t.end()
})
function cleanup () {
process.chdir(osenv.tmpdir())
rimraf.sync(pkg)
rimraf.sync(target)
}
function setup () {
cleanup()
mkdirp.sync(target)
fs.writeFileSync(
path.join(target, 'package.json'),
JSON.stringify(localDependencyJson, null, 2)
)
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(dependentJson, null, 2)
)
process.chdir(pkg)
}