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

@magicsandbox.ai/test

v0.1.2

Published

`@magicsandbox.ai/test` makes it easy to run [Playwright](https://playwright.dev/) tests for [Magic Sandbox](https://magicsandbox.ai) Apps.

Readme

@magicsandbox.ai/test

@magicsandbox.ai/test makes it easy to run Playwright tests for Magic Sandbox Apps.

Getting Started

npm install "@magicsandbox.ai/test"

See the Magic Sandbox docs to learn more about Magic Sandbox.

Cost Warning

Because there are costs associated with loading Apps on Magic Sandbox, there are costs associated with running tests. See the Tests Cost Warning and Configuration Cost Warning sections below for more details.

Usage

Set up a folder structured like so:

.env
MyApp/
├── magic.json5
├── index.js
└── tests/
    ├── test1.spec.js
    └── test2.spec.js

@magicsandbox.ai/test requires the MAGICSANDBOX_API_KEY environment variable to be set, which you can set in a .env file in your project root. You can get an API key here.

See Writing Tests for details on creating the test files like test1.spec.js.

@magicsandbox.ai/test depends on @magicsandbox.ai/dev, so you should already be able to successfully run npx magicsandbox dev MyApp.

Then run:

npx magicsandbox test MyApp

This command will:

  • Run npx playwright install to ensure the Playwright browsers used for testing are installed
  • Start the @magicsandbox.ai/dev development server for MyApp if it's not already running
  • If you haven't already, create a playwright.config.js file in MyApp/tests for you. See Configuration for details.
  • Run the tests in MyApp/tests

Any additional arguments are passed to the Playwright CLI:

npx magicsandbox test MyApp --ui

Writing Tests

See the Playwright docs for details on writing tests.

@magicsandbox.ai/test extends Playwright's test function by adding an app fixture. When you use the app fixture, @magicsandbox.ai/test handles:

  • Authentication using your API key
  • Loading the correct URL and waiting for the dev server to build the app
  • Selecting the correct nested iframe to use as the app fixture

app is a Playwright Frame object.

Here's an example test:

import { test, expect } from "@magicsandbox.ai/test";

test("example test", async ({ app }) => {
  await expect(app.getByText("Hello, world!")).toBeVisible();
  await app.getByRole("button", { name: "Click me" }).click();
  await expect(app.getByText("Button clicked!")).toBeVisible();
  const context = await app.evaluate(() => app.context()); //https://playwright.dev/docs/api/class-frame#frame-evaluate
  expect(context).toEqual("This is the context");
  await app.evaluate(() => {
    const text = app.api.text;
    app.api.setText(text + " Goodbye!");
  });
  await expect(app.getByText("Button clicked! Goodbye!")).toBeVisible();
});

By default, app.init is automatically called. If you want to test init, disable this behavior like so:

test.describe("run tests with autoInit disabled", () => {
  test.use({ appOptions: { autoInit: false } });
  test("test init", async ({ app }) => {
    await expect(app.getByText("Hello, world!")).not.toBeVisible();
    const init = await app.evaluate(() => app.init());
    expect(init).toEqual("This is the init");
    await expect(app.getByText("Hello, world!")).toBeVisible();
  });
});

To disable magicsandbox.Assistant user confirmation prompts (for example, when spending money with requestFunction), set autoConfirm to true:

test.use({ appOptions: { autoConfirm: true } });

See the ExampleApp folder for an App that passes the above tests.

Tests Cost Warning

Each Playwright test runs in a new browser instance. That means each test has to load the Apps magicsandbox.Assistant and magicsandbox.DevLocal at a cost of $0.002. Be sure not to run thousands of tests!

Use extra caution when setting autoConfirm to true.

Configuration

You can create or edit the playwright.config.js file in your App's tests folder and magicsandbox.ai/test won't override your changes. See the Playwright docs for details.

When the dev server first starts, the initial build can be slow (rebuilds are much faster). To guard against slow builds causing tests to fail, magicsandbox.ai/test configures a timeout of 60 seconds rather than Playwright's default of 30 seconds.

Configuration Cost Warning

Because each test has a cost, consider carefully the impact of using projects to configure Playwright to run tests across many browsers or configurations.