OATTS (OpenAPI Test Templates) is a utility designed to generate basic Node.js unit test scaffolding directly from an OpenAPI specification document. Currently at version 1.6.0, it provides both a command-line interface and a module API to automate the creation of boilerplate tests for your API endpoints. The generated tests are structured for the Mocha testing framework and utilize Chakram for API assertions, encouraging developers to maintain a consistent contract between their API specification and its implementation. While providing valuable scaffolding for early and continuous API contract testing, it's important to note that OATTS is described as a 'work in progress' and 'not an officially supported Google product', suggesting a less frequent release cadence and potentially limited long-term support compared to core Google projects. Its primary differentiator is its focus on generating runnable Mocha/Chakram tests specifically for Node.js environments, building on lessons learned from `swagger-test-templates`.
npm install oattsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically use `oatts` to generate unit test scaffolding for a simple OpenAPI specification, writing them to a specified directory. It includes cleanup for the dummy spec.
Factor this disclaimer into project adoption decisions; consider maintaining a local fork for critical projects that require long-term stability or specific feature sets.
Ensure `mocha` and `chakram` are installed as development dependencies in your project: `npm install --save-dev mocha chakram`.
Consistently use `const oatts = require('oatts');` for importing the module in your Node.js applications. If using ESM in your project, `oatts` might need to be dynamically imported or bundled with a tool that handles CJS-to-ESM conversion.Refer to the `oatts` documentation or the `templates` directory within the `oatts` source code for the exact required names and structure of custom Handlebars templates.
Upgrade to `oatts` version 1.3.0 or higher to ensure you benefit from these security fixes: `npm install oatts@latest`.
Install `mocha` and `chakram` as development dependencies in your project's test environment: `npm install --save-dev mocha chakram`.
Install the `oatts` CLI globally using `npm install -g oatts`, or execute the command directly using `npx oatts generate ...` if you prefer not to install globally.
Ensure you are importing the module using the CommonJS `require` syntax: `const oatts = require('oatts');`. Then, call `oatts.generate(...)`.Start your API server before running the generated tests. Verify that the `host` option supplied to `oatts.generate` (or the `--host` CLI option) correctly points to your running API's address and port.
No dependency data recorded yet.