UNPKG

886 BJavaScriptView Raw
1var test = require('tap').test;
2var detective = require('../');
3var fs = require('fs');
4
5// in order to use detective to find any function
6// it needs to properly handle functions called without args
7var src = [ 'fn();', 'otherfn();', 'fn();' ].join('\n')
8
9test('noargs', function (t) {
10 t.plan(1);
11 t.deepEqual(detective(src, { word: 'fn' }).length, 0, 'finds no arg id');
12});
13
14test('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});