syntax_cache.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. var Seq = require('seq');
  2. var browserify = require('../');
  3. var test = require('tap').test;
  4. var shasum = require('shasum-object');
  5. test('syntax cache - valid', function (t) {
  6. t.plan(2);
  7. var expectedCache = {}
  8. var cacheKey;
  9. var b = browserify(__dirname + '/syntax_cache/valid.js');
  10. b.once('dep', function(row) {
  11. cacheKey = shasum(row.source);
  12. expectedCache[cacheKey] = true;
  13. });
  14. Seq()
  15. .seq(function() { b.bundle(this); })
  16. .seq(function() {
  17. t.deepEqual(b._syntaxCache, expectedCache);
  18. b._syntaxCache[cacheKey] = expectedCache[cacheKey] = 'beep';
  19. b.bundle(function(err, src) {
  20. // if the cache worked, the "cacheKey"
  21. // should not be reset to "true"
  22. t.deepEqual(b._syntaxCache, expectedCache);
  23. });
  24. });
  25. });
  26. test('syntax cache - skip invalid', function (t) {
  27. t.plan(5);
  28. var b = browserify(__dirname + '/syntax_cache/invalid.js');
  29. Seq()
  30. .seq(function() { b.bundle(this); })
  31. .catch(function(lastErr) {
  32. t.deepEqual(b._syntaxCache, {});
  33. t.similar(String(lastErr), /ParseError/);
  34. b.bundle(function(err, src) {
  35. t.deepEqual(b._syntaxCache, {});
  36. t.similar(String(err), /ParseError/);
  37. t.notEqual(lastErr, err, 'errors should be unique');
  38. });
  39. });
  40. });