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

JavaScript Testing Framework: Under the Hood(JS...

JavaScript Testing Framework: Under the Hood(JSConfJP2022)

Yoshiaki Togami/戸上義章

November 27, 2022
Tweet

More Decks by Yoshiaki Togami/戸上義章

Other Decks in Programming

Transcript

  1. $whoami Yoshiaki Togami - B4 student major in electronic engineering

    - JSer at noon, Rustacean at night Github: @togami2864
  2. In this Lightning Talk… ❌: How to set up a

    testing framework 🤔 ❌: How to use ESM with tests 🤔 ❌: How to run test with TypeScript 🤔
  3. Build our tiny test framework Goal: Our framework can test

    codes including basic test functions - expect - it - describe
  4. Our test framework v1 1. Get all files including .test.js

    2. Read files as string 3. Eval a. If error occurs => FAIL b. success => PASS
  5. 2. With describe(), it() 📚describe() and it() is the function

    just for categorizing. 📚Not for judging the test code
  6. Implementation(abstract) - lib - it, describe - Imported to the

    test file - Runtime 1. Get file path of tests 2. Evaluate the test file => execute describe() 3. Run collect() => execute it() inside describe() 4. Iterate over suites and evaluate test cases(same as v1) 5. Output results
  7. Conclusion ✅ What’s happening under the hood 🤔 1. Get

    .test.js file path 2. Exec describe() via evaluating files 3. Run collect() to run it() 4. Iterate collected suites and eval tests 5. Output results
  8. More features… - Hook,Mocking,Chain - Parallelization - Dependency Resolving -

    Dependency caching - Where’s bottleneck in the execution speed? - How is the implementation of the test runner built in node, deno, bun? - Will alternatives written in other languages appear?(like babel, eslint, prettier..) Advanced Topic
  9. References - Building a JavaScript Testing Framework(by cpojer) - This

    is highly recommended to read before code reading - https://cpojer.net/posts/building-a-javascript-testing-framework - ava - https://github.com/avajs/ava - Jest - https://github.com/facebook/jest - Vitest - https://github.com/vitest-dev/vitest - deno-std/testing/bdd.ts - https://github.com/denoland/deno_std/testing/bdd.ts