Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80551 views
1
var test = require('tap').test;
2
var detective = require('../');
3
var fs = require('fs');
4
5
// in order to use detective to find any function
6
// it needs to properly handle functions called without args
7
var src = [ 'fn();', 'otherfn();', 'fn();' ].join('\n')
8
9
test('noargs', function (t) {
10
t.plan(1);
11
t.deepEqual(detective(src, { word: 'fn' }).length, 0, 'finds no arg id');
12
});
13
14
test('find noargs with nodes', function (t) {
15
t.plan(4);
16
var modules = detective.find(src, { word: 'fn', nodes: true });
17
t.equal(modules.strings.length, 0, 'finds no arg id');
18
t.equal(modules.expressions.length, 0, 'finds no expressions');
19
t.equal(modules.nodes.length, 2, 'finds a node for each matching function call');
20
t.equal(
21
modules.nodes.filter(function (x) {
22
return x.callee.name === 'fn'
23
}).length, 2,
24
'all matches are correct'
25
);
26
});
27
28