/
require-analyzer-test.js
80 lines (75 loc) · 2.05 KB
/
require-analyzer-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
/*
* require-analyzer-test.js: Basic tests for the require-analyzer module.
*
* (C) 2010, Nodejitsu Inc.
*
*/
require.paths.unshift(require('path').join(__dirname, '..', 'lib'));
var fs = require('fs'),
path = require('path'),
vows = require('vows'),
assert = require('assert'),
analyzer = require('require-analyzer');
var rawPackages = [
'npm',
'semver',
'nopt',
'abbrev',
'findit',
'seq',
'hashish',
'traverse',
'chainsaw'
];
var packages = [
'findit',
'npm',
'semver'
];
vows.describe('require-analyzer').addBatch({
"When using require-analyzer": {
"the analyze() method": {
"when passed a directory": {
"with a valid package.json": {
topic: function () {
analyzer.analyze({target: path.join(__dirname, '..') }, this.callback)
},
"should respond with the correct dependencies": function (err, pkgs) {
assert.isNull(err);
assert.deepEqual(Object.keys(pkgs), packages);
}
}
}
},
"the dir() method": {
topic: function () {
var that = this;
analyzer.dir({ target: path.join(__dirname, '..', 'lib') }, this.callback);
},
"should respond with the correct dependencies": function (err, pkgs) {
assert.isNull(err);
assert.deepEqual(pkgs, rawPackages);
}
},
"the package() method": {
topic: function () {
analyzer.package({ target: path.join(__dirname, '..') }, this.callback)
},
"should respond with the correct dependencies": function (err, pkgs) {
assert.isNull(err);
assert.deepEqual(pkgs, rawPackages);
}
},
"the file() method": {
"when passed a valid file": {
topic: function () {
analyzer.file({ target: path.join(__dirname, '..', 'lib', 'require-analyzer') }, this.callback)
},
"should respond with the correct dependencies": function (err, pkgs) {
assert.isNull(err);
assert.deepEqual(pkgs, rawPackages);
}
}
}
}
}).export(module);