Skip to content

Commit

Permalink
async test for node 7
Browse files Browse the repository at this point in the history
  • Loading branch information
substack authored and substack committed Mar 1, 2017
1 parent 06a47d1 commit fe8c57b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: node_js
node_js:
- "5"
- "7"
- "6"
- "4"
- "0.12"
- "0.10"
Expand Down
24 changes: 24 additions & 0 deletions test/async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var browserify = require('../');
var fs = require('fs');
var vm = require('vm');
var test = require('tap').test;

var src = fs.readFileSync(__dirname + '/async/src.js','utf8');
var canAsync = true;
try { Function(src) } catch (err) { canAsync = false }

if (!canAsync) console.error('# async/await unsupported in this environment')
else test('async/await', function (t) {
t.plan(2);
var b = browserify(__dirname + '/async/src.js');
b.bundle(function (err, src) {
t.error(err)
var c = {
console: { log: log },
setTimeout: setTimeout,
clearTimeout: clearTimeout
}
vm.runInNewContext(src, c);
function log (msg) { t.equal(msg, 60) }
});
});
8 changes: 8 additions & 0 deletions test/async/src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function f (x) { return new Promise(resolve => {
process.nextTick(() => { resolve(x) }) }) }

async function add (x) {
return x + await f(20) + await f(30)
}

add(10).then(v => { console.log(v) })

0 comments on commit fe8c57b

Please sign in to comment.