What is Bun? A look at Its Capabilities for Automation Testing
Nowadays, if you use Twitter or follow tech news, you can see a new tool called “Bun” everywhere. Besides its funny name and the icon; it is one of the most exciting developments in the Javascript ecosystem. It also caught my attention and I decided to give it a try. In this newsletter, let’s explore what Bun is and what it offers to the software testing ecosystem.
Bun is a new JavaScript runtime designed to serve the modern JavaScript ecosystem, focused on speed, elegant APIs, and a cohesive developer experience. It is built to be a fast and efficient alternative to Node.js, offering a complete toolkit for building JavaScript apps, including a package manager, test runner, and bundler.
So, Bun is offering lots of tools, and it can serve as a replacement for Node.js. When we run JS-based automated tests, we could use Node.js runner or Jest, thus Bun can provide an alternative tool for running our tests.
Based on my observation, the Bun test runner is currently useful for running unit tests. So if you are planning to migrate your project to Bun (1.X.X stable version), your unit tests should run without a problem. Also, Bun provides limited features for Windows native functionality. So, if you are using a Windows machine, I would discourage you from using Bun at the moment.
To test it out, I set up a local project to get a feel for it. Let’s go through the steps together to run a very basic unit test via Bun.
1- First, create a simple project:
mkdir my-bun-project
cd my-bun-project
2- Add Bun to your globals:
npm install -g bun
3- Add a test file
You can simply create a folder named “tests” and add your test file under it. Ensure your test file includes either ".test", "test", ".spec", or "spec" in the filename.
4- To run the test, you can use the command
“bun test"
In this example, I wrote a very basic unit test, testing if 2+2 equals 4. After executing the bun test command, you can see the test result. The test ran in 0.02ms and it passed.
It is quite straightforward to run unit tests via Bun. At this moment, I can’t make a comparison between Bun and other test runners, but I can already see lots of comments that it’s a good improvement compared to existing runners. I encourage you to give it a try and see how it works for you.
I also tried to make it work for UI tests, specifically for Playwright. It was quite challenging to set up, and I found some open issues for Bun’s Playwright compatibility. At this moment, I wouldn’t recommend migrating a project to Bun if you use Playwright as part of your automation process. Here, you can find the open issues about it:
https://github.com/oven-sh/bun/issues/2492
https://github.com/microsoft/playwright/issues/27139
For us as software testers, it's important to keep up with new tools and trends and give them a try. It doesn’t mean that we should immediately change our tooling, but we should be aware of the new options in the market and do a small pet project to play with them. I believe that Bun has a good chance to grow in the near future and more and more projects will be built using it. Currently, it’s still not fully Node.js compatible, which is why it’s hard to run your existing tests on it, since Playwright heavily depends on Node.js. However, I believe that in the near future, these problems will be solved.
What are your thoughts? Do you also explore new tools for fun and to see how they function? Comment on this issue, and I'll look into your suggestions.
Happy testing ✌️