Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

most-test

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

most-test - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

6

lib/run/index.js

@@ -41,2 +41,3 @@ 'use strict';

this._timer = new _virtualTimer2.default();
this._scheduler = new _Scheduler2.default(this._timer, new _Timeline2.default());
this._t = 0;

@@ -137,5 +138,4 @@ this._cacheMap = new WeakMap();

var observer = new _observer2.default(sink.event.bind(sink), sink.end.bind(sink), sink.error.bind(sink), disposable);
var scheduler = new _Scheduler2.default(this._timer, new _Timeline2.default());
disposable.setDisposable(source.run(observer, scheduler));
return { sink: sink, disposable: disposable, observer: observer, scheduler: scheduler, buckets: [] };
disposable.setDisposable(source.run(observer, this._scheduler));
return { sink: sink, disposable: disposable, observer: observer, buckets: [] };
}

@@ -142,0 +142,0 @@ }, {

{
"name": "most-test",
"version": "1.2.0",
"version": "1.3.0",
"description": "Unit testing tools for Most.js",

@@ -5,0 +5,0 @@ "typings": "type-definitions/most-test.d.ts",

@@ -10,2 +10,4 @@ # Unit Testing Tools for Most.js

_Special thanks to [@RamIdeas](https://github.com/RamIdeas) for testing and contributing fixes and enhancements to the library._
## Installation

@@ -28,5 +30,5 @@

run: (stream:Stream) => TestEnvironment
run: (stream:Stream) => BasicTestEnvironment
type TestEnvironment: {
type BasicTestEnvironment: {
tick: (min?:Interval) => Promise<Result>

@@ -48,3 +50,3 @@ now: Time,

A `TestEnvironment` object also contains a `results` property (getter only), which is an array of all of the `Result` objects created as a result of each `tick()` call.
A `BasicTestEnvironment` object also contains a `results` property (getter only), which is an array of all of the `Result` objects created as a result of each `tick()` call.

@@ -92,1 +94,47 @@ ### Example

```
### As of version 1.2.0:
As of version 1.2.0, `run(stream)` returns a `BasicTestEnvironment` which is a wrapper around `TestEnvironment`.
`run(stream)` works best when instantiating the stream under test within the test itself.
If you are testing a stream instantiated externally of your tests (eg. an imported module), the environment created when running this stream can remain associated with it and, therefore, future tests on the same stream can have unpredictable results.
In this situation, you should create a `TestEnvironment` and share it amongst your tests. Remembering to `.reset()` the environment after each test.
```js
import { TestEnvironment } from 'most-test'
import { stream1, stream2 } from './streams'
const env = new TestEnvironment();
// returns a promise - either return it to `afterEach` or `await` it
afterEach( () => env.reset() );
it( 'test stream1 after 1ms', async () => {
const { events } = await env.tick().collect( stream1 );
assert.equal( events.length, ... );
});
it( 'test stream1 after 10ms', async () => {
const { events } = await env.tick(10).collect( stream1 );
assert.equal( events.length, ... );
});
```
`tick()` initiates a promise chain but returns the `TestEnvironment` instance. Subsequent calls to `collect()` wait for this promise and then return a `Result`.
`collect(stream)` implicitly calls `track(stream)` - this helps avoid repetition. If `collect()` isn't being called within the same frame as `tick()`, you'll need to call `track()` explicitly, upfront.
```js
it( 'test stream1 then test stream2', async () => {
env.track( stream1, stream2 ); // could also chain calls: env.track( stream1 ).track( stream2 );
const results1 = await env.tick().collect( stream1 );
assert.equal( results1.events.length, ... );
const results2 = await env.tick().collect( stream2 );
assert.equal( results2.events.length, ... );
});
```

@@ -11,2 +11,3 @@ import Observer from './observer';

this._timer = new VirtualTimer();
this._scheduler = new Scheduler( this._timer, new Timeline() );
this._t = 0;

@@ -60,5 +61,5 @@ this._cacheMap = new WeakMap();

if( !cache ) {
cache = this._buildCache( stream );
this._cacheMap.set( stream, cache );
this._disposables.push( cache.disposable );
cache = this._buildCache( stream );
this._cacheMap.set( stream, cache );
this._disposables.push( cache.disposable );
}

@@ -76,5 +77,4 @@ return cache;

disposable );
const scheduler = new Scheduler( this._timer, new Timeline() );
disposable.setDisposable( source.run(observer, scheduler) );
return { sink, disposable, observer, scheduler, buckets: [] };
disposable.setDisposable( source.run(observer, this._scheduler) );
return { sink, disposable, observer, buckets: [] };
}

@@ -81,0 +81,0 @@ }

@@ -19,3 +19,3 @@

results<T>( stream: Stream<T> ): Result<T>[];
reset(): void;
reset(): Promise<void>;
}

@@ -22,0 +22,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc