This repository has been archived by the owner on Aug 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["es2015"], | ||
"plugins": ["transform-async-to-generator"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict' | ||
// **Github:** https://github.com/thunks/tman | ||
// | ||
// **License:** MIT | ||
|
||
// `babel-node --presets es2015 --plugins transform-async-to-generator bin/tman example/es-next.es` | ||
// or (with .babelrc) | ||
// `tman -r babel-register -r babel-polyfill example/es-next.es` | ||
|
||
import assert from 'assert' | ||
import tman from '..' | ||
|
||
var count = 0 | ||
// async "after hook" | ||
tman.after(async () => { | ||
assert.strictEqual(await Promise.resolve(count++), 4) | ||
}) | ||
|
||
tman.it('async/await asynchronous test', async function () { | ||
assert.strictEqual(await Promise.resolve(count++), 0) | ||
assert.strictEqual(await new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
resolve(count++) | ||
}, 100) | ||
}), 1) | ||
}) | ||
|
||
tman.it('generator asynchronous test', function * () { | ||
// yield Promise | ||
assert.strictEqual(yield Promise.resolve(count++), 2) | ||
// yield thunk function | ||
assert.strictEqual(yield (done) => { | ||
setTimeout(() => { | ||
done(null, count++) | ||
}, 100) | ||
}, 3) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters