JAVASCRIPT   79

async.js

Guest on 10th October 2021 02:21:31 PM

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

Raw Paste


Login or Register to edit or fork this paste. It's free.