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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tramvai/test-pw

v4.41.39

Published

Set of helpers for using [playwright](https://playwright.dev) in the integration tests

Downloads

1,355

Readme

Tramvai test Playwright

Set of helpers for using playwright in the integration tests

Playwright should be installed separately

Installation

npm install --save-dev @tramvai/test-pw

Usage

Configuration

Create file playwright.config.ts with defaults from @tramvai/test-pw package:

import { createPlaywrightConfig } from '@tramvai/test-pw';

export default createPlaywrightConfig();

You can always extend default config, here is createPlaywrightConfig type definition:

// passed configuration object will be merged with defaults
type createPlaywrightConfig = (config: PlaywrightTestConfig) => PlaywrightTestConfig;

Testing

:::tip

Use case for this section and startAppFixture - monorepo with many tramvai modules and example applications, where you need to test independent features.

All usage of startAppFixture in different workers will run development build, which might not be optimal for tests execution time, if you want to test the same app in different cases.

For real applications, prefer to run application once as web server or manually and pass baseUrl after.

:::

@tramvai/test-pw provide a useful fixture for application start (local server in development mode) and testing - startAppFixture. This fixture use startCli method from @tramvai/test-integration package.

First, you need to add and configure this fixture for application tests:

import path from 'path';
import { test as base } from '@playwright/test';
import type { StartAppTypes } from '@tramvai/test-pw';
import { startAppFixture } from '@tramvai/test-pw';

type TestFixture = {};

type WorkerFixture = {
  app: StartAppTypes.TestApp;
  appTarget: StartAppTypes.AppTarget;
  startOptions: StartAppTypes.StartOptions;
};

export const test = base.extend<TestFixture, WorkerFixture>({
  appTarget: [
    // provide application name and directory
    {
      target: 'appName',
      cwd: path.resolve(__dirname, '..'),
    },
    { scope: 'worker', auto: true, option: true },
  ],
  // any `startCli` parameters
  startOptions: [{
    env: {
      SOME_MOCKED_API: 'xxx'
    },
  }, { scope: 'worker', auto: true, option: true }],

  app: startAppFixture,
});

Then, use the app object in integration tests:

import { expect } from '@playwright/test';
import { test } from './test-fixture';

test.describe('examples/app', async () => {
  test('Navigation is visible', async ({ app, page }) => {
    await page.goto(app.serverUrl);

    expect(page.getByRole('navigation')).toBeVisible();
  });
});

You can find more info about app object in our Testing Guide

Production build testing

If you need to test production build, @tramvai/test-pw provide a few fixtures for it:

  • appServerFixture to run compiled application server
  • buildAppFixture to run production build of the application (will be called implicitly for appServerFixture)

First, configure fixtures:

import path from 'path';
import { test as base } from '@playwright/test';
import type { BuildAppTypes } from '@tramvai/test-pw';
import { appServerFixture } from '@tramvai/test-pw';

type TestFixture = {};

type WorkerFixture = {
  app: BuildAppTypes.TestApp;
  appTarget: BuildAppTypes.AppTarget;
  buildOptions: BuildAppTypes.StartOptions;
};

export const test = base.extend<TestFixture, WorkerFixture>({
  appTarget: [
    // provide application name and directory
    {
      target: 'appName',
      cwd: path.resolve(__dirname, '..'),
    },
    { scope: 'worker', auto: true, option: true },
  ],
  // any `buildCli` parameters
  buildOptions: [{
    env: {
      SOME_MOCKED_API: 'xxx'
    },
  }, { scope: 'worker', auto: true, option: true }],

  appServer: appServerFixture,
});

Then, use the appServer object in integration tests:

import { expect } from '@playwright/test';
import { test } from './test-fixture';

test.describe('examples/app', async () => {
  test('Navigation is visible', async ({ appServer, page }) => {
    await page.goto(`http://localhost:${appServer.port}/`);

    expect(page.getByRole('navigation')).toBeVisible();
  });
});