-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Action interface + add
testee
param to act
- Loading branch information
Showing
8 changed files
with
52 additions
and
19 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
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 |
---|---|---|
@@ -1,7 +1,40 @@ | ||
import {setTimeout} from 'timers/promises'; | ||
import {Testee} from '../Testee'; | ||
import {TestbedEvents} from '../../testbeds/Testbed'; | ||
import {Breakpoint} from '../../debug/Breakpoint'; | ||
import {breakpointHitParser} from '../../messaging/Parsers'; | ||
|
||
export type Action<T> = () => Promise<T>; | ||
export interface Action<T> { | ||
act: (testee: Testee) => Promise<T>; | ||
} | ||
|
||
export interface PureAction<T> extends Action<T> { | ||
act: () => Promise<T>; | ||
} | ||
|
||
export function wait(time: number): PureAction<boolean> { | ||
return {act: () => setTimeout(time).then(() => true)} | ||
} | ||
|
||
export function awaitBreakpoint(): Action<Breakpoint> { | ||
return { | ||
act: (testee: Testee) => { | ||
return new Promise<Breakpoint>((resolve) => { | ||
function breakpointListener(message: string) { | ||
// check breakpoint hit message | ||
try { | ||
const breakpoint = breakpointHitParser(message); | ||
// on success: remove listener + resolve | ||
testee.testbed?.removeListener(TestbedEvents.OnMessage, breakpointListener); | ||
resolve(breakpoint); | ||
} catch (e) { | ||
|
||
} | ||
} | ||
|
||
export function wait(time: number): Action<boolean> { | ||
return () => setTimeout(time).then(() => true) | ||
// await breakpoint hit | ||
testee.testbed?.on(TestbedEvents.OnMessage, breakpointListener) | ||
}); | ||
} | ||
}; | ||
} |
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
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
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