Configurapi Test Utils
raw JSON → 1.0.5 verified Sat Apr 25 auth: no javascript
Helper utilities for testing Configurapi handlers. v1.0.5 ships TypeScript types, but the package is very new and may have limited documentation. Offers base test classes and mocks for Configurapi environments. Currently stable with no known breaking changes, but the API may evolve. Differentiator: purpose-built for Configurapi, reducing boilerplate in integration tests.
Common errors
error SyntaxError: Cannot use import statement outside a module ↓
cause Trying to import the package in a CommonJS file without 'type': 'module'.
fix
Add 'type': 'module' to your package.json or use .mjs extension for the importing file.
error TypeError: MockRequest is not a constructor ↓
cause Using default import instead of named import.
fix
Use import { MockRequest } from 'configurapi-test-utils'.
Warnings
breaking Package is ESM-only. CommonJS require() will throw an error. ↓
fix Use dynamic import() or configure your project to use ESM.
gotcha MockResponse.body might not be a string; check type definitions. ↓
fix Cast body to expected type or use toJSON() if available.
gotcha TestHandler.run() expects async handler; wrapping non-async handler may cause issues. ↓
fix Ensure handler is async or returns a Promise.
Install
npm install configurapi-test-utils yarn add configurapi-test-utils pnpm add configurapi-test-utils Imports
- TestHandler wrong
import TestHandler from 'configurapi-test-utils'correctimport { TestHandler } from 'configurapi-test-utils' - MockRequest wrong
const { MockRequest } = require('configurapi-test-utils')correctimport { MockRequest } from 'configurapi-test-utils' - MockResponse wrong
import { MockResponse } from 'configurapi-test-utils'correctimport type { MockResponse } from 'configurapi-test-utils'
Quickstart
import { TestHandler, MockRequest, MockResponse } from 'configurapi-test-utils';
import { handler } from './my-handler';
const req = new MockRequest({
method: 'GET',
path: '/items',
query: { limit: '10' },
headers: { 'content-type': 'application/json' },
body: null
});
const res = new MockResponse();
TestHandler.run(handler, req, res).then(() => {
console.log(res.statusCode); // 200
console.log(res.body); // response body
});