Comments (6)
I found all questions answered. Nothing to complain about.
from time.
I think it should be mentioned somewhere that completion times are not taken into account when comparing streams. An example: '-x-|' == '-x---|'
.
from time.
@rjkip I might change that. My original rationale was that sometimes you want to make assertions against diagrams where the last event and completion occur in the same frame (character in diagram).
Like:
it("creates a stream that emits every period ms", (done) => {
const Time = mockTimeSource();
const stream = Time.periodic(40);
const expected = Time.diagram(
`----0---1---2|`
);
Time.assertEqual(
stream.take(3),
expected
);
Time.run(done);
});
The expected diagram states that completion occurs the frame after the last event, whereas in reality it occurs immediately. So there is lenience in asserting and a kludge in diagram generation to support this case.
The real fix for this issue is so support syntax for multiple items in a single frame, which I plan on investigating soon.
Even then I think it would be ugly to have to do:
it("creates a stream that emits every period ms", (done) => {
const Time = mockTimeSource();
const stream = Time.periodic(40);
const expected = Time.diagram(
`----0---1---(2|)`
);
Time.assertEqual(
stream.take(3),
expected
);
Time.run(done);
});
I'm also considering another kludge where I would check the time difference between completion events for actual and expected and fail if it's more than one frame different.
from time.
@rjkip I have released v0.6 which will fail a test if the actual and expected streams end at different times.
As part of this I have also added syntax to express simultaneous events, as per the above example.
However, to improve the readability of the above test, I have allowed for testing infinite streams without completion:
it("creates a stream that emits every period ms", (done) => {
const Time = mockTimeSource();
const stream = Time.periodic(80);
const expected = Time.diagram(
`----0---1---2---`
);
Time.assertEqual(
stream,
expected
);
Time.run(done);
});
Even though periodic
is infinite, now Time.run()
will only run to the end of your longest diagram (if you've used a diagram). So we can now test infinite streams without using .take
, which is nice, and they will no longer run forever if you forget to use .take
.
from time.
@rjkip I have released v0.6 which will fail a test if the actual and expected streams end at different times.
That sounds good. Confirmed to work as well :)
It does make a test that tests for a value and a completion in the same frame a bit awkward, but I think that's acceptable. These things are hard. You can still change it in a future minor, though :)
Time.assertEqual(Time.periodic(20).take(1), Time.diagram(`-(0|)`));
[...] I have allowed for testing infinite streams without completion:
Great! I was wondering about options there :)
All in all, thanks for replying and creating and maintaining this library 👌
from time.
It does make a test that tests for a value and a completion in the same frame a bit awkward, but I think that's acceptable. These things are hard.
Agreed, but I figure for a testing tool it's important to prioritize accuracy and correctness. I would rather be explicit and slightly awkward than implicit and imprecise.
In any case, this will only really come up when you have a stream designed to emit in the last frame, like of
and last
. It's thankfully not the common case for Cycle.js apps.
from time.
Related Issues (20)
- Export marble diagram images from tests HOT 6
- Expectation of delayed value with start-with value fails HOT 3
- Port xstream#tween to @cycle/time HOT 4
- Support Jasmine's done.fail() HOT 3
- Document behaviour of "simultaneous" value syntax HOT 11
- Export TimeSource type
- Support snapshot style testing with html-looks-like HOT 9
- Support alternative testing frameworks such as Ava HOT 18
- Make Time.run() return a promise HOT 2
- Add throttleIdleCallback HOT 7
- Write a specification for the marble diagram DSL HOT 3
- Add support for loading extra operators HOT 13
- Allow events to run even when focus is lost HOT 9
- throttleAnimationFrame() HOT 5
- cjs bundle means lodash deps for mocking are pulled in on production apps HOT 4
- Delete code and add moved readme HOT 1
- Move issues and pull request to monorepo HOT 2
- Can you explain why the operators are useful... HOT 1
- Add support for most.js and rxjs HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from time.