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 🙏

© 2026 – Pkg Stats / Ryan Hefner

pseudo-fixture

v1.2.0

Published

Contains a small helper class for creating reusable fixture structures.

Readme

pseudo-fixture

pseudo-fixture contains a small helper class for creating reusable fixture structures.

Installation

npm i -D pseudo-fixture

Basic Usage

PseudoFixture takes a fixtures type and optionally an options type. You define how each fixture is created with setup functions and can optionally add teardown functions. Setup and teardown functions can depend on other fixtures. Dependencies are handled automatically. If you use options, you also provide default option values. You can then run callbacks through PseudoFixture. Any fixtures used by the callback are automatically prepared and passed in.

Methods of PseudoFixture

  • run(callback): Prepares all fixtures required by the callback function and executes the callback with them.

  • fullRun(callback, options?): Prepares all fixtures required by the callback function and executes the callback with them. Before and after the callback the teardown is run.

  • runTeardown(): Runs all teardown functions of used fixtures.

Example Usage in Playwright

You can for example use pseudo-fixture in Playwright to create a fixture structure for working in multiple contexts:
Suppose we have an application with a login page and a transaction page. Transactions can be created by users with the role "basic" but only approved by users with the role "approver". We could create the following custom fixtures:
Define the types used for the PseudoFixture:

// Defines what can be used inside the PseudoFixture.
export type PseudoFixtures = {
    context: BrowserContext
    page: Page
    request: APIRequestContext
    user: { username: string; password: string; role: string }
    loginPage: LoginPage
    transactionPage: TransactionPage
}

// Defines what can be configured for the PseudoFixture.
type PseudoOptions = {
    userData: { username: string; password: string; role: string }
}

Define the types used for the custom Playwright fixtures:

// Defines custom Playwright fixtures.
type Fixtures = {
    createPseudoFixture: (
        defaultOptions?: PseudoOptions
    ) => PseudoFixture<PseudoFixtures, PseudoOptions>
    runPseudoFixture: <T>(
        callback: (fixtures: PseudoFixtures) => Promise<T>,
        options?: PseudoOptions
    ) => Promise<T>
}

Extend the Playwright test object with the custom fixtures and create the PseudoFixture:

// Extends Playwright test.
export const test = base.extend<Fixtures>({
    // Creates a function to generate new PseudoFixtures.
    // Every key of type PseudoFixtures needs a setup function to define how the data is created.
    // Optionally a teardown function can be defined.
    createPseudoFixture: async ({ browser }, use) => {
        await use((defaultOptions) => {
            return new PseudoFixture<PseudoFixtures, PseudoOptions>(
                {
                    context: {
                        setup: () => browser.newContext(),
                        teardown: ({ context }) => context.close()
                    },
                    page: ({ context }) => context.newPage(),
                    request: ({ context }) => context.request,
                    user: {
                        setup: async ({ request, userData }) => {
                            await createUser(request, userData)
                            return userData
                        },
                        teardown: ({ request, user }) =>
                            deleteUser(request, user.username)
                    },
                    loginPage: async ({ page }) => {
                        const loginPage = new LoginPage(page)
                        await loginPage.goto()
                        return loginPage
                    },
                    transactionPage: async ({ user, page, loginPage }) => {
                        await loginPage.login(user)
                        return new TransactionPage(page)
                    }
                },
                defaultOptions || {
                    userData: {
                        username: 'user1',
                        password: 'password',
                        role: 'basic'
                    }
                }
            )
        })
    },

    // Creates a function that uses the fullRun method of PseudoFixture to run the callback and the teardown with the specified options.
    runPseudoFixture: async ({ createPseudoFixture }, use) => {
        await use((callback, options) => {
            const pseudoFixture = createPseudoFixture()
            return pseudoFixture.fullRun(callback, options)
        })
    }
})

Now we can use the PseudoFixture inside our test functions. For example, we could have a test case where we create a transaction with our default user with role "basic" and after that approve the transaction with a second user with role "approver". The creation of the users and the navigation is handled in the PseudoFixture.

test('Transaction workflow', async ({ runPseudoFixture }) => {
    const transactionID = await runPseudoFixture(({ transactionPage }) =>
        transactionPage.createTransaction()
    )

    await runPseudoFixture(
        ({ transactionPage }) =>
            transactionPage.approveTransaction(transactionID),
        {
            userData: {
                username: 'user2',
                password: 'password',
                role: 'approver'
            }
        }
    )
})

Alternatively, we could also keep the PseudoFixture and run a second callback to continue the transaction after the approval:

let pseudoFixtureUser1: PseudoFixture<PseudoFixtures>

test.beforeEach(({ createPseudoFixture }) => {
    pseudoFixtureUser1 = createPseudoFixture()
})

test('Transaction workflow', async ({ runPseudoFixture }) => {
    const transactionID = await pseudoFixtureUser1.run(({ transactionPage }) =>
        transactionPage.createTransaction()
    )

    await runPseudoFixture(
        ({ transactionPage }) =>
            transactionPage.approveTransaction(transactionID),
        {
            userData: {
                username: 'user2',
                password: 'password',
                role: 'approver'
            }
        }
    )

    await pseudoFixtureUser1.run(({ transactionPage }) =>
        transactionPage.continueAfterApproval(transactionID)
    )
})

test.afterEach(() => pseudoFixtureUser1.runTeardown())

PseudoFixture objects are async disposables. If a PseudoFixture is only used within a single test, it can be created with await using to automatically run teardown when the object goes out of scope:

test('Transaction workflow', async ({
    createPseudoFixture,
    runPseudoFixture
}) => {
    await using pseudoFixtureUser1 = createPseudoFixture()

    const transactionID = await pseudoFixtureUser1.run(({ transactionPage }) =>
        transactionPage.createTransaction()
    )

    await runPseudoFixture(
        ({ transactionPage }) =>
            transactionPage.approveTransaction(transactionID),
        {
            userData: {
                username: 'user2',
                password: 'password',
                role: 'approver'
            }
        }
    )

    await pseudoFixtureUser1.run(({ transactionPage }) =>
        transactionPage.continueAfterApproval(transactionID)
    )
})

License

This package is licensed under the MIT License.