async.js 730 B

123456789101112131415161718192021222324
  1. var browserify = require('../');
  2. var fs = require('fs');
  3. var vm = require('vm');
  4. var test = require('tap').test;
  5. var src = fs.readFileSync(__dirname + '/async/src.js','utf8');
  6. var canAsync = true;
  7. try { Function(src) } catch (err) { canAsync = false }
  8. if (!canAsync) console.error('# async/await unsupported in this environment')
  9. else test('async/await', function (t) {
  10. t.plan(2);
  11. var b = browserify(__dirname + '/async/src.js');
  12. b.bundle(function (err, src) {
  13. t.error(err)
  14. var c = {
  15. console: { log: log },
  16. setTimeout: setTimeout,
  17. clearTimeout: clearTimeout
  18. }
  19. vm.runInNewContext(src, c);
  20. function log (msg) { t.equal(msg, 60) }
  21. });
  22. });