Skip to content

Commit

Permalink
Merge pull request #534 from kwonoj/refactor-test-scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj authored Nov 6, 2020
2 parents c2922e5 + 054cea2 commit eb30e74
Show file tree
Hide file tree
Showing 21 changed files with 2,176 additions and 1,381 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# [2.0.0-beta.3](https://github.com/kwonoj/rx-sandbox/compare/v2.0.0-beta.2...v2.0.0-beta.3) (2020-11-06)


### Bug Fixes

* **sandboxinstance:** expose scheduler instance ([6ada7a5](https://github.com/kwonoj/rx-sandbox/commit/6ada7a52c7e9bd25ae83b41eba1e786b194ffc93))


### Features

* **creattestscheduler:** support flush with native async tick ([93a99a4](https://github.com/kwonoj/rx-sandbox/commit/93a99a45bf63698f4e721a75f85fbf22f74eea68))
* **marbleassert:** jasmine style toEqual() matcher ([6dcc7f8](https://github.com/kwonoj/rx-sandbox/commit/6dcc7f89936f971da66e0e4d0b286203b0fa68b9))
* **sandbox:** accept config object ([3464710](https://github.com/kwonoj/rx-sandbox/commit/346471048564667c3a41df256467299fcb43eaa0))
* **sandbox:** expose interface to create async flush scheduler ([f20fb40](https://github.com/kwonoj/rx-sandbox/commit/f20fb4088ae3fb2d3ee8501fa38b392685a67063))
* **sandbox:** support to create async flush instance ([b9c5e71](https://github.com/kwonoj/rx-sandbox/commit/b9c5e71281cc3fd7def2c39ea94ab21c767585a8))


### BREAKING CHANGES

* **sandboxinstance:** scheduler no longer expose `maxFrame` property. use
property returned by `sandbox.create()`.
* **sandbox:** no longer directly export signatures for utilities,
such as `getMessages` due to overloaded signature behaviors. Use
`RxSandboxInstance['name']` or `RxAsyncSandboxInstance['name']` instead
to pick up signatures.



## [1.0.4](https://github.com/kwonoj/rx-sandbox/compare/v1.0.3...v1.0.4) (2020-11-02)


Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ it('testcase', () => {

```typescript
rxSandbox.create(autoFlush?: boolean, frameTimeFactor?: number, maxFrameValue?: number): RxSandboxInstance

rxSandbox.create({
autoFlush?: boolean,
frameTimeFactor?: number,
maxFrameValue?: boolean,
flushWithAsyncTick?: boolean,
}): RxSandboxInstance | RxAsyncSandboxInstance
```

`frameTimeFactor` allows to override default frame passage `1` to given value.
Expand Down Expand Up @@ -232,9 +239,33 @@ expect(messages).to.deep.equal(expected);

//subsequent attempt will throw
expect(() => getMessages(e1.mapTo('y'))).to.throw();
```

### Scheduling flush into native async tick (Experimental)

If you create sandbox instance with `flushWithAsyncTick` option, sandbox will return instance of `RxAsyncSandboxInstance` which all of flush interfaces need to be asynchronously awaited:

```
interface RxAsyncSandboxInstance {
...,
advanceTo(toFrame: number) => Promise<void>;
flush: () => Promise<void>;
getMessages: <T = string>(observable: Observable<T>, unsubscriptionMarbles?: string | null) => Promise<void>;
}
```

It is not uncommon practices chaining native async function or promise inside of observables, especially for inner observables. Let's say if there's a redux-observable epic like below

```
const epic = (actionObservable) => actionObservable.ofType(...).pipe((mergeMap) => {
return new Promise.resolve(...);
})
```

Testing this epic via rxSandbox won't work. Once sandbox flush all internal actions synchronously, promises are still scheduled into next tick so there's no inner observable subscription value collected by flush. `RxAsyncSandboxInstance` in opposite no longer flush actions synchronously but schedule each individual action into promise tick to try to collect values from async functions.

**NOTE: this is beta feature and likely have some issues. Also Until stablized internal implementation can change without semver breaking.**

#### Custom frame time factor

Each timeframe `-` is predefined to `1`, can be overridden.
Expand Down
3 changes: 0 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ module.exports = {
}
},
"bail": true,
"resetMocks": true,
"clearMocks": true,
"resetModules": true,
"testEnvironment": "node",
"moduleFileExtensions": [
"js",
Expand Down
Loading

0 comments on commit eb30e74

Please sign in to comment.