Skip to content

Commit

Permalink
Update tests to use both the token and the AST based finder.
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed May 11, 2018
1 parent ec5d003 commit 3ed9968
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 9 deletions.
22 changes: 22 additions & 0 deletions test/both.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ test('both', function (t) {
t.end();
});

test('both fullParse', function (t) {
var modules = detective.find(src, { fullParse: true });
t.deepEqual(modules.strings, [ 'a', 'b' ]);
t.deepEqual(modules.expressions, [ "'c' + x", "'d' + y" ]);
t.notOk(modules.nodes, 'has no nodes');
t.end();
});

test('both with nodes specified in opts', function (t) {
var modules = detective.find(src, { nodes: true });
t.deepEqual(modules.strings, [ 'a', 'b' ]);
Expand All @@ -24,3 +32,17 @@ test('both with nodes specified in opts', function (t) {
'has a node for each require');
t.end();
});

test('both with nodes and fullParse', function (t) {
var modules = detective.find(src, { nodes: true, fullParse: true });
t.deepEqual(modules.strings, [ 'a', 'b' ]);
t.deepEqual(modules.expressions, [ "'c' + x", "'d' + y" ]);
t.deepEqual(
modules.nodes.map(function (n) {
var arg = n.arguments[0];
return arg.value || arg.left.value;
}),
[ 'a', 'b', 'c', 'd' ],
'has a node for each require');
t.end();
});
1 change: 1 addition & 0 deletions test/chained.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ var src = fs.readFileSync(__dirname + '/files/chained.js');

test('chained', function (t) {
t.deepEqual(detective(src), [ 'c', 'b', 'a' ]);
t.deepEqual(detective(src, { fullParse: true }), [ 'c', 'b', 'a' ]);
t.end();
});
7 changes: 7 additions & 0 deletions test/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ test('comment', function (t) {
t.notOk(modules.nodes, 'has no nodes');
t.end();
});

test('comment fullParse', function (t) {
var modules = detective.find(src, { fullParse: true });
t.deepEqual(modules.strings, [ 'beep' ]);
t.notOk(modules.nodes, 'has no nodes');
t.end();
});
3 changes: 2 additions & 1 deletion test/complicated.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ var sources = [
];

test('complicated', function (t) {
t.plan(sources.length);
t.plan(sources.length * 2);
sources.forEach(function(src) {
t.deepEqual(detective(src), [ 'a' ]);
t.deepEqual(detective(src, { fullParse: true }), [ 'a' ]);
});
});
3 changes: 2 additions & 1 deletion test/es6-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/es6-module.js');

test('es6-module', function (t) {
t.plan(1);
t.plan(2);
t.deepEqual(detective(src, {parse: {sourceType: 'module'}}), [ 'a', 'b' ]);
t.deepEqual(detective(src, {parse: {sourceType: 'module'}, fullParse: true}), [ 'a', 'b' ]);
});
3 changes: 2 additions & 1 deletion test/generators.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/generators.js');

test('generators', function (t) {
t.plan(1);
t.plan(2);
t.deepEqual(detective(src), [ 'a', 'b' ]);
t.deepEqual(detective(src, { fullParse: true }), [ 'a', 'b' ]);
});
1 change: 1 addition & 0 deletions test/nested.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ var src = fs.readFileSync(__dirname + '/files/nested.js');

test('nested', function (t) {
t.deepEqual(detective(src), [ 'a', 'b', 'c' ]);
t.deepEqual(detective(src, { fullParse: true }), [ 'a', 'b', 'c' ]);
t.end();
});
17 changes: 16 additions & 1 deletion test/noargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ var fs = require('fs');
var src = [ 'fn();', 'otherfn();', 'fn();' ].join('\n')

test('noargs', function (t) {
t.plan(1);
t.plan(2);
t.deepEqual(detective(src, { word: 'fn' }).length, 0, 'finds no arg id');
t.deepEqual(detective(src, { word: 'fn', fullParse: true }).length, 0, 'finds no arg id');
});

test('find noargs with nodes', function (t) {
Expand All @@ -24,3 +25,17 @@ test('find noargs with nodes', function (t) {
'all matches are correct'
);
});

test('find noargs with nodes and fullParse', function (t) {
t.plan(4);
var modules = detective.find(src, { word: 'fn', nodes: true, fullParse: true });
t.equal(modules.strings.length, 0, 'finds no arg id');
t.equal(modules.expressions.length, 0, 'finds no expressions');
t.equal(modules.nodes.length, 2, 'finds a node for each matching function call');
t.equal(
modules.nodes.filter(function (x) {
return x.callee.name === 'fn'
}).length, 2,
'all matches are correct'
);
});
3 changes: 2 additions & 1 deletion test/return.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fs = require('fs');
var src = [ 'require("a")\nreturn' ];

test('return', function (t) {
t.plan(1);
t.plan(2);
t.deepEqual(detective(src), [ 'a' ]);
t.deepEqual(detective(src, { fullParse: true }), [ 'a' ]);
});
3 changes: 2 additions & 1 deletion test/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/scope.js');

test('scope', function (t) {
t.plan(1);
t.plan(2);
t.deepEqual(detective(src), [ './x', './z' ]);
t.deepEqual(detective(src, { fullParse: true }), [ './x', './z' ]);
});
6 changes: 5 additions & 1 deletion test/set-in-object-pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ test('set in object pattern', function (t) {
detective(src, { word : 'load' }),
[ 'a', 'b', 'c', 'tt' ]
);
t.deepEqual(
detective(src, { word : 'load', fullParse: true }),
[ 'a', 'b', 'c', 'tt' ]
);
t.end();
});
});
3 changes: 2 additions & 1 deletion test/shebang.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/shebang.js');

test('shebang', function (t) {
t.plan(1);
t.plan(2);
t.deepEqual(detective(src), [ 'a', 'b', 'c' ]);
t.deepEqual(detective(src, { fullParse: true }), [ 'a', 'b', 'c' ]);
});
3 changes: 3 additions & 0 deletions test/sparse-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ test('sparse-array', function (t) {
t.doesNotThrow(function () {
detective(src)
})
t.doesNotThrow(function () {
detective(src, { fullParse: true })
})
t.end();
});

Expand Down
1 change: 1 addition & 0 deletions test/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ var src = fs.readFileSync(__dirname + '/files/strings.js');

test('single', function (t) {
t.deepEqual(detective(src), [ 'a', 'b', 'c', 'events', 'doom', 'y', 'events2' ]);
t.deepEqual(detective(src, { fullParse: true }), [ 'a', 'b', 'c', 'events', 'doom', 'y', 'events2' ]);
t.end();
});
4 changes: 4 additions & 0 deletions test/word.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ test('word', function (t) {
detective(src, { word : 'load' }),
[ 'a', 'b', 'c', 'events', 'doom', 'y', 'events2' ]
);
t.deepEqual(
detective(src, { word : 'load', fullParse: true }),
[ 'a', 'b', 'c', 'events', 'doom', 'y', 'events2' ]
);
t.end();
});
3 changes: 2 additions & 1 deletion test/yield.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fs = require('fs');
var src = fs.readFileSync(__dirname + '/files/yield.js');

test('yield', function (t) {
t.plan(1);
t.plan(2);
t.deepEqual(detective(src), [ 'a', 'c' ]);
t.deepEqual(detective(src, { fullParse: true }), [ 'a', 'c' ]);
});

0 comments on commit 3ed9968

Please sign in to comment.