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

@dvsa/api-test-kit

v0.1.0

Published

Playwright API test kit for testing endpoints

Readme

API test kit

Shared Playwright API test fixtures and request utilities. Install the kit and a compatible Playwright runner as development dependencies:

npm install --save-dev @dvsa/api-test-kit @playwright/test

Configure authentication

The consuming service loads and validates its environment, then passes configuration to the factory in its own fixture module:

import { createApiTest } from '@dvsa/api-test-kit';
import { config } from '../config';

export const test = createApiTest({
  jwt: {
    fetchUrl: `${config.jwt.baseUrl}/vta`,
    apiKey: config.jwt.apiKey,
    username: config.jwt.username,
    password: config.jwt.password,
  },
});

export { expect } from '@dvsa/api-test-kit';

The package does not read environment variables or assume a token URL suffix. Authentication posts { username, password } with an x-api-key header and expects { token: string }.

getAuthToken() fetches lazily and caches the token per worker. It refreshes 30 seconds before the JWT expiry and disposes its request context when the worker finishes. Tokens without a decodable expiry are reused for that worker's lifetime. Decoding the expiry does not verify the JWT signature.

Send API requests

Import test from your configured fixture module:

import { getApiResponse } from '@dvsa/api-test-kit';
import { test, expect } from './helpers/fixtures';

test('updates an item', async ({ request, getAuthToken }) => {
  const response = await getApiResponse(request, '/items/123', {
    method: 'PATCH',
    token: await getAuthToken(),
    data: { name: 'updated' },
    headers: { 'x-correlation-id': 'example' },
  });

  expect(response.status()).toBe(200);
});

method supports GET, PUT, POST, DELETE and PATCH; it defaults to GET. Pass an absolute URL, or configure Playwright's use.baseURL for relative paths. Playwright uses standard URL resolution: /items starts at the origin root; items preserves a base path when the base URL ends with /.

The remaining options are Playwright's fetch options, including params, data, form, multipart, headers and timeout. The helper returns the unparsed APIResponse so tests can inspect status, headers and body.

token adds a Bearer authorization header. Explicit authorization headers take precedence regardless of casing. Omitting the token adds no authorization header; any authentication configured on the request context still applies. Use a context without default authentication for unauthenticated tests.

Response utilities and test data

The package also exports parseJsonOrThrow, decodeBase64Gzip, getTokenExpiryMs, getJwtToken and their configuration/request types.

Expected responses stay in the consuming service. readJsonFixture takes a caller-resolved file path:

import { resolve } from 'node:path';
import { readJsonFixture } from '@dvsa/api-test-kit';

const expected = readJsonFixture(resolve(__dirname, 'resources', 'expected.json'));

Development

From the workspace root:

npm install
npm run build --workspace=@dvsa/api-test-kit
npm test --workspace=@dvsa/api-test-kit -- --runInBand
npm run lint --workspace=@dvsa/api-test-kit

The build emits CommonJS (index.cjs) and ES module (index.mjs) bundles with matching declarations into dist. The existing publish lifecycle copies these files to the package root, where package.json entry points select the appropriate bundle and types. The package regression tests build and load this published layout using both require and import. Public APIs are exported from src/index.ts. Playwright is a peer dependency so consumers supply the runner; it is also a development dependency for this package's checks.