Skip to content

Commit

Permalink
Merge pull request #428 from kwonoj/bump-rx
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj authored Jun 2, 2020
2 parents 4626d7a + a5b4f1b commit 4644d0e
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 70 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
<a name="2.0.0-beta.1"></a>
# [2.0.0-beta.1](https://github.com/kwonoj/rx-sandbox/compare/v1.0.3...v2.0.0-beta.1) (2020-06-02)


### build

* **tsconfig:** update tsconfig ([748ea40](https://github.com/kwonoj/rx-sandbox/commit/748ea40))


### Features

* **sandbox:** support 7.x ([d8220f8](https://github.com/kwonoj/rx-sandbox/commit/d8220f8))


### BREAKING CHANGES

* **tsconfig:** require es2015 supported runtime
* **sandb8x:** require rx >= 7.x



<a name="1.0.3"></a>
## [1.0.3](https://github.com/kwonoj/rx-sandbox/compare/v1.0.2...v1.0.3) (2019-06-23)

Expand Down
5 changes: 5 additions & 0 deletions jest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"testMatch": [
"**/spec/**/*-spec.ts"
],
"globals": {
"ts-jest": {
"diagnostics": false
}
},
"bail": true,
"resetMocks": true,
"clearMocks": true,
Expand Down
26 changes: 22 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rx-sandbox",
"version": "1.0.3",
"version": "2.0.0-beta.1",
"description": "Marble diagram DSL based test suite for RxJS 6",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -61,15 +61,15 @@
"lint-staged": "^9.5.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.0.5",
"rxjs": "^6.5.5",
"rxjs": "^7.0.0-beta.0",
"shx": "^0.3.2",
"ts-jest": "^26.1.0",
"tslint": "^6.1.2",
"tslint-no-unused-expression-chai": "^0.1.4",
"typescript": "^3.9.3"
},
"peerDependencies": {
"rxjs": "6.x"
"rxjs": "7.x"
},
"dependencies": {
"jest-matcher-utils": "^26.0.1",
Expand Down
15 changes: 11 additions & 4 deletions spec/marbles/parseObservableMarble-spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { expect } from 'chai';
import { ColdObservable } from 'rxjs/internal/testing/ColdObservable';
import { parseObservableMarble } from '../../src/marbles/parseObservableMarble';
import { complete, error, next } from '../../src/message/TestMessage';
import { TestScheduler } from '../../src/scheduler/TestScheduler';

//tslint:disable no-var-requires no-require-imports
const {
ColdObservable,
}: {
ColdObservable: typeof import('rxjs/dist/types/internal/testing/ColdObservable').ColdObservable;
} = require('rxjs/dist/cjs/internal/testing/ColdObservable');
//tslint:enable no-var-requires no-require-imports

describe('parseObservableMarble', () => {
it('should not allow unsubscription token', () => {
const marble = '----!';
Expand Down Expand Up @@ -52,7 +59,7 @@ describe('parseObservableMarble', () => {

const customValue = {
a: new ColdObservable(aMessages, null as any),
b: new ColdObservable(bMessages, null as any)
b: new ColdObservable(bMessages, null as any),
};

const messages = parseObservableMarble(marble, customValue, null, true);
Expand All @@ -68,7 +75,7 @@ describe('parseObservableMarble', () => {

const customValue = {
a: new ColdObservable<string>(aMessages, null as any),
b: new ColdObservable<string>(bMessages, null as any)
b: new ColdObservable<string>(bMessages, null as any),
};

const messages = parseObservableMarble(marble, customValue, null, false);
Expand Down Expand Up @@ -107,7 +114,7 @@ describe('parseObservableMarble', () => {
it('should parse value literal with custom value', () => {
const marble = '----a----';
const customValue = {
a: 'qwerty'
a: 'qwerty',
};

const messages = parseObservableMarble(marble, customValue);
Expand Down
21 changes: 18 additions & 3 deletions spec/scheduler/TestScheduler-spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { expect } from 'chai';
import { AsyncAction } from 'rxjs/internal/scheduler/AsyncAction';
import { ColdObservable } from 'rxjs/internal/testing/ColdObservable';
import { HotObservable } from 'rxjs/internal/testing/HotObservable';
import { mapTo, windowCount } from 'rxjs/operators';
import { parseObservableMarble } from '../../src/marbles/parseObservableMarble';
import { complete, error, next, subscribe, TestMessage } from '../../src/message/TestMessage';
import { TestScheduler } from '../../src/scheduler/TestScheduler';

//tslint:disable no-var-requires no-require-imports
const {
AsyncAction,
}: {
AsyncAction: typeof import('rxjs/dist/types/internal/scheduler/AsyncAction').AsyncAction;
} = require('rxjs/dist/cjs/internal/scheduler/AsyncAction');
const {
ColdObservable,
}: {
ColdObservable: typeof import('rxjs/dist/types/internal/testing/ColdObservable').ColdObservable;
} = require('rxjs/dist/cjs/internal/testing/ColdObservable');
const {
HotObservable,
}: {
HotObservable: typeof import('rxjs/dist/types/internal/testing/HotObservable').HotObservable;
} = require('rxjs/dist/cjs/internal/testing/HotObservable');
//tslint:enable no-var-requires no-require-imports

describe('TestScheduler', () => {
describe('hotObservable', () => {
it('should create hot observable via TestMessage', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/RxSandbox.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SubscriptionLog } from 'rxjs/internal/testing/SubscriptionLog';
import { SubscriptionLog } from 'rxjs/dist/types/internal/testing/SubscriptionLog';
import { TestMessage } from './message/TestMessage';
import { RxSandboxInstance } from './RxSandboxInstance';

Expand Down
4 changes: 2 additions & 2 deletions src/RxSandboxInstance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SubscriptionLog } from 'rxjs/internal/testing/SubscriptionLog';
import { SubscriptionLog } from 'rxjs/dist/types/internal/testing/SubscriptionLog';
import { TestMessage } from './message/TestMessage';
import { TestScheduler } from './scheduler/TestScheduler';

Expand Down Expand Up @@ -59,5 +59,5 @@ export {
getObservableMessage,
expectedObservable,
expectedSubscription,
RxSandboxInstance
RxSandboxInstance,
};
4 changes: 2 additions & 2 deletions src/assert/constructSubscriptionMarble.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SubscriptionLog } from 'rxjs/internal/testing/SubscriptionLog';
import { SubscriptionLog } from 'rxjs/dist/types/internal/testing/SubscriptionLog';
import { ObservableMarbleToken } from '../marbles/ObservableMarbleToken';
import { SubscriptionMarbleToken } from '../marbles/SubscriptionMarbleToken';

Expand All @@ -9,7 +9,7 @@ const MAX_FRAME_LENGTH = 30;
*/
const constructSubscriptionMarble = ({
subscribedFrame,
unsubscribedFrame
unsubscribedFrame,
}: SubscriptionLog): { marbleString: string; frameString: string } => {
const marble: Array<ObservableMarbleToken | SubscriptionMarbleToken> = Array.from(Array(MAX_FRAME_LENGTH + 1)).map(
() => ObservableMarbleToken.TIMEFRAME
Expand Down
24 changes: 15 additions & 9 deletions src/assert/marbleAssert.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { toEqual } from 'jest-matchers/build/matchers';
import { SubscriptionLog } from 'rxjs/internal/testing/SubscriptionLog';
import { TestMessage } from '../message/TestMessage';
import { constructObservableMarble } from './constructObservableMarble';
import { constructSubscriptionMarble } from './constructSubscriptionMarble';
const { matcherHint, printExpected, printReceived } = require('jest-matcher-utils'); //tslint:disable-line:no-require-imports no-var-requires

//tslint:disable:no-require-imports no-var-requires
const { matcherHint, printExpected, printReceived } = require('jest-matcher-utils');
const { SubscriptionLog } = require('rxjs/dist/cjs/internal/testing/SubscriptionLog');
//tslint:enbale:no-require-imports no-var-requires

const toEqualAssert = toEqual.bind({ expand: false });

const subscriptionMarbleAssert = (source: Array<SubscriptionLog>) => (expected: Array<SubscriptionLog>) => {
const subscriptionMarbleAssert = (
source: Array<import('rxjs/dist/types/internal/testing/SubscriptionLog').SubscriptionLog>
) => (expected: Array<import('rxjs/dist/types/internal/testing/SubscriptionLog').SubscriptionLog>) => {
const asserted = toEqualAssert(source, expected);

if (!asserted.pass) {
Expand Down Expand Up @@ -52,6 +57,7 @@ const observableMarbleAssert = <T = string>(source: Array<TestMessage<T>> | Read

//polymorphic picks up observablemarbleassert first when empty array, manually falls back
//if expected is subscriptionlog
//tslint:disable-next-line no-var-requires no-require-imports
if ((expected as any).every((x: any) => x instanceof SubscriptionLog)) {
subscriptionMarbleAssert(source as any)(expected as any);
return;
Expand Down Expand Up @@ -83,11 +89,11 @@ function marbleAssert<T = string>(
};
};
function marbleAssert<T = void>(
source: Array<SubscriptionLog>
): { to: { equal(expected: Array<SubscriptionLog>): void } };
source: Array<import('rxjs/dist/types/internal/testing/SubscriptionLog').SubscriptionLog>
): { to: { equal(expected: Array<import('rxjs/dist/types/internal/testing/SubscriptionLog').SubscriptionLog>): void } };
function marbleAssert<T = string>(
source:
| Array<SubscriptionLog>
| Array<import('rxjs/dist/types/internal/testing/SubscriptionLog').SubscriptionLog>
| Array<TestMessage<T | Array<TestMessage<T>>>>
| Readonly<Array<TestMessage<T | Array<TestMessage<T>>>>>
): { to: { equal(expected: object): void } } {
Expand All @@ -96,12 +102,12 @@ function marbleAssert<T = string>(
throw new Error('Cannot assert non array');
}

const isSourceSubscription = source.length > 0 && (source as Array<any>).every(v => v instanceof SubscriptionLog);
const isSourceSubscription = source.length > 0 && (source as Array<any>).every((v) => v instanceof SubscriptionLog);

return {
to: {
equal: isSourceSubscription ? subscriptionMarbleAssert(source as any) : observableMarbleAssert(source as any)
}
equal: isSourceSubscription ? subscriptionMarbleAssert(source as any) : observableMarbleAssert(source as any),
},
};
}

Expand Down
14 changes: 3 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { Observable } from 'rxjs';
import { ColdObservable } from 'rxjs/internal/testing/ColdObservable';
import { HotObservable } from 'rxjs/internal/testing/HotObservable';
import { marbleAssert } from './assert/marbleAssert';
import { parseObservableMarble } from './marbles/parseObservableMarble';
import { parseSubscriptionMarble } from './marbles/parseSubscriptionMarble';
Expand All @@ -16,14 +13,9 @@ export {
getObservableMessage,
expectedObservable,
expectedSubscription,
RxSandboxInstance
RxSandboxInstance,
} from './RxSandboxInstance';

//workaround TS4029 by explicitly import types and avoid unused import error
(() => Observable.toString())();
(() => ColdObservable.toString())();
(() => HotObservable.toString())();

type marbleAssertion = typeof marbleAssert;

const rxSandbox: RxSandbox = {
Expand All @@ -39,10 +31,10 @@ const rxSandbox: RxSandbox = {
getMessages: scheduler.getMessages.bind(scheduler) as typeof scheduler.getMessages,
e: <T = string>(marble: string, value?: { [key: string]: T } | null, error?: any) =>
parseObservableMarble(marble, value, error, true, frameTimeFactor, frameTimeFactor * maxFrameValue),
s: (marble: string) => parseSubscriptionMarble(marble, frameTimeFactor, frameTimeFactor * maxFrameValue)
s: (marble: string) => parseSubscriptionMarble(marble, frameTimeFactor, frameTimeFactor * maxFrameValue),
};
},
marbleAssert: marbleAssert
marbleAssert: marbleAssert,
};

export { rxSandbox, TestMessage, marbleAssertion, next, error, complete, subscribe };
13 changes: 10 additions & 3 deletions src/marbles/parseSubscriptionMarble.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import { SubscriptionLog } from 'rxjs/internal/testing/SubscriptionLog';
import { ObservableMarbleToken } from './ObservableMarbleToken';
import { subscriptionTokenParseReducer } from './tokenParseReducer';

//tslint:disable no-var-requires no-require-imports
const {
SubscriptionLog,
}: {
SubscriptionLog: typeof import('rxjs/dist/types/internal/testing/SubscriptionLog').SubscriptionLog;
} = require('rxjs/dist/cjs/internal/testing/SubscriptionLog');
//tslint:enable no-var-requires no-require-imports

const parseSubscriptionMarble = (marble: string | null, frameTimeFactor: number = 1, maxFrame = 1000) => {
if (!marble) {
return new SubscriptionLog(Number.POSITIVE_INFINITY);
}

const marbleTokenArray = Array.from(marble).filter(token => token !== ObservableMarbleToken.NOOP);
const marbleTokenArray = Array.from(marble).filter((token) => token !== ObservableMarbleToken.NOOP);
const value = marbleTokenArray.reduce(subscriptionTokenParseReducer(frameTimeFactor, maxFrame), {
currentTimeFrame: 0,
subscriptionFrame: Number.POSITIVE_INFINITY,
unsubscriptionFrame: Number.POSITIVE_INFINITY,
simultaneousGrouped: false,
expandingTokenCount: 0,
expandingValue: []
expandingValue: [],
});

return value.unsubscriptionFrame === Number.POSITIVE_INFINITY
Expand Down
11 changes: 9 additions & 2 deletions src/marbles/tokenParseReducer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { ColdObservable } from 'rxjs/internal/testing/ColdObservable';
import { complete, error as e, next, TestMessage } from '../message/TestMessage';
import { ObservableMarbleToken } from './ObservableMarbleToken';
import { SubscriptionMarbleToken } from './SubscriptionMarbleToken';

//tslint:disable no-var-requires no-require-imports
const {
ColdObservable,
}: {
ColdObservable: typeof import('rxjs/dist/types/internal/testing/ColdObservable').ColdObservable;
} = require('rxjs/dist/cjs/internal/testing/ColdObservable');
//tslint:enable no-var-requires no-require-imports

/**
* @internal
* Base accumulator interface for parsing marble diagram.
Expand Down Expand Up @@ -219,5 +226,5 @@ export {
ObservableTokenParseAccumulator,
SubscriptionTokenParseAccumulator,
subscriptionTokenParseReducer,
observableTokenParseReducer
observableTokenParseReducer,
};
9 changes: 8 additions & 1 deletion src/message/TestMessage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Notification } from 'rxjs';
import { SubscriptionLog } from 'rxjs/internal/testing/SubscriptionLog';

//tslint:disable no-var-requires no-require-imports
const {
SubscriptionLog,
}: {
SubscriptionLog: typeof import('rxjs/dist/types/internal/testing/SubscriptionLog').SubscriptionLog;
} = require('rxjs/dist/cjs/internal/testing/SubscriptionLog');
//tslint:enable no-var-requires no-require-imports

/**
* Represents interface for single metadata value emitted by HotObservable<T> or ColdObservable<T>
Expand Down
Loading

0 comments on commit 4644d0e

Please sign in to comment.