Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Unit test in deno

Unit test in deno

In this presentation we will see how to use the cli to run unit tests in deno, write assertions and have an overview of the benchmark API.

paul souche

April 14, 2020
Tweet

More Decks by paul souche

Other Decks in Technology

Transcript

  1. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Unit

    tests in deno A std journey
  2. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Me

    myself and I @paul.souche paulsouche @paulsouche 2
  3. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Disclaimer

    Deno is in v0.40.0 at the time I made this presentation. Some presented patterns may evolve in further releases. Purpose is to present the opinionated choices deno made in its architecture. 3
  4. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 My

    first IT job interview 4 For the algorithm test we should begin with Fibonacci. Do you know it ? Yes, I studied it in highschool Ok great ! Could you begin with a unit test ? I never did a unit test of my life sorry ! but maybe can you help me ?
  5. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 You

    have the job but... 5
  6. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Me

    at the time 6 Fibonacci master First IT job Need to learn everything about tests
  7. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Resolution

    #1 Always learn a language / framework / library / … through tests 7
  8. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Seven

    years later 8 deno test Hey Lilian ! Deno looks so great but how do you test ? Try yourself and make a presentation ! Ok but what are the patterns ? What do you write ? Ok then...
  9. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Deno

    test command 9
  10. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Useful

    options 10 • -A --allow-all to manage permissions • --filter to filter spec files • --inspect-brk to debug • --log-level to debug
  11. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Limitations

    11 • No watch mode out of the box • Specs are executed sequentially (no parallelism) • Coverage is missing • Files must respect pattern (can be tricked with Deno.runTests())
  12. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 12

    First test
  13. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Assertions

    1 / 3 13
  14. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Assertions

    2 / 3 14
  15. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Assertions

    3 / 3 15 Powerful Error assertions
  16. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Now

    I can do job interviews myself 16 And have access to all job interviews reports
  17. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Doesn’t

    know Fibonacci at all !!! 17
  18. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 18

    Fibonacci 1 / 1 / 2 / 3 / 5 / 8 / 13 f(0) = 1 f(1) = 1 f(n) = f(n-1) + f(n-2)
  19. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 What

    I did at the time 1/3 : fibonacci 19
  20. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 What

    I did at the time 2/3 : fibonacci Rec 20
  21. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 What

    I did at the time 3/3 : famous unit test 21
  22. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 What

    I missed at the time : fibonacci memo 22
  23. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 23

    deno benchmarks
  24. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 24

    Demno time
  25. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 Conclusion

    25 • deno dev experience is great (thanks to axetroy extension for vs code) • testing std & cli are not production ready at all • I hope the bench API will be kept
  26. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 26

    Thank you Questions ?
  27. Paul SOUCHE Repository => https://github.com/paulsouche/unit-tests-in-deno Meetup Paris Deno 4/14/2020 27

    Ressources • repository (https://github.com/paulsouche/unit-tests-in-deno) • testing std (https://github.com/denoland/deno/tree/master/std/testing) • fibonacci & golden number (https://youtu.be/J6tcnc7LukM?t=971) (french) • fibonacci & JavaScript (https://medium.com/developers-writing/fibonacci-sequence-algorithm-in-javascript-b253dc7e320e) • demo meme (https://youtu.be/y_lYoENIffI) (check it out it's hilarious) Thanks to Paris Deno, axetroy, Aurélien & Mathieu