Comments (3)
@jamestalmage Ah, Good catch! Thank you for sharing your thought!
import assert from 'power-assert';
const tests = [];
function test (name, body) {
tests.push({
name,
body
});
}
function later (millis, value) {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(`captured [${value}]`);
resolve(value);
}, millis);
});
};
test('testA', async () => {
const val1 = 'a1';
const val2 = 'a2';
const delay1 = 1000;
const delay2 = 6000;
try {
assert.equal(await later(delay1, val1), await later(delay2, val2));
} catch (e) {
console.log(e.message);
} finally {
console.log(`done [testA]`);
}
});
test('testB', async () => {
const val3 = 'b1';
const val4 = 'b2';
const delay3 = 2000;
const delay4 = 3000;
try {
assert.equal(await later(delay3, val3), await later(delay4, val4));
} catch (e) {
console.log(e.message);
} finally {
console.log(`done [testB]`);
}
});
for (let {name, body} of tests) {
console.log(`running [${name}]`);
body();
}
Produces power-assert output that is totally broken.
$ babel-node interleaving_promises.js
running [testA]
running [testB]
captured [a1]
captured [b1]
captured [b2]
# interleaving_promises.js:41
assert.equal(await later(delay3, val3), await later(delay4, val4))
| | | |
| | | |a2"
| | |000 "b2"
"b1" "b2" 3000
done [testB]
captured [a2]
# interleaving_promises.js:27
assert.equal(await later(delay1, val1), await later(delay2, val2))
| | | |
"a1" 2000 "b1" "a2"
done [testA]
$
I'll fix this problem in this issue
from empower.
Thanks @twada, I meant to write that test and verify this.
Could we maybe introduce a runtime helper? I think Babel 6 now includes an easy way to do that (from what I have browsed of the source.
t.is(await foo(), await bar());
var __powerAssertRuntime = require(...); // once at the top of the file.
// create a unique name - I think Babel might have a tool for this.
const capt_1 = new __powerAssertRuntime.Capture();
const capt_2 = new __powerAssertRuntime.Capture();
t.is(await capt_1._expr(capt_1._capt(foo(), {powerAssertContext:...})), await capt_2._... )
from empower.
@jamestalmage Yeah, I'm thinking about introducing runtime helper too.
This is my thought but I'll make prototypes of both.
from empower.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from empower.