Skip to content

Commit

Permalink
fix(faketime): fix fakeTime for RxJS 7
Browse files Browse the repository at this point in the history
fix breaking changes of RxJS 7 that break the fakeTime util

fix #39
  • Loading branch information
shairez committed Dec 10, 2021
1 parent 00ee48a commit 8acd37b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"prettier": "2.0.5",
"pretty-quick": "2.0.1",
"rimraf": "3.0.2",
"rxjs": "^6.5.5",
"rxjs": "~7.4.0",
"semantic-release": "^17.0.7",
"travis-deploy-once": "^5.0.11",
"ts-jest": "^25.4.0",
Expand Down
33 changes: 11 additions & 22 deletions src/fake-time.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { VirtualTimeScheduler } from 'rxjs';
import { AsyncScheduler } from 'rxjs/internal/scheduler/AsyncScheduler';
import { TestScheduler } from 'rxjs/testing';

export function fakeTime(callback: (...args: any[]) => any) {
if (callback.length === 0) {
Expand All @@ -11,31 +10,21 @@ export function fakeTime(callback: (...args: any[]) => any) {

if (callback.length === 1) {
return function () {
const virtualScheduler = new VirtualTimeScheduler();
AsyncScheduler.delegate = virtualScheduler;
/* istanbul ignore next */
const testScheduler = new TestScheduler(() => {});

function customFlush() {
virtualScheduler.flush();
}
const originalReturnedValue = callback(customFlush);

AsyncScheduler.delegate = undefined;

return originalReturnedValue;
return testScheduler.run(({ flush }) => {
return callback(flush);
});
};
}

return function (done: () => void) {
const virtualScheduler = new VirtualTimeScheduler();
AsyncScheduler.delegate = virtualScheduler;

function customFlush() {
virtualScheduler.flush();
}
const originalReturnedValue = callback(customFlush, done);

AsyncScheduler.delegate = undefined;
/* istanbul ignore next */
const testScheduler = new TestScheduler(() => {});

return originalReturnedValue;
return testScheduler.run(({ flush }) => {
return callback(flush, done);
});
};
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"emitDecoratorMetadata": true,
"declaration": true, // generate .d.ts files
"declarationMap": true,
"noImplicitAny": true,
"noImplicitAny": false,
"esModuleInterop": true,
"sourceMap": true,
"downlevelIteration": true,
Expand Down
14 changes: 13 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7618,13 +7618,20 @@ run-queue@^1.0.0, run-queue@^1.0.3:
dependencies:
aproba "^1.1.1"

rxjs@^6.4.0, rxjs@^6.5.3, rxjs@^6.5.5:
rxjs@^6.4.0, rxjs@^6.5.3:
version "6.5.5"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.5.tgz#c5c884e3094c8cfee31bf27eb87e54ccfc87f9ec"
integrity sha512-WfQI+1gohdf0Dai/Bbmk5L5ItH5tYqm3ki2c5GdWhKjalzjg93N3avFjVStyZZz+A2Em+ZxKH5bNghw9UeylGQ==
dependencies:
tslib "^1.9.0"

rxjs@~7.4.0:
version "7.4.0"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.4.0.tgz#a12a44d7eebf016f5ff2441b87f28c9a51cebc68"
integrity sha512-7SQDi7xeTMCJpqViXh8gL/lebcwlp3d831F05+9B44A4B0WfsEwUQHR64gsH1kvJ+Ep/J9K2+n1hVl1CsGN23w==
dependencies:
tslib "~2.1.0"

safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@^5.2.0, safe-buffer@~5.2.0:
version "5.2.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
Expand Down Expand Up @@ -8516,6 +8523,11 @@ tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.11.1.tgz#eb15d128827fbee2841549e171f45ed338ac7e35"
integrity sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==

tslib@~2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==

tslint@6.1.1:
version "6.1.1"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-6.1.1.tgz#ac03fbd17f85bfefaae348b353b25a88efe10cde"
Expand Down

0 comments on commit 8acd37b

Please sign in to comment.