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

play-fixture

v0.1.0-alpha.6

Published

play with playwright fixture

Readme

play-fixture

Play with playwright fixtures.

Description

This package converts Playwright fixtures into playable tests. This allows for the following:

  • Test setup and teardown of fixtures
  • Separate setup and teardown of the same fixture
  • Convenient setup and teardown of fixtures for other tests

fixtures are playable as tests in VSCode

fixtures are playable as tests in VSCode

The Problem

Fixtures are a core concept in Playwright. They provide an encapsulated, reusable, lazy-loaded, and composable way of establishing an environment.

However, fixtures are not runnable on their own, so it can be inconvenient to focus on writing and testing fixtures.

This package provides a solution to the problem using some tricks. It's not perfect, but it's usable.

In addition, manually performing setup for testing can be tedious. This package enables you to reuse fixture setups and automate the process.

Installation

npm install -D play-fixture

Usage

There are several steps to use this package:

  1. Create fixtures as ES modules.

    To create a fixture, create an ES module that exports the following named members:

    • name: The fixture name used in destructing params of tests.
    • setup: A function to set up the fixture values.
    • teardown: A function to tear down the fixture values.
    • reserveOnFail: Optional, boolean, defaults to false. If set to true, it will skip the teardown if some tests depend on the fixture and fail.

    Example:

    // project.fixture.ts
    export const name = "project";
    
    export const setup = async ({ page }) => {
      // create project here
      const project = {
        // project info used by other tests
      };
      return { project }; // return value is passed to `use`, as fixture value
    };
    
    export const teardown = async ({ page, project }) => {
      // teardown for the project
      return {project: null}; // return new value for other uses
    };
    export const name = "anotherFixture"
    
    export const setup = async ({page, project}) => {
     // setup another fixture here with project
     return {
       project,
       [name]: value
     }
    }
    
    export const teardown = async ({page, project}) => {
     // teardown for the fixture
     return {
       project,
       [name]: null
     }
    }
  2. Extend Playwright tests with fixtures.

    use testWithFixtures to extend playwright test, and utilize the exported test in other tests:

    // extended-test.ts
    import * as project from "./project.fixture";
    import { testWithFixtures } from "play-fixture";
    
    const test = testWithFixtures(fixtures);
    
    export default test;

    Optional unserialize and serialize functions can be used to recover or persist fixture values from storage.

    // extended-test.ts
    import * as project from "./project.fixture";
    import { testWithFixtures } from "play-fixture";
    
    const test = testWithFixtures(fixtures, {
      unserialize: () => {
        // read value from file or database
        return value;
      },
      serialize: (value) => {
        // serialize fixture value to file or database
      },
    });
    
    export default test;

    This is for reusing a pre-existing fixture multiple times. If unserialize is provided and returns a truthy value, the setup process will be skipped in order to use the value from unserialize. teardown and serialize will also be skipped.

  3. Convert the fixtures to tests in fixtures.test.ts.

    • To enable Playwright to discover tests, you need a test file. We use fixtures.test.ts.
    • To convert setup and teardown into tests, decorate them with wrap.

    Example:

    // fixtures.test.ts
    import * as fixtures from "./fixtures";
    import { wrap } from "play-fixture";
    import test from "./extended-test";
    
    Object.values(fixtures).forEach((fixture) => {
      test.describe(fixture.name, () => {
        let currentValue;
        const callback = (v) => {
          // do something with the value
        };
        test("setup", wrap(fixture.setup, callback));
        test("teardown", wrap(fixture.teardown, callback));
      });
    });

    Here are some details about wrap:

    • It hides the return value from the test, which is expected to be void.
    • It keeps the destructing object signature of setup and teardown, which is required by Playwright to parse required fixtures.
    • You may pass a callback to do something the fixture value
  4. Recommended: extend the Playwright configuration to enable only fixture tests in the VSCode extension.

    Since fixture tests are primarily for development and work best with the VSCode extension, it is recommended to enable them only for the VSCode Playwright extension.

    // playwright.config.ts
    import type { PlaywrightTestConfig } from "@playwright/test";
    import { config as playFixtureConfig } from "play-fixture";
    
    const config: PlaywrightTestConfig = {
      // configurations
    };
    
    export default playFixtureConfig(config);

    This function append testIgnore: "**/fixtures.{test,spec}.{ts,js,mjs}" to playwright config when extension detected.