both.js 843 B

1234567891011121314151617181920212223242526
  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. });