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
|
var test = require("tap").test
var fs = require("fs")
var node = process.execPath
var npm = require.resolve("../../bin/npm-cli.js")
var rimraf = require("rimraf")
var mr = require("npm-registry-mock")
var common = require("../common-tap.js")
var spawn = require("child_process").spawn
var env = process.env
process.env.npm_config_depth = "Infinity"
var pkg = __dirname + "/prune"
var cache = pkg + "/cache"
var server
test("reg mock", function (t) {
mr(common.port, function (s) {
server = s
t.pass("registry mock started")
t.end()
})
})
test("npm install", function (t) {
rimraf.sync(pkg + "/node_modules")
var c = spawn(node, [
npm, "install",
"--cache=" + cache,
"--registry=" + common.registry,
"--loglevel=silent",
"--production=false"
], { cwd: pkg, env: env })
c.stderr.on("data", function(d) {
t.fail("Should not get data on stderr: " + d)
})
c.on("close", function(code) {
t.notOk(code, "exit ok")
t.end()
})
})
test("npm install test-package", function (t) {
var c = spawn(node, [
npm, "install", "test-package",
"--cache=" + cache,
"--registry=" + common.registry,
"--loglevel=silent",
"--production=false"
], { cwd: pkg, env: env })
c.stderr.on("data", function(d) {
t.fail("Should not get data on stderr: " + d)
})
c.on("close", function(code) {
t.notOk(code, "exit ok")
t.end()
})
})
test("verify installs", function (t) {
var dirs = fs.readdirSync(pkg + "/node_modules").sort()
t.same(dirs, [ "test-package", "mkdirp", "underscore" ].sort())
t.end()
})
test("npm prune", function (t) {
var c = spawn(node, [
npm, "prune",
"--loglevel=silent",
"--production=false"
], { cwd: pkg, env: env })
c.stderr.on("data", function(d) {
t.fail("Should not get data on stderr: " + d)
})
c.on("close", function(code) {
t.notOk(code, "exit ok")
t.end()
})
})
test("verify installs", function (t) {
var dirs = fs.readdirSync(pkg + "/node_modules").sort()
t.same(dirs, [ "mkdirp", "underscore" ])
t.end()
})
test("npm prune", function (t) {
var c = spawn(node, [
npm, "prune",
"--loglevel=silent",
"--production"
], { cwd: pkg, env: env })
c.stderr.on("data", function(d) {
t.fail("Should not get data on stderr: " + d)
})
c.on("close", function(code) {
t.notOk(code, "exit ok")
t.end()
})
})
test("verify installs", function (t) {
var dirs = fs.readdirSync(pkg + "/node_modules").sort()
t.same(dirs, [ "underscore" ])
t.end()
})
test("cleanup", function (t) {
server.close()
rimraf.sync(pkg + "/node_modules")
rimraf.sync(pkg + "/cache")
t.pass("cleaned up")
t.end()
})
|