jasmine-marbles
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -244,2 +244,3 @@ (function (global, factory) { | ||
if (passed) { | ||
expect(passed).toBe(true); | ||
return; | ||
@@ -305,2 +306,85 @@ } | ||
function unparseMarble(result, assignSymbolFn) { | ||
const FRAME_TIME_FACTOR = 10; // need to be up to date with `TestScheduler.frameTimeFactor` | ||
let frames = 0; | ||
let marble = ''; | ||
let isInGroup = false; | ||
let groupMembersAmount = 0; | ||
let index = 0; | ||
const isNextMessageInTheSameFrame = () => { | ||
const nextMessage = result[index + 1]; | ||
return nextMessage && nextMessage.frame === result[index].frame; | ||
}; | ||
result.forEach((testMessage, i) => { | ||
index = i; | ||
const framesDiff = testMessage.frame - frames; | ||
const emptyFramesAmount = framesDiff > 0 ? framesDiff / FRAME_TIME_FACTOR : 0; | ||
marble += '-'.repeat(emptyFramesAmount); | ||
if (isNextMessageInTheSameFrame()) { | ||
if (!isInGroup) { | ||
marble += '('; | ||
} | ||
isInGroup = true; | ||
} | ||
switch (testMessage.notification.kind) { | ||
case 'N': | ||
marble += assignSymbolFn(testMessage.notification); | ||
break; | ||
case 'E': | ||
marble += '#'; | ||
break; | ||
case 'C': | ||
marble += '|'; | ||
break; | ||
} | ||
if (isInGroup) { | ||
groupMembersAmount += 1; | ||
} | ||
if (!isNextMessageInTheSameFrame() && isInGroup) { | ||
marble += ')'; | ||
isInGroup = false; | ||
frames += (groupMembersAmount + 1) * FRAME_TIME_FACTOR; | ||
groupMembersAmount = 0; | ||
} | ||
else { | ||
frames = testMessage.frame + FRAME_TIME_FACTOR; | ||
} | ||
}); | ||
return marble; | ||
} | ||
function mapSymbolsToNotifications(marbles, messagesArg) { | ||
const messages = messagesArg.slice(); | ||
const result = {}; | ||
for (let i = 0; i < marbles.length; i++) { | ||
const symbol = marbles[i]; | ||
switch (symbol) { | ||
case ' ': | ||
case '-': | ||
case '^': | ||
case '(': | ||
case ')': | ||
break; | ||
case '#': | ||
case '|': { | ||
messages.shift(); | ||
break; | ||
} | ||
default: { | ||
if ((symbol.match(/^[0-9]$/) && i === 0) || marbles[i - 1] === ' ') { | ||
const buffer = marbles.slice(i); | ||
const match = buffer.match(/^([0-9]+(?:\.[0-9]+)?)(ms|s|m) /); | ||
if (match) { | ||
i += match[0].length - 1; | ||
} | ||
break; | ||
} | ||
const message = messages.shift(); | ||
result[symbol] = message.notification; | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
function hot(marbles, values, error) { | ||
@@ -351,3 +435,3 @@ return new TestHotObservable(marbles.trim(), values, error); | ||
}), | ||
toBeObservable: () => ({ | ||
toBeObservable: (utils, equalityTester) => ({ | ||
compare: function (actual, fixture) { | ||
@@ -382,4 +466,9 @@ const results = []; | ||
const expected = rxjs_testing.TestScheduler.parseMarbles(fixture.marbles, fixture.values, fixture.error, true, true); | ||
expect(results).toEqual(expected); | ||
return { pass: true }; | ||
if (utils.equals(results, expected)) { | ||
return { pass: true }; | ||
} | ||
const mapNotificationToSymbol = buildNotificationToSymbolMapper(fixture.marbles, expected, utils.equals); | ||
const receivedMarble = unparseMarble(results, mapNotificationToSymbol); | ||
const message = formatMessage(fixture.marbles, expected, receivedMarble, results); | ||
return { pass: false, message }; | ||
}, | ||
@@ -389,2 +478,23 @@ }), | ||
} | ||
function buildNotificationToSymbolMapper(expectedMarbles, expectedMessages, equalityFn) { | ||
const symbolsToNotificationsMap = mapSymbolsToNotifications(expectedMarbles, expectedMessages); | ||
return (notification) => { | ||
const mapped = Object.keys(symbolsToNotificationsMap).find(key => { | ||
return equalityFn(symbolsToNotificationsMap[key], notification); | ||
}); | ||
return mapped || '?'; | ||
}; | ||
} | ||
function formatMessage(expectedMarbles, expectedMessages, receivedMarbles, receivedMessages) { | ||
return ` | ||
Expected: ${expectedMarbles}, | ||
Received: ${receivedMarbles}, | ||
Expected: | ||
${JSON.stringify(expectedMessages)} | ||
Received: | ||
${JSON.stringify(receivedMessages)}, | ||
`; | ||
} | ||
function setupEnvironment() { | ||
@@ -391,0 +501,0 @@ jasmine.getEnv().beforeAll(() => addMatchers()); |
@@ -1,33 +0,21 @@ | ||
import { TestColdObservable, TestHotObservable } from './src/test-observables'; | ||
export { | ||
getTestScheduler, | ||
initTestScheduler, | ||
resetTestScheduler, | ||
} from './src/scheduler'; | ||
export declare function hot( | ||
marbles: string, | ||
values?: any, | ||
error?: any, | ||
): TestHotObservable; | ||
export declare function cold( | ||
marbles: string, | ||
values?: any, | ||
error?: any, | ||
): TestColdObservable; | ||
import { TestColdObservable, TestHotObservable, TestObservable } from './src/test-observables'; | ||
export { getTestScheduler, initTestScheduler, resetTestScheduler } from './src/scheduler'; | ||
export declare function hot(marbles: string, values?: any, error?: any): TestHotObservable; | ||
export declare function cold(marbles: string, values?: any, error?: any): TestColdObservable; | ||
export declare function time(marbles: string): number; | ||
declare global { | ||
namespace jasmine { | ||
interface Matchers<T> { | ||
toBeObservable: any; | ||
toHaveSubscriptions: any; | ||
declare global { | ||
namespace jasmine { | ||
interface Matchers<T> { | ||
toBeObservable(expected: TestObservable): boolean; | ||
toHaveSubscriptions(marbles: string | string[]): boolean; | ||
} | ||
} | ||
} | ||
namespace jest { | ||
interface Matchers<R> { | ||
toBeObservable: any; | ||
toHaveSubscriptions: any; | ||
namespace jest { | ||
interface Matchers<R> { | ||
toBeObservable(expected: TestObservable): R; | ||
toHaveSubscriptions(marbles: string | string[]): R; | ||
} | ||
} | ||
} | ||
} | ||
export declare function addMatchers(): void; | ||
export declare function setupEnvironment(): void; |
@@ -5,2 +5,4 @@ import { Notification, Observable } from 'rxjs'; | ||
import { TestColdObservable, TestHotObservable, } from './src/test-observables'; | ||
import { unparseMarble } from './src/marble-unparser'; | ||
import { mapSymbolsToNotifications } from './src/map-symbols-to-notifications'; | ||
export { getTestScheduler, initTestScheduler, resetTestScheduler, } from './src/scheduler'; | ||
@@ -52,3 +54,3 @@ export function hot(marbles, values, error) { | ||
}), | ||
toBeObservable: () => ({ | ||
toBeObservable: (utils, equalityTester) => ({ | ||
compare: function (actual, fixture) { | ||
@@ -83,4 +85,9 @@ const results = []; | ||
const expected = TestScheduler.parseMarbles(fixture.marbles, fixture.values, fixture.error, true, true); | ||
expect(results).toEqual(expected); | ||
return { pass: true }; | ||
if (utils.equals(results, expected)) { | ||
return { pass: true }; | ||
} | ||
const mapNotificationToSymbol = buildNotificationToSymbolMapper(fixture.marbles, expected, utils.equals); | ||
const receivedMarble = unparseMarble(results, mapNotificationToSymbol); | ||
const message = formatMessage(fixture.marbles, expected, receivedMarble, results); | ||
return { pass: false, message }; | ||
}, | ||
@@ -90,2 +97,23 @@ }), | ||
} | ||
function buildNotificationToSymbolMapper(expectedMarbles, expectedMessages, equalityFn) { | ||
const symbolsToNotificationsMap = mapSymbolsToNotifications(expectedMarbles, expectedMessages); | ||
return (notification) => { | ||
const mapped = Object.keys(symbolsToNotificationsMap).find(key => { | ||
return equalityFn(symbolsToNotificationsMap[key], notification); | ||
}); | ||
return mapped || '?'; | ||
}; | ||
} | ||
function formatMessage(expectedMarbles, expectedMessages, receivedMarbles, receivedMessages) { | ||
return ` | ||
Expected: ${expectedMarbles}, | ||
Received: ${receivedMarbles}, | ||
Expected: | ||
${JSON.stringify(expectedMessages)} | ||
Received: | ||
${JSON.stringify(receivedMessages)}, | ||
`; | ||
} | ||
export function setupEnvironment() { | ||
@@ -92,0 +120,0 @@ jasmine.getEnv().beforeAll(() => addMatchers()); |
@@ -239,2 +239,3 @@ /** | ||
if (passed) { | ||
expect(passed).toBe(true); | ||
return; | ||
@@ -241,0 +242,0 @@ } |
import { Observable } from 'rxjs'; | ||
import { SubscriptionLog } from 'rxjs/internal/testing/SubscriptionLog'; | ||
export declare class TestColdObservable extends Observable<any> { | ||
marbles: string; | ||
values: any[] | undefined; | ||
error: any; | ||
constructor(marbles: string, values?: any[] | undefined, error?: any); | ||
getSubscriptions(): SubscriptionLog[]; | ||
marbles: string; | ||
values: any[] | undefined; | ||
error: any; | ||
constructor(marbles: string, values?: any[] | undefined, error?: any); | ||
getSubscriptions(): SubscriptionLog[]; | ||
} | ||
export declare class TestHotObservable extends Observable<any> { | ||
marbles: string; | ||
values: any[] | undefined; | ||
error: any; | ||
constructor(marbles: string, values?: any[] | undefined, error?: any); | ||
getSubscriptions(): SubscriptionLog[]; | ||
marbles: string; | ||
values: any[] | undefined; | ||
error: any; | ||
constructor(marbles: string, values?: any[] | undefined, error?: any); | ||
getSubscriptions(): SubscriptionLog[]; | ||
} | ||
export declare type TestObservable = TestColdObservable | TestHotObservable; |
@@ -1,33 +0,21 @@ | ||
import { TestColdObservable, TestHotObservable } from './src/test-observables'; | ||
export { | ||
getTestScheduler, | ||
initTestScheduler, | ||
resetTestScheduler, | ||
} from './src/scheduler'; | ||
export declare function hot( | ||
marbles: string, | ||
values?: any, | ||
error?: any, | ||
): TestHotObservable; | ||
export declare function cold( | ||
marbles: string, | ||
values?: any, | ||
error?: any, | ||
): TestColdObservable; | ||
import { TestColdObservable, TestHotObservable, TestObservable } from './src/test-observables'; | ||
export { getTestScheduler, initTestScheduler, resetTestScheduler } from './src/scheduler'; | ||
export declare function hot(marbles: string, values?: any, error?: any): TestHotObservable; | ||
export declare function cold(marbles: string, values?: any, error?: any): TestColdObservable; | ||
export declare function time(marbles: string): number; | ||
declare global { | ||
namespace jasmine { | ||
interface Matchers<T> { | ||
toBeObservable: any; | ||
toHaveSubscriptions: any; | ||
declare global { | ||
namespace jasmine { | ||
interface Matchers<T> { | ||
toBeObservable(expected: TestObservable): boolean; | ||
toHaveSubscriptions(marbles: string | string[]): boolean; | ||
} | ||
} | ||
} | ||
namespace jest { | ||
interface Matchers<R> { | ||
toBeObservable: any; | ||
toHaveSubscriptions: any; | ||
namespace jest { | ||
interface Matchers<R> { | ||
toBeObservable(expected: TestObservable): R; | ||
toHaveSubscriptions(marbles: string | string[]): R; | ||
} | ||
} | ||
} | ||
} | ||
export declare function addMatchers(): void; | ||
export declare function setupEnvironment(): void; |
25
index.js
@@ -7,2 +7,4 @@ "use strict"; | ||
var test_observables_1 = require("./src/test-observables"); | ||
var marble_unparser_1 = require("./src/marble-unparser"); | ||
var map_symbols_to_notifications_1 = require("./src/map-symbols-to-notifications"); | ||
var scheduler_2 = require("./src/scheduler"); | ||
@@ -62,3 +64,3 @@ exports.getTestScheduler = scheduler_2.getTestScheduler; | ||
}); }, | ||
toBeObservable: function () { return ({ | ||
toBeObservable: function (utils, equalityTester) { return ({ | ||
compare: function (actual, fixture) { | ||
@@ -93,4 +95,9 @@ var results = []; | ||
var expected = testing_1.TestScheduler.parseMarbles(fixture.marbles, fixture.values, fixture.error, true, true); | ||
expect(results).toEqual(expected); | ||
return { pass: true }; | ||
if (utils.equals(results, expected)) { | ||
return { pass: true }; | ||
} | ||
var mapNotificationToSymbol = buildNotificationToSymbolMapper(fixture.marbles, expected, utils.equals); | ||
var receivedMarble = marble_unparser_1.unparseMarble(results, mapNotificationToSymbol); | ||
var message = formatMessage(fixture.marbles, expected, receivedMarble, results); | ||
return { pass: false, message: message }; | ||
}, | ||
@@ -101,2 +108,14 @@ }); }, | ||
exports.addMatchers = addMatchers; | ||
function buildNotificationToSymbolMapper(expectedMarbles, expectedMessages, equalityFn) { | ||
var symbolsToNotificationsMap = map_symbols_to_notifications_1.mapSymbolsToNotifications(expectedMarbles, expectedMessages); | ||
return function (notification) { | ||
var mapped = Object.keys(symbolsToNotificationsMap).find(function (key) { | ||
return equalityFn(symbolsToNotificationsMap[key], notification); | ||
}); | ||
return mapped || '?'; | ||
}; | ||
} | ||
function formatMessage(expectedMarbles, expectedMessages, receivedMarbles, receivedMessages) { | ||
return "\n Expected: " + expectedMarbles + ",\n Received: " + receivedMarbles + ",\n \n Expected:\n " + JSON.stringify(expectedMessages) + "\n \n Received:\n " + JSON.stringify(receivedMessages) + ",\n "; | ||
} | ||
function setupEnvironment() { | ||
@@ -103,0 +122,0 @@ jasmine.getEnv().beforeAll(function () { return addMatchers(); }); |
{ | ||
"name": "jasmine-marbles", | ||
"version": "0.6.0", | ||
"description": "Marble testing helpers for RxJS and Jasmine", | ||
"keywords": [ | ||
"jasmine", | ||
"rxjs", | ||
"ngrx", | ||
"testing" | ||
], | ||
"version": "0.7.0", | ||
"module": "index.js", | ||
"es2015": "es6/index.js", | ||
"main": "bundles/jasmine-marbles.umd.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/synapse-wireless-labs/jasmine-marbles.git" | ||
}, | ||
"homepage": "https://github.com/synapse-wireless-labs/jasmine-marbles#readme", | ||
"bugs": "https://github.com/synapse-wireless-labs/jasmine-marbles/issues", | ||
"license": "MIT", | ||
@@ -20,3 +33,4 @@ "scripts": { | ||
"precommit": "yarn run prettier", | ||
"prettier": "prettier --parser typescript --single-quote --trailing-comma all --write \"./**/*.ts\"" | ||
"prettier": "prettier --parser typescript --single-quote --trailing-comma all --write \"./**/*.ts\"", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0" | ||
}, | ||
@@ -39,2 +53,4 @@ "nyc": { | ||
"@types/node": "^8.0.14", | ||
"conventional-changelog": "^3.1.12", | ||
"conventional-changelog-cli": "^2.0.25", | ||
"cpy-cli": "^1.0.1", | ||
@@ -44,3 +60,3 @@ "husky": "^0.14.3", | ||
"jasmine-core": "^2.8.0", | ||
"nyc": "^10.1.2", | ||
"nyc": "^14", | ||
"prettier": "^1.5.2", | ||
@@ -57,4 +73,4 @@ "rimraf": "^2.6.1", | ||
"dependencies": { | ||
"lodash": "^4.5.0" | ||
"lodash": "^4.17.12" | ||
} | ||
} |
@@ -241,2 +241,3 @@ "use strict"; | ||
if (passed) { | ||
expect(passed).toBe(true); | ||
return; | ||
@@ -243,0 +244,0 @@ } |
import { Observable } from 'rxjs'; | ||
import { SubscriptionLog } from 'rxjs/internal/testing/SubscriptionLog'; | ||
export declare class TestColdObservable extends Observable<any> { | ||
marbles: string; | ||
values: any[] | undefined; | ||
error: any; | ||
constructor(marbles: string, values?: any[] | undefined, error?: any); | ||
getSubscriptions(): SubscriptionLog[]; | ||
marbles: string; | ||
values: any[] | undefined; | ||
error: any; | ||
constructor(marbles: string, values?: any[] | undefined, error?: any); | ||
getSubscriptions(): SubscriptionLog[]; | ||
} | ||
export declare class TestHotObservable extends Observable<any> { | ||
marbles: string; | ||
values: any[] | undefined; | ||
error: any; | ||
constructor(marbles: string, values?: any[] | undefined, error?: any); | ||
getSubscriptions(): SubscriptionLog[]; | ||
marbles: string; | ||
values: any[] | undefined; | ||
error: any; | ||
constructor(marbles: string, values?: any[] | undefined, error?: any); | ||
getSubscriptions(): SubscriptionLog[]; | ||
} | ||
export declare type TestObservable = TestColdObservable | TestHotObservable; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
146380
40
1560
1
0
16
Updatedlodash@^4.17.12