Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80552 views
1
var test = require('tap').test;
2
var detective = require('../');
3
var fs = require('fs');
4
var src = fs.readFileSync(__dirname + '/files/both.js');
5
6
test('both', function (t) {
7
var modules = detective.find(src);
8
t.deepEqual(modules.strings, [ 'a', 'b' ]);
9
t.deepEqual(modules.expressions, [ "'c' + x", "'d' + y" ]);
10
t.notOk(modules.nodes, 'has no nodes');
11
t.end();
12
});
13
14
test('both with nodes specified in opts', function (t) {
15
var modules = detective.find(src, { nodes: true });
16
t.deepEqual(modules.strings, [ 'a', 'b' ]);
17
t.deepEqual(modules.expressions, [ "'c' + x", "'d' + y" ]);
18
t.deepEqual(
19
modules.nodes.map(function (n) {
20
var arg = n.arguments[0];
21
return arg.value || arg.left.value;
22
}),
23
[ 'a', 'b', 'c', 'd' ],
24
'has a node for each require');
25
t.end();
26
});
27
28