diff --git a/addon/index.ts b/addon/index.ts index 2772e75..9c4d542 100644 --- a/addon/index.ts +++ b/addon/index.ts @@ -64,14 +64,17 @@ export function advanceTo(name: string): MilestoneTarget { * When not activated, code wrapped in a milestone is immediately invoked as though * the wrapper weren't there at all. */ -export function milestone>(name: string, callback: () => T): T { +export function milestone>(name: string, callback: () => T): T; +export function milestone(name: string): PromiseLike; +export function milestone(name: string, callback?: () => any): PromiseLike { let coordinator = CoordinatorImpl.forMilestone(name); + let action = callback || (() => Promise.resolve()); if (coordinator) { debugActive('reached active milestone %s', name); - return coordinator._milestoneReached(name, callback); + return coordinator._milestoneReached(name, action); } else { debugInactive('skipping inactive milestone %s', name); - return callback(); + return action(); } } diff --git a/tests/integration/milestones-test.ts b/tests/integration/milestones-test.ts index 9450751..69f726f 100644 --- a/tests/integration/milestones-test.ts +++ b/tests/integration/milestones-test.ts @@ -20,12 +20,25 @@ module('Integration | milestones', function(hooks) { }); module('with no milestones active', function() { - test('milestones are inert', async function(assert) { + test('milestones with callbacks are inert', async function(assert) { let { first, second } = await program(); assert.equal(location, 'two-completed'); assert.equal(first, 1); assert.equal(second, 2); }); + + test('milestones without callbacks are inert', async function(assert) { + let program = async () => { + let first = await milestone('one'); + let second = await milestone('two'); + return { first, second }; + }; + + assert.deepEqual(await program(), { + first: undefined, + second: undefined, + }); + }); }); module('with milestones active', function(hooks) { @@ -127,6 +140,19 @@ module('Integration | milestones', function(hooks) { assert.equal(await program(), boom); }); + test('with no callback', async function(assert) { + let program = async () => { + let first = await milestone('one'); + let second = await milestone('two'); + return { first, second }; + }; + + let programPromise = program(); + await advanceTo('one').andContinue(); + await advanceTo('two').andContinue(); + assert.deepEqual(await programPromise, { first: undefined, second: undefined }); + }); + test('stepping through each location', async function(assert) { let programPromise = program();