-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
146 lines (126 loc) · 3.95 KB
/
test.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
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
135
136
137
138
139
140
141
142
143
144
145
146
'use strict';
require('mocha');
var assert = require('assert');
var path = require('path');
var Base = require('base');
var Pkg = require('pkg-store');
var del = require('delete');
var npm = require('./');
var app, pkg;
var fixtures = path.resolve.bind(path, __dirname, 'fixtures');
var cwd = process.cwd();
describe('base-npm', function() {
this.timeout(20000);
beforeEach(function() {
process.chdir(fixtures());
pkg = new Pkg(process.cwd());
app = new Base();
app.isApp = true;
app.use(npm());
});
afterEach(function(cb) {
del(fixtures('package.json'), function(err) {
if (err) return cb(err);
pkg.data = require(fixtures('tmpl.json'));
pkg.save();
cb();
});
});
after(function() {
process.chdir(cwd);
});
it('should export a function', function() {
assert.equal(typeof npm, 'function');
});
it('should install globally and not save to package.json', function(cb) {
app.npm.global('node-foo', function(err) {
if (err) return cb(err);
assert(!pkg.has('dependencies.node-foo'));
assert(!pkg.has('devDependencies.node-foo'));
cb();
});
});
it('should install and not save to package.json', function(cb) {
app.npm.install('isobject', function(err) {
if (err) return cb(err);
assert(!pkg.has('dependencies.isobject'));
assert(!pkg.has('devDependencies.isobject'));
cb();
});
});
it('should install to dependencies in package.json', function(cb) {
app.npm.save('isobject', function(err) {
if (err) return cb(err);
assert(pkg.has('dependencies.isobject'));
cb();
});
});
it('should install to devDependencies in package.json', function(cb) {
app.npm.saveDev('isobject', function(err) {
if (err) return cb(err);
assert(pkg.has('devDependencies.isobject'));
cb();
});
});
it('should install the latest version of a package', function(cb) {
var obj = new Pkg(process.cwd());
obj.set('devDependencies', {isobject: '*'});
obj.save();
app.npm.latest(['isobject', '--save-dev'], function(err) {
if (err) return cb(err);
var pkg2Path = fixtures('package.json');
var pkg2 = require(pkg2Path);
assert(pkg2.devDependencies.hasOwnProperty('isobject'));
assert.notEqual(pkg2.devDependencies.isobject, '*');
del(pkg2, cb);
});
});
it('should return `true` when module exists on npm', function(cb) {
var name = 'base-npm';
app.npm.exists(name, function(err, exists) {
if (err) return cb(err);
assert.equal(typeof exists, 'object');
assert.equal(exists[name], true);
cb();
});
});
it('should return `false` when module does not exist on npm', function(cb) {
var name = 'ljalskdjflkadsflkjalksdjlkasdflkjsdfljlklk';
app.npm.exists(name, function(err, exists) {
if (err) return cb(err);
assert.equal(typeof exists, 'object');
assert.equal(exists[name], false);
cb();
});
});
it('should return mixed results when some modules exist and some do not', function(cb) {
var names = ['base-npm', 'ljalskdjflkadsflkjalksdjlkasdflkjsdfljlklk'];
app.npm.exists(names, function(err, exists) {
if (err) return cb(err);
assert.equal(typeof exists, 'object');
assert.equal(exists[names[0]], true);
assert.equal(exists[names[1]], false);
cb();
});
});
describe('cwd', function() {
var nestedPkg;
beforeEach(function() {
nestedPkg = new Pkg(fixtures('nested'));
nestedPkg.data = require(fixtures('tmpl.json'));
nestedPkg.save();
});
afterEach(function(cb) {
del(fixtures('nested'), cb);
});
it('should install to the specified cwd', function(cb) {
app.cwd = fixtures('nested');
app.npm.saveDev('isobject', function(err) {
if (err) return cb(err);
nestedPkg = new Pkg(fixtures('nested'));
assert(nestedPkg.has('devDependencies.isobject'));
cb();
});
});
});
});