Skip to content

Commit 7a72307

Browse files
authored
Merge pull request #635 from kwonoj/bump-rxjs
2 parents 2b1e571 + 86781c0 commit 7a72307

File tree

9 files changed

+2316
-1129
lines changed

9 files changed

+2316
-1129
lines changed

jest.config.js

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,26 @@
11
const isWallaby = !!process.env.WALLABY_ENV;
22

33
module.exports = {
4-
"preset": "ts-jest",
5-
"testMatch": [
6-
"**/spec/**/*-spec.ts"
7-
],
8-
"globals": {
9-
"ts-jest": {
10-
"diagnostics": false
11-
}
4+
preset: 'ts-jest',
5+
testMatch: ['**/spec/**/*-spec.ts'],
6+
globals: {
7+
'ts-jest': {
8+
diagnostics: false,
9+
},
1210
},
13-
"bail": true,
14-
"testEnvironment": "node",
15-
"moduleFileExtensions": [
16-
"js",
17-
"jsx",
18-
"json",
19-
"ts",
20-
"tsx"
21-
],
22-
"testPathIgnorePatterns": [
23-
"/.tmp/"
24-
],
25-
"coverageReporters": [
26-
"lcov"
27-
],
28-
reporters: !isWallaby ? [ "jest-spin-reporter" ] : undefined,
29-
"collectCoverageFrom": [
30-
"src/**/*.{ts, tsx}",
31-
"!**/*.d.ts"
11+
resolver: '<rootDir>/spec/exportMapResolver.js',
12+
bail: true,
13+
testEnvironment: 'node',
14+
moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'],
15+
testPathIgnorePatterns: ['/.tmp/'],
16+
coverageReporters: ['lcov'],
17+
reporters: !isWallaby ? ['jest-spin-reporter'] : undefined,
18+
collectCoverageFrom: ['src/**/*.{ts, tsx}', '!**/*.d.ts'],
19+
coveragePathIgnorePatterns: [
20+
'<rootDir>/node_modules/',
21+
'<rootDir>/spec/.*\\.(ts|js)$',
22+
'<rootDir>/build/.*\\.(ts|js)$',
23+
'<rootDir>/src/RxSandbox.ts',
24+
'<rootDir>/src/RxSandboxInstance.ts',
3225
],
33-
"coveragePathIgnorePatterns": [
34-
"<rootDir>/node_modules/",
35-
"<rootDir>/spec/.*\\.(ts|js)$",
36-
"<rootDir>/build/.*\\.(ts|js)$",
37-
"<rootDir>/src/RxSandbox.ts",
38-
"<rootDir>/src/RxSandboxInstance.ts"
39-
]
40-
}
26+
};

package-lock.json

Lines changed: 2192 additions & 988 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,27 @@
4747
},
4848
"homepage": "https://github.com/kwonoj/rx-sandbox#readme",
4949
"devDependencies": {
50-
"@commitlint/cli": "^11.0.0",
51-
"@commitlint/config-angular": "^11.0.0",
52-
"@types/jest": "^26.0.15",
53-
"@types/node": "^14.14.6",
50+
"@commitlint/cli": "^12.1.4",
51+
"@commitlint/config-angular": "^12.1.4",
52+
"@types/jest": "^26.0.23",
53+
"@types/node": "^15.3.0",
5454
"conventional-changelog-cli": "^2.1.1",
5555
"cz-conventional-changelog": "^3.3.0",
56+
"enhanced-resolve": "^5.8.2",
5657
"husky": "^3.1.0",
5758
"jest": "^26.6.3",
5859
"jest-spin-reporter": "^2.0.0",
59-
"lint-staged": "^10.5.1",
60+
"lint-staged": "^11.0.0",
6061
"npm-run-all": "^4.1.5",
61-
"prettier": "^2.1.2",
62-
"rxjs": "^7.0.0-beta.0",
62+
"prettier": "^2.3.0",
63+
"rxjs": "^7.0.1",
6364
"shx": "^0.3.3",
64-
"ts-jest": "^26.4.3",
65+
"ts-jest": "^26.5.6",
6566
"tslint": "^6.1.3",
66-
"typescript": "^4.0.5"
67+
"typescript": "^4.2.4"
6768
},
6869
"peerDependencies": {
69-
"rxjs": "^7.0.0-beta.8"
70+
"rxjs": "^7.0.1"
7071
},
7172
"dependencies": {
7273
"expect": "^26.6.2",

spec/exportMapResolver.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// temporary workaround while we wait for https://github.com/facebook/jest/issues/9771
2+
const resolver = require('enhanced-resolve').create.sync({
3+
conditionNames: ['require', 'node', 'default', 'import'],
4+
extensions: ['.js', '.json', '.node', '.ts'],
5+
});
6+
7+
module.exports = function (request, options) {
8+
return resolver(options.basedir, request);
9+
};

spec/message/TestMessage-spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { ObservableNotification } from 'rxjs';
12
import { complete, error, next, subscribe, TestMessageValue } from '../../src/message/TestMessage';
2-
import { COMPLETE_NOTIFICATION, errorNotification, nextNotification } from '../../src/utils/coreInternalImport';
33

44
describe('TestMessageValue', () => {
55
it('should create metadata', () => {
6-
const notification = nextNotification('meh');
6+
const notification = { kind: 'N', value: 'meh' } as ObservableNotification<string>;
77

88
const message = new TestMessageValue(10, notification);
99

@@ -15,19 +15,19 @@ describe('TestMessageValue', () => {
1515
it('should create next', () => {
1616
const value = next(10, 'meh');
1717

18-
expect(value).toEqual(new TestMessageValue(10, nextNotification('meh')));
18+
expect(value).toEqual(new TestMessageValue(10, { kind: 'N', value: 'meh' }));
1919
});
2020

2121
it('should create error', () => {
2222
const errorValue = error(10, 'meh');
2323

24-
expect(errorValue).toEqual(new TestMessageValue(10, errorNotification('meh')));
24+
expect(errorValue).toEqual(new TestMessageValue(10, { kind: 'E', error: 'meh' }));
2525
});
2626

2727
it('should create complete', () => {
2828
const completeValue = complete(10);
2929

30-
expect(completeValue).toEqual(new TestMessageValue(10, COMPLETE_NOTIFICATION));
30+
expect(completeValue).toEqual(new TestMessageValue(10, { kind: 'C' }));
3131
});
3232

3333
it('should create subscription log', () => {

src/message/TestMessage.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { ObservableNotification } from 'rxjs';
2-
import {
3-
COMPLETE_NOTIFICATION,
4-
errorNotification,
5-
nextNotification,
6-
SubscriptionLog,
7-
} from '../utils/coreInternalImport';
2+
import { SubscriptionLog } from '../utils/coreInternalImport';
83

94
/**
105
* Represents interface for single metadata value emitted by HotObservable<T> or ColdObservable<T>
@@ -29,22 +24,21 @@ class TestMessageValue<T = string> implements TestMessage<T> {
2924
* @param value
3025
*/
3126

32-
const next = <T = string>(frame: number, value: T): TestMessage<T> =>
33-
new TestMessageValue(frame, nextNotification(value));
27+
const next = <T = string>(frame: number, value: T): TestMessage<T> => new TestMessageValue(frame, { kind: 'N', value });
3428

3529
/**
3630
* Utility function to generate TestMessage represents error for Observer::error()
3731
* @param frame virtual frame time when value will be emitted
3832
* @param value
3933
*/
4034
const error = (frame: number, error: any = '#'): TestMessage<any> =>
41-
new TestMessageValue<any>(frame, errorNotification(error));
35+
new TestMessageValue<any>(frame, { kind: 'E', error });
4236

4337
/**
4438
* Utility function to generate TestMessage represents completion for Observer::complete()
4539
* @param frame virtual frame time when value will be emitted
4640
*/
47-
const complete = <T = void>(frame: number): TestMessage<T> => new TestMessageValue<T>(frame, COMPLETE_NOTIFICATION);
41+
const complete = <T = void>(frame: number): TestMessage<T> => new TestMessageValue<T>(frame, { kind: 'C' });
4842

4943
const subscribe = (
5044
subscribedFrame: number = Number.POSITIVE_INFINITY,

src/scheduler/createTestScheduler.ts

Lines changed: 69 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@ import { parseObservableMarble } from '../marbles/parseObservableMarble';
55
import { SubscriptionMarbleToken } from '../marbles/SubscriptionMarbleToken';
66
import { TestMessage } from '../message/TestMessage';
77
import { TestMessageValue } from '../message/TestMessage';
8-
import {
9-
AsyncAction,
10-
ColdObservable,
11-
COMPLETE_NOTIFICATION,
12-
errorNotification,
13-
HotObservable,
14-
nextNotification,
15-
} from '../utils/coreInternalImport';
8+
import { AsyncAction, ColdObservable, HotObservable } from '../utils/coreInternalImport';
169
import { calculateSubscriptionFrame } from './calculateSubscriptionFrame';
1710

1811
/**
@@ -97,11 +90,17 @@ const getCreateHotObservable = (state: SandboxState) => {
9790
* As we don't inherit virtualtimescheduler anymore, only these functions should be
9891
* used to properly flush out actions. Calling `scheduler.flush()` will not do any work.
9992
*/
100-
function getSchedulerFlushFunctions(state: SandboxState, flushWithAsyncTick: true): {
93+
function getSchedulerFlushFunctions(
94+
state: SandboxState,
95+
flushWithAsyncTick: true
96+
): {
10197
flushUntil: (toFrame?: number) => Promise<void>;
10298
advanceTo: (toFrame?: number) => Promise<void>;
10399
};
104-
function getSchedulerFlushFunctions(state: SandboxState, flushWithAsyncTick: false): {
100+
function getSchedulerFlushFunctions(
101+
state: SandboxState,
102+
flushWithAsyncTick: false
103+
): {
105104
flushUntil: (toFrame?: number) => void;
106105
advanceTo: (toFrame?: number) => void;
107106
};
@@ -131,9 +130,11 @@ function getSchedulerFlushFunctions(state: SandboxState, flushWithAsyncTick: boo
131130
* For synchronous loop, it'll use plain `while` loop. In case of flushing with tick, each action
132131
* will be scheduled into promise instead.
133132
*/
134-
function loopActions(loopState: SandboxState,
135-
condition: (loopState: SandboxState) => boolean,
136-
fn: (loopState: SandboxState) => Error | undefined): Promise<Error | undefined> | Error | undefined {
133+
function loopActions(
134+
loopState: SandboxState,
135+
condition: (loopState: SandboxState) => boolean,
136+
fn: (loopState: SandboxState) => Error | undefined
137+
): Promise<Error | undefined> | Error | undefined {
137138
if (!flushWithAsyncTick) {
138139
let fnResult;
139140
while (condition(loopState)) {
@@ -160,15 +161,19 @@ function getSchedulerFlushFunctions(state: SandboxState, flushWithAsyncTick: boo
160161

161162
// flush actions via custom loop fn, as same as
162163
// https://github.com/kwonoj/rx-sandbox/blob/c2922e5c5e2503739c64af626f2861b1e1f38159/src/scheduler/TestScheduler.ts#L166-L173
163-
const loopResult = loopActions(state, (flushState) => {
164-
const action = flushState.scheduler.actions[0];
165-
return !!action && action.delay <= toFrame;
166-
}, (flushState) => {
167-
const action = flushState.scheduler.actions.shift()!;
168-
flushState.scheduler.frame = action.delay;
169-
170-
return action.execute(action.state, action.delay);
171-
});
164+
const loopResult = loopActions(
165+
state,
166+
(flushState) => {
167+
const action = flushState.scheduler.actions[0];
168+
return !!action && action.delay <= toFrame;
169+
},
170+
(flushState) => {
171+
const action = flushState.scheduler.actions.shift()!;
172+
flushState.scheduler.frame = action.delay;
173+
174+
return action.execute(action.state, action.delay);
175+
}
176+
);
172177

173178
const tearDown = (error?: Error) => {
174179
state.flushing = false;
@@ -212,15 +217,20 @@ function getSchedulerFlushFunctions(state: SandboxState, flushWithAsyncTick: boo
212217
}
213218

214219
const flushResult = flushUntil(toFrame);
215-
const tearDown = () => { state.scheduler.frame = toFrame; };
220+
const tearDown = () => {
221+
state.scheduler.frame = toFrame;
222+
};
216223
return isPromise(flushResult) ? flushResult.then(() => tearDown()) : tearDown();
217224
};
218225

219226
return { flushUntil, advanceTo };
220227
}
221228

222229
type getMessages = <T = string>(observable: Observable<T>, unsubscriptionMarbles?: string | null) => void;
223-
type getMessagesWithTick = <T = string>(observable: Observable<T>, unsubscriptionMarbles?: string | null) => Promise<void>;
230+
type getMessagesWithTick = <T = string>(
231+
observable: Observable<T>,
232+
unsubscriptionMarbles?: string | null
233+
) => Promise<void>;
224234

225235
/**
226236
* create getMessages function. Depends on flush, this'll either work asynchronously or synchronously.
@@ -235,11 +245,11 @@ function createGetMessages(state: SandboxState, flush: Function): Function {
235245
const pushMetaData = (notification: ObservableNotification<T>) =>
236246
innerObservableMetadata.push(new TestMessageValue<T>(state.scheduler.frame - outerFrame, notification));
237247

238-
observable.subscribe(
239-
(value) => pushMetaData(nextNotification(value)),
240-
(err) => pushMetaData(errorNotification(err)),
241-
() => pushMetaData(COMPLETE_NOTIFICATION)
242-
);
248+
observable.subscribe({
249+
next: (value) => pushMetaData({ kind: 'N', value }),
250+
error: (error) => pushMetaData({ kind: 'E', error }),
251+
complete: () => pushMetaData({ kind: 'C' }),
252+
});
243253

244254
return innerObservableMetadata;
245255
};
@@ -257,16 +267,15 @@ function createGetMessages(state: SandboxState, flush: Function): Function {
257267

258268
let subscription: Subscription | null = null;
259269
state.scheduler.schedule(() => {
260-
subscription = observable.subscribe(
261-
(value: T) =>
262-
pushMetadata(
263-
nextNotification(
264-
value instanceof Observable ? materializeInnerObservable<T>(value, state.scheduler.frame) : value
265-
)
266-
),
267-
(err: any) => pushMetadata(errorNotification(err)),
268-
() => pushMetadata(COMPLETE_NOTIFICATION)
269-
);
270+
subscription = observable.subscribe({
271+
next: (value: T) =>
272+
pushMetadata({
273+
kind: 'N',
274+
value: value instanceof Observable ? materializeInnerObservable<T>(value, state.scheduler.frame) : value,
275+
}),
276+
error: (error: any) => pushMetadata({ kind: 'E', error }),
277+
complete: () => pushMetadata({ kind: 'C' }),
278+
});
270279
}, subscribedFrame);
271280

272281
if (unsubscribedFrame !== Number.POSITIVE_INFINITY) {
@@ -294,7 +303,7 @@ const initializeSandboxState = (autoFlush: boolean, frameTimeFactor: number, max
294303
maxFrame,
295304
frameTimeFactor,
296305
scheduler: new VirtualTimeScheduler(VirtualAction, Number.POSITIVE_INFINITY),
297-
autoFlush
306+
autoFlush,
298307
};
299308
};
300309

@@ -337,8 +346,8 @@ interface SchedulerInstance extends BaseSchedulerInstance {
337346

338347
interface AsyncSchedulerInstance extends BaseSchedulerInstance {
339348
/**
340-
* Flush out currently scheduled observables, only until reaches frame specfied.
341-
*/
349+
* Flush out currently scheduled observables, only until reaches frame specfied.
350+
*/
342351
advanceTo: ReturnTypeWithArgs<typeof getSchedulerFlushFunctions, [SandboxState, true]>['advanceTo'];
343352
/**
344353
* Flush out currently scheduled observables, fill values returned by `getMarbles`.
@@ -355,9 +364,24 @@ interface AsyncSchedulerInstance extends BaseSchedulerInstance {
355364
/**
356365
* Creates a new instance of virtualScheduler, along with utility functions for sandbox assertions.
357366
*/
358-
function createTestScheduler(autoFlush: boolean, frameTimeFactor: number, maxFrameValue: number, flushWithAsyncTick: true): AsyncSchedulerInstance;
359-
function createTestScheduler(autoFlush: boolean, frameTimeFactor: number, maxFrameValue: number, flushWithAsyncTick: false): SchedulerInstance;
360-
function createTestScheduler(autoFlush: boolean, frameTimeFactor: number, maxFrameValue: number, flushWithAsyncTick: boolean): any {
367+
function createTestScheduler(
368+
autoFlush: boolean,
369+
frameTimeFactor: number,
370+
maxFrameValue: number,
371+
flushWithAsyncTick: true
372+
): AsyncSchedulerInstance;
373+
function createTestScheduler(
374+
autoFlush: boolean,
375+
frameTimeFactor: number,
376+
maxFrameValue: number,
377+
flushWithAsyncTick: false
378+
): SchedulerInstance;
379+
function createTestScheduler(
380+
autoFlush: boolean,
381+
frameTimeFactor: number,
382+
maxFrameValue: number,
383+
flushWithAsyncTick: boolean
384+
): any {
361385
const sandboxState = initializeSandboxState(autoFlush, frameTimeFactor, maxFrameValue);
362386

363387
const { flushUntil, advanceTo } = getSchedulerFlushFunctions(sandboxState, flushWithAsyncTick as any);

src/utils/ambient.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)