| 1 |
import * as evaluator from "../../_namespaces/evaluator"; |
| 2 |
|
| 3 |
describe("unittests:: evaluation:: awaiter", () => { |
| 4 |
// NOTE: This could break if the ECMAScript spec ever changes the timing behavior for Promises (again) |
| 5 |
it("await (es5)", async () => { |
| 6 |
const result = evaluator.evaluateTypeScript(` |
| 7 |
async function a(msg: string) { |
| 8 |
await Promise.resolve(); |
| 9 |
output.push(msg); |
| 10 |
} |
| 11 |
function b(msg: string) { |
| 12 |
return Promise.resolve().then(() => { |
| 13 |
output.push(msg); |
| 14 |
}); |
| 15 |
} |
| 16 |
export const output: string[] = []; |
| 17 |
export async function main() { |
| 18 |
const p1 = a('1'); |
| 19 |
const p2 = b('2'); |
| 20 |
await Promise.all([p1, p2]); |
| 21 |
} |
| 22 |
`); |
| 23 |
await result.main(); |
| 24 |
assert.deepEqual(result.output, ["1", "2"]); |
| 25 |
}); |
| 26 |
}); |