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

pseudo-fixture

v1.1.1

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 requires one type that specifies the fixtures. Optionally, you can pass a second type that specifies the options. The constructor requires a setup function for each fixture parameter. These functions define how the fixtures are created. Optionally, a teardown function can also be defined for each fixture.
Each setup and teardown function can depend on other fixtures. Those dependencies are automatically prepared before the specific setup or teardown runs.
If an options type is specified, the constructor also requires default values for the options. After setup, you can use the different methods of PseudoFixture to run callback functions. These callbacks can use all fixtures and options as parameters. When fixtures are used in the parameters, they are prepared (if they weren’t already in a previous run) and passed to the callback.

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: async () => {
                            return await browser.newContext()
                        },
                        teardown: async ({ context }) => {
                            await context.close()
                        }
                    },
                    page: {
                        setup: async ({ context }) => {
                            return await context.newPage()
                        }
                    },
                    request: {
                        setup: async ({ context }) => {
                            return context.request
                        }
                    },
                    user: {
                        setup: async ({ request, userData }) => {
                            await createUser(request, userData)
                            return userData
                        },
                        teardown: async ({ request, user }) => {
                            await deleteUser(request, user.username)
                        }
                    },
                    loginPage: {
                        setup: async ({ page }) => {
                            const loginPage = new LoginPage(page)
                            await loginPage.goto()
                            return loginPage
                        }
                    },
                    transactionPage: {
                        setup: 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(async (callback, options) => {
            const pseudoFixture = createPseudoFixture()
            return await 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(
        async ({ transactionPage }) => {
            return await transactionPage.createTransaction()
        }
    )

    await runPseudoFixture(
        async ({ transactionPage }) => {
            await 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(
        async ({ transactionPage }) => {
            return await transactionPage.createTransaction()
        }
    )

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

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

test.afterEach(async () => {
    await pseudoFixtureUser1.runTeardown()
})

License

This package is licensed under the MIT License.