Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port van @politie/sherlock tutorial #55

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft

Port van @politie/sherlock tutorial #55

wants to merge 22 commits into from

Conversation

untio11
Copy link
Collaborator

@untio11 untio11 commented Nov 23, 2023

Deze port doet voornamelijk twee dingen:

  • Gemigreerd van chai naar Jest.
  • Wat kleine updates van instructies en structuur van de tutorial zelf.

Het meeste was vrij straight forward. De wat grotere/complexere aanpassingen markeer ik met comments in Github.

Verder heb ik nog een aparte branch met mijn oplossingen voor de tutorials. Ik denk dat het handig is als die ook ter reference in de repo staan, misschien als een getagde commit? Voor nu zet ik het in ieder geval ook in een PR zodat het gereviewed kan worden (#56).

untio11 and others added 22 commits November 7, 2023 19:51
Additionally fixed the broken imports of sherlock and sherlock-utils
Use npm run tutorial to run all the test cases in the tutorial directory.
Note that it's currently skipping the test cases.
They have been validated to run (and fail) before
committing though.
Again skipping by default.
There's still one part at line 121 where I'm not sure what's happening
As always, set to skip by default.
Some weird config/import spaghetti was going on. Now everything works
with the '@' import notation.

Co-authored-by: Paco van der Linden <pavadeli@users.noreply.github.com>
Currently skipped as always.

Also removed some unused pieces of code:
- Imports
- Outer test suite that didn't do anything useful
Still have to iron out some details probably
Probably have to tweak it a bit more though
This way it doesn't count as a failed test case when running
npm run tutorial.
Also updated a comment in tutorial 1 slightly.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was een lege file, maar Jest geeft dan errors dat er geen test suites/cases in staan. Vandaar deze placeholder.

* Now, use `pairwise()` directly in `.react()`. Implement the same
* derivation as before: subtract the previous value from the current.
*
* Instead of returning the computed value, assign it
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik heb het een hele tijd geprobeerd, maar ik kreeg het niet voor elkaar om spioneren op het resultaat van .pairwise(). Als ik .react() vervang met een mock krijg ik namelijk alleen maar te zien dat deze aangeroepen is met een wrapped functie.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hetzelfde geldt overigens voor .scan() in de volgende test case.

*
* This is best explained in practice.
*/
it('struct', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deze test heeft mij niet per se inzicht gegeven in waarom ik .struct() zou moeten gebruiken. Het voorbeeld laat namelijk alleen maar zien in welk opzicht .struct() op dezelfde manier reageert op een atom als op een normale member.

*/

await new Promise(r => setTimeout(r, 1));

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hier werd in de oorspronkelijke versie de mock gecleared na de delay. Deze variant zonder de clear lijkt me echter iets interessanter omdat je dan het resultaat van die delay ook kan waarnemen.

describe('`derivableCache`', () => {
type Stocks = 'GOOGL' | 'MSFT' | 'APPL';

let stockPrice$: jest.Mock<DerivableAtom<number>, [Stocks], any>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dit was eerst met een sinon stub functie geimplementeerd en dit was wel even puzzelen om goed om te schrijven. Volgens mij doet ie nu wat ie hoort te doen, kijkende naar de comments en de tests, maar even dubbel checken hier zou fijn zijn.


beforeEach(() => {
// By default the stock price retriever returns unresolved.
stockPrice$ = jest.fn(_ => atom.unresolved());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hier jest.fn().mockReturnValue(atom.unresolved()); gebruiken werkte niet zoals verwacht, omdat het steeds dezelfde unresolved atom returnde.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants