You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
843 B

2 years ago
  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. test('both', function (t) {
  6. var modules = detective.find(src);
  7. t.deepEqual(modules.strings, [ 'a', 'b' ]);
  8. t.deepEqual(modules.expressions, [ "'c' + x", "'d' + y" ]);
  9. t.notOk(modules.nodes, 'has no nodes');
  10. t.end();
  11. });
  12. test('both with nodes specified in opts', function (t) {
  13. var modules = detective.find(src, { nodes: true });
  14. t.deepEqual(modules.strings, [ 'a', 'b' ]);
  15. t.deepEqual(modules.expressions, [ "'c' + x", "'d' + y" ]);
  16. t.deepEqual(
  17. modules.nodes.map(function (n) {
  18. var arg = n.arguments[0];
  19. return arg.value || arg.left.value;
  20. }),
  21. [ 'a', 'b', 'c', 'd' ],
  22. 'has a node for each require');
  23. t.end();
  24. });