Using Playwright Test to run Unit Tests

This page summarizes the projects mentioned and recommended in the original post on /r/javascript

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • Playwright

    Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

    For your question, it does actually not spin up a browser if you do not use page or browser in your test cases! And I wrote the blog post exactly because I think many people don't even consider to use it for unit tests, but I think it can be a viable test runner for that kind of scenarios! And just to be clear, before I released the blog post I asked the folks behind Playwright what they say about using Playwright for unit tests, and they are very supportive of that idea:

  • vitest

    Next generation testing framework powered by Vite.

    The "pros" stated in the blog post compare Playwright Test with Jest/Mocha. vitest is a very interesting, modern test framework and shares some of the pros, like TS OOTB support (as you mentioned) and it also has no globals. Still, some of the pros like "Same tool for E2E tests and unit tests" still hold only for Playwright.

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

  • jest

    Delightful JavaScript Testing.

    And honestly, I had a couple of troubles with it. Like: TS is not supported out-of-the-box, so you have to configure ts-jest or something do get it even running; then, path aliases still don't work, so you have to apply some additional setup (like pathsToModuleNameMapper from ts-jest). Then I added Cypress for E2E tests and suddenly, nothing would compile because both Jest and Cypress define global typings, which conflict with each other... And at the end of the day, Jest had memory leaks such that the CI/CD system would sometimes error because of OOM issues (see e.g. with 69 comments at the time of writing).

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts