swagger-test-templates is a Node.js library designed to generate API test code directly from a Swagger 2.0 specification. It currently stands at version 1.6.0, with its most recent listed releases (1.5.0, 1.4.0) indicating ongoing maintenance rather than rapid feature development. The library differentiates itself by allowing users to specify the assertion format (e.g., 'should', 'expect', 'assert') and the HTTP request module (e.g., 'supertest', 'request') for the generated tests. It also includes capabilities for generating load tests and supports custom Handlebars templates for advanced customization of the test output. A key limitation is its exclusive focus on Swagger 2.0, meaning it does not natively support newer OpenAPI 3.x specifications.
npm install swagger-test-templatesVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `swagger-test-templates` with a mock Swagger 2.0 spec and configuration, generating test files for specified paths and including basic load test setup.
Ensure your API specification is in Swagger 2.0 format. For OpenAPI 3.x, consider alternative test generation tools or manual conversion.
If using `templatesPath`, ensure your custom directory contains all necessary Handlebars templates (e.g., base-test.js.handlebars, request-test.js.handlebars, load-test.js.handlebars) or your generated tests may be incomplete.
Carefully review the `requestData` structure in the documentation, ensuring keys for path, operation, and response code, along with an array of objects containing `body` (for HTTP body) or parameter keys (for path/query params).
Explicitly list the paths you wish to test in the `pathName` array. If you truly want all paths, document this choice clearly in your configuration.
For CommonJS, use `const stt = require('swagger-test-templates');`. For ESM, use `import stt from 'swagger-test-templates';`. Then call `stt(swagger, config);`.Add a valid `assertionFormat` property (e.g., 'should', 'expect', or 'assert') to your configuration object: `config: { assertionFormat: 'should', ... }`.Add a valid `testModule` property (e.g., 'supertest' or 'request') to your configuration object: `config: { testModule: 'supertest', ... }`.Verify that your `requestData` object precisely follows the `/endpoint -> operation -> responseCode -> array of data` format, and that the data objects themselves contain the correct keys for parameters or the `body` property for request bodies.
No dependency data recorded yet.