forked from angular/jasminewd
-
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.
feat(SELENIUM_PROMISE_MANAGER): Don't rely on
webdriver.promise
fun…
…ctions While we support `SELENIUM_PROMISE_MANAGER=0` already, we rely on `SimpleScheduler` and some other utility functions which will be going away after the control flow has been fully deprecated. This commit allows jasminewd to work without those utility functions, and even allows people to pass jasminewd their own custom scheduler implementation. This does not fix our tests, which will also break when those utility functions go away. See angular#81 Closes angular#80
- Loading branch information
Showing
6 changed files
with
182 additions
and
39 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
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,68 @@ | ||
# Schedulers | ||
|
||
Many of the core features of jasminewd are centered around automatically synchronizing your tests | ||
with the WebDriver control flow. However, jasminewd can synchronize with any scheduler as long as | ||
it implements the following interface: | ||
|
||
```ts | ||
interface Scheduler { | ||
execute<T>(fn: () => Promise<T>|T): Promise<T>; | ||
} | ||
``` | ||
|
||
Where `execute` is the function used to put something on the scheduler. As long as your scheduler | ||
implements this interface, you can pass it into `require('jasminewd2').init`. | ||
|
||
## Custom Promise Implementation | ||
|
||
Some schedulers need scheduled functions to use a specific implementation of the promise API. For | ||
instance, WebDriver has its `ManagedPromise` implementation, which it needs in order to track | ||
tasks across `then()` blocks. If your scheduler has its own promise implementation, you can | ||
implement the following interface: | ||
|
||
```ts | ||
interface SchedulerWithCustomPromises { | ||
execute<T>(fn: () => CustomPromise<T>|T): CustomPromise<T>; | ||
promise<T>(resolver: (resolve: (T) => void, reject: (any) => void) => void): CustomPromise<T>; | ||
} | ||
``` | ||
|
||
If the `promise` function is specified, jasminewd will use that function to generate all of its | ||
internal promises. If `scheduler.promise` is not specified, jasminewd will try to use WebDriver's | ||
`ManagedPromise`. If `ManagedPromise` is not available (e.g. the control flow is disabled), | ||
jasminewd will default to using native promises. | ||
|
||
### Idle API | ||
|
||
If your scheduler requires a custom promise implementation, it is highly recommended that you | ||
implement the Idle API. This will help to mitigate issues with users who sometimes use other | ||
promise implementations (see https://github.com/angular/jasminewd/issues/68#issuecomment-262317167). | ||
To do this, implement the following interface: | ||
|
||
```ts | ||
var EventEmitter = require('events'); | ||
|
||
interface SchedulerWithIdleAPI extends EventEmitter { | ||
execute<T>(fn: () => CustomPromise<T>|T): CustomPromise<T>; | ||
promise<T>(resolver: (resolve: (T) => void, reject: (any) => void) => void): CustomPromise<T>; | ||
isIdle(): boolean; | ||
} | ||
``` | ||
|
||
Your scheduler must emit `"idle"` when it becomes idle. | ||
|
||
|
||
### Reset API | ||
|
||
If you want your scheduler to be reset whenever a spec times out, implement the following interface: | ||
|
||
```ts | ||
interface SchedulerWithResetAPI { | ||
execute<T>(fn: () => CustomPromise<T>|T): CustomPromise<T>; | ||
reset(): void; | ||
} | ||
``` | ||
|
||
jasminewd will automatically look for a `reset` function and call it when specs time out. This is | ||
useful so that if a spec executes a task that hangs, only that spec will timeout (as opposed to | ||
tying up the scheduler and causing all future specs to timeout). |
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