Logo Haradkou SDET
Bun: Is it fast for test automation?

Bun: Is it fast for test automation?

September 10, 2023
5 min read
Table of Contents

What is Bun?

From official site - Bun is a fast JavaScript all-in-one toolkit/bundler/runtime/package-manager/test runner.

Bun - it’s similar to node.js and Deno - both of them are JavaScript runtimes.

Deno also can supports typescript out-of box and compilation step does not required.

Environment information

I use MacBook Pro 14-inch, 2023.

NameDescription
ChipApple M2 Pro
Memory16 GB
OS14.0 Beta (23A5337a)
npm9.6.7
yarn1.22.19
pnpm8.7.0
node.jsv18.17.1
bun1

How to install Bun

From Official site:

curl -fsSL https://bun.sh/install | bash
installation command

Test

Disclaimer: I cannot test bun on the current project, since we use unimplemented bun node: API. When bun will fully compatable with node.js - I will retest on the real project.

The test is simple. We will run both headless and headful modes

Play > Video 1. Repesentation of headless mode.

Round 1. Headful mode

playwright Configuration will be looks like this:

playwright.config.ts
import { defineConfig, devices } from '@playwright/test'
 
export default defineConfig({
  // Look for test files in the "tests" directory, relative to this configuration file.
  testDir: 'tests',
  workers: 1,
  use: {
    // Base URL to use in actions like `await page.goto('/')`.
    baseURL: 'https://google.com',
    launchOptions: {
      // headful mode
      headless: false,
    },
  },
  // Configure projects for major browsers.
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
  ],
})
playwright config

And Test file will be looks like:

tests/some.test.ts
import { test, expect } from '@playwright/test'
 
test('should work', async ({ page }) => {
  // opens baseURL
  await page.goto('/')
})
simple playwright test

Let’s see some results:

Launch #Bunpnpmyarnnpm
12.62.872.772.75
22.52.722.712.66
32.452.772.682.64
42.513.052.772.67
Median
N/A2.52.822.7352.665
Difference
N/A012%9.4%6.6%

Table 1. Bun vs. pnpm vs yarn vs npm. Headful mode. Time in seconds

Very impressive. Bun is about 12% faster than pnpm in execution time. Npm is a second after bun! 🤯

Round 2. Headless mode

Same test file, but let’s update configuration in playwright.config.ts file

playwright.config.ts
import { defineConfig, devices } from '@playwright/test'
 
export default defineConfig({
  // Look for test files in the "tests" directory, relative to this configuration file.
  testDir: 'tests',
  workers: 1,
  use: {
    // Base URL to use in actions like `await page.goto('/')`.
    baseURL: 'https://google.com',
    launchOptions: {
      // headless mode
      headless: true,
    },
  },
  // Configure projects for major browsers.
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
  ],
})
updated playwright config
Launch #Bunpnpmyarnnpm
11.972.162.072.17
21.972.242.322.1
31.972.202.062.17
42.022.222.192.14
Median
N/A1.972.212.132.15
Difference
N/A012%8%9%

Table 2. Bun vs. pnpm vs yarn vs npm. Headless mode. Time in seconds

Difference between executions for pnpm and bun is about 12%! pnpm is a slowest!

Conclusion

I was impressive! Bun is 12% faster than pnpm; 9% faster than yarn and 8% faster than npm

NOTE 1: I cannot test bun on the current project, since we use unimplemented bun node: API. When bun will fully compatable with node.js - I will retest on the real project.

Observation 1: NPM is a second after bun by execution time. It blows my mind! 🤯

Observation 2: PNPM is a slowest package manager by execution time. Nevertheless, I’m still like it by installation and lock-resolving time.

I thing that Bun is preferable than Deno! Why? Because deno starts own ecosystem without node.js compatibility and it’s have own package system (as URL importing instead of local package name). URL import notation can confused developers and it always to be remember package URL.

Bunbye!