ESDoc2 Integrate Test Plugin
This package, `esdoc2-integrate-test-plugin`, functions as a specialized plugin for the ESDoc2 documentation generator. Its primary purpose is to seamlessly embed and link integration test documentation directly into the output generated by ESDoc2. Users configure the plugin within their `esdoc2` setup to specify the source directories containing test files, define recognized testing interfaces (such as `describe`, `it`, `context`, `suite`, and `test`), and apply include/exclude regex patterns to precisely control which test files are processed. The plugin is currently on version 2.0.0, with a recent feature release (v2.1.0) indicating ongoing maintenance and development. Its key differentiator lies in enabling comprehensive documentation that cross-references code with its corresponding integration tests, enhancing clarity for maintainers and consumers of the documented codebase. The release cadence appears feature-driven, providing updates as new capabilities are added or existing ones are refined.
Common errors
-
Error: The plugin 'esdoc2-integrate-test-plugin' could not load.
cause esdoc2 could not find the plugin package or there was an error in its configuration.fixEnsure `esdoc2-integrate-test-plugin` is installed (`npm install esdoc2-integrate-test-plugin`) and correctly referenced by name in your `esdoc2` configuration's `plugins` array. -
TypeError: Cannot read property 'source' of undefined
cause The `source` option for the `esdoc2-integrate-test-plugin` within its `option` object is missing or null.fixAdd a `source` property with a valid path to your test files, e.g., `"option": { "source": "./test/" }`. -
Some test files are not appearing in my documentation.
cause The `includes` or `excludes` regular expressions are incorrectly configured, preventing the plugin from identifying your test files.fixReview the `includes` and `excludes` patterns in your `esdoc2` configuration to ensure they correctly match the filenames and paths of your integration tests. Use online regex testers to validate.
Warnings
- gotcha The plugin requires `esdoc2` to be installed and configured in your project. This plugin does not run tests itself but rather integrates the *documentation* of your tests into ESDoc2.
- breaking The `source` option within the plugin's configuration is mandatory. Omitting it will prevent the plugin from locating your integration test files.
- gotcha Regex patterns for `includes` and `excludes` must be correctly formatted JavaScript regular expressions. Incorrect patterns can lead to test files being missed or incorrect files being included.
- gotcha The `interfaces` option defines the global test functions (like `describe`, `it`) that the plugin recognizes. If you use custom test framework functions or aliases, you must add them to this list.
Install
-
npm install esdoc2-integrate-test-plugin -
yarn add esdoc2-integrate-test-plugin -
pnpm add esdoc2-integrate-test-plugin
Quickstart
// esdoc.config.js
/**
* @type {import('esdoc2').Config}
*/
module.exports = {
// Source directory for your main application code
source: './src',
// Destination directory for the generated documentation
destination: './docs',
// Array of plugins to extend ESDoc2's functionality
plugins: [
{
// Name of the integration test plugin
name: 'esdoc2-integrate-test-plugin',
// Options specific to this plugin
option: {
// Source directory for your integration test files
source: './test/',
// List of global test interfaces to recognize and link (e.g., from Mocha, Jest)
interfaces: ['describe', 'it', 'context', 'suite', 'test'],
// Regex patterns to include specific test files
includes: ['(spec|Spec|test|Test)\\.js$', '(integration|e2e)\\.ts$'],
// Regex patterns to exclude specific test files (e.g., configuration files)
excludes: ['\\.config\\.js$', '\\.fixture\\.js$']
}
}
]
};
// To run this configuration, save it as `esdoc.config.js` in your project root
// and execute: `npx esdoc2` in your terminal.