npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

vitest-browser-commands

v0.2.0

Published

A set of custom server commands for Vitest browser mode

Readme

vitest-browser-commands

NPM version

Vitest is a test runner for JavaScript and TypeScript. Vitest browser mode allows you to run your tests in the browser natively, and it provides an unified API for different underlying end-to-end providers like Playwright and WebdriverIO.

However, sometimes you want to invoke the underlying provider's API directly, for example, you want to invoke the Playwright API directly to interact with mouse or keyboard, which is not supported yet by Vitest browser mode.

This packages provides a set of custom commands for Vitest browser mode that allows you to invoke the underlying provider's API directly. Currently, it only supports the Playwright provider, but it can be easily extended to support other providers. Welcome contributions!

Usage

In your vitest config file, you need to import the playwrightCommands plugin from vitest-browser-commands and configure the browser provider to use the playwright provider.

// vitest.config.ts

import { defineConfig } from 'vitest/config'
import { playwright } from '@vitest/browser-playwright'
import { playwrightCommands } from 'vitest-browser-commands'

export default defineConfig({
  plugins: [playwrightCommands()],
  test: {
    browser: {
      enabled: true,
      provider: playwright(),
      instances: [{ browser: 'chromium' }],
    },
  },
})

In your test code, you can import various objects from vitest-browser-commands/playwright to interact with the browser. For example, you can import the mouse object to interact with the mouse or the keyboard object to interact with the keyboard. See the API section below for more details.

// tests/browser.test.ts
import { it } from 'vitest'
import { mouse, keyboard } from 'vitest-browser-commands/playwright'
import { render } from './my-render-function.js'

it('should be able to interact with the mouse', async () => {
  // mount DOM elements
  render()

  // interact with the mouse to trace a 100x100 square
  await mouse.move(0, 0)
  await mouse.down()
  await mouse.move(0, 100)
  await mouse.move(100, 100)
  await mouse.move(100, 0)
  await mouse.move(0, 0)
  await mouse.up()
})

it('should be able to interact with the keyboard', async () => {
  // mount DOM elements
  render()

  // type text into a focused input
  await keyboard.type('Hello World')

  // press Enter key
  await keyboard.press('Enter')
})

API

Playwright

mouse

The mouse object is a wrapper around the Playwright Mouse API. It has the identical API as the Playwright Mouse API, but it is wrapped in a way that it can be run in the browser.

// tests/browser.test.ts
import { mouse } from 'vitest-browser-commands/playwright'

await mouse.click(x, y)
await mouse.click(x, y, options)

await mouse.dblclick(x, y)
await mouse.dblclick(x, y, options)

await mouse.down()
await mouse.down(options)

await mouse.move(x, y)
await mouse.move(x, y, options)

await mouse.up()
await mouse.up(options)

await mouse.wheel(deltaX, deltaY)

keyboard

The keyboard object is a wrapper around the Playwright Keyboard API. It has the identical API as the Playwright Keyboard API, but it is wrapped in a way that it can be run in the browser.

// tests/browser.test.ts
import { keyboard } from 'vitest-browser-commands/playwright'

await keyboard.down(key)

await keyboard.up(key)

await keyboard.press(key)
await keyboard.press(key, options)

await keyboard.type(text)
await keyboard.type(text, options)

await keyboard.insertText(text)

License

MIT