@tsdoc-test-reporter is a test reporter that attaches TSDoc comments to your test results. It enables you to attach metadata to your unit tests in the form of comments.
Example output from the reporter
npm install @tsdoc-test-reporter/jest
npm install @tsdoc-test-reporter/vitest
jest.config.js
)/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
reporters: ['default', '@tsdoc-test-reporter/jest'],
};
/**
* @remarks
* WCAG Criteria
*/
test('get correct background color based on text color', () => {
expect(true).toBe(true);
});
tsdoc-test-reporter-report.html
in the browser of your choicevite.config.ts
)/// <reference types="vitest" />
import { defineConfig } from 'vite';
export default defineConfig({
test: {
reporters: ['@tsdoc-test-reporter/vitest'],
},
});
/**
* @remarks
* WCAG Criteria
*/
test('get correct background color based on text color', () => {
expect(true).toBe(true);
});
vitest run
)tsdoc-test-reporter-report.html
in the browser of your choiceSee the documentation for the config for full docs of possible options
/** @type {import('@tsdoc-test-reporter/jest').TsDocTestReporterConfig} */
const options = {
outputFileName: 'reports/tsdoc-report',
uiOptions: {
htmlTitle: 'Title of HTML Page',
},
};
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
reporters: ['default', ['@tsdoc-test-reporter/jest', options]],
};
See the documentation for the config for full docs of possible options
// reporter.ts
import TSDocTestReporter from '@tsdoc-test-reporter/vitest';
import { Reporter } from 'vitest/reporters';
import type { File, Vitest } from 'vitest';
export default class MyDefaultReporter extends Reporter {
private reporter: TSDocTestReporter;
constructor() {
this.reporter = new TSDocTestReporter({
outputFileName: 'reports/tsdoc-report',
uiOptions: {
htmlTitle: 'Title of HTML Page',
},
});
}
onInit(ctx: Vitest) {
this.reporter.onInit(ctx);
}
onFinished(files: File[]) {
this.reporter.onFinished(files);
}
}
/// <reference types="vitest" />
import { defineConfig } from 'vite';
export default defineConfig({
test: {
reporters: ['./reporter.ts'],
},
});
/** @type {import('@tsdoc-test-reporter/jest').TsDocTestReporterConfig} */
const options = {
customTags: [
{
tagName: '@customModifierTag',
syntaxKind: 2,
},
],
};
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
reporters: ['default', ['@tsdoc-test-reporter/jest', options]],
};
// reporter.ts
import TSDocTestReporter from '@tsdoc-test-reporter/vitest';
import { Reporter } from 'vitest/reporters';
import type { File, Vitest } from 'vitest';
export default class MyDefaultReporter extends Reporter {
private reporter: TSDocTestReporter;
constructor() {
this.reporter = new TSDocTestReporter({
customTags: [
{
tagName: '@customModifierTag',
syntaxKind: 2,
},
],
});
}
onInit(ctx: Vitest) {
this.reporter.onInit(ctx);
}
onFinished(files: File[]) {
this.reporter.onFinished(files);
}
}
,
you can supply it as an option./**
* @remarks
* unit,acceptance,whatever
*/
test('get correct background color based on text color', () => {
expect(true).toBe(true);
});
@see {@link variableName}
. If the linked reference is a variable it will be resolved to a value if it is in scope of the source file (in the source file or imported by the source file). This is limited to string literals and object properties that are string literals (or enums). The example below works, and works if the enum is imported as a named import.const enum MyEnum {
Key = 'Value',
}
/**
* @see {@link MyEnum.Key}
*/
test('get correct background color based on text color', () => {
expect(true).toBe(true);
});
test.each
or similar where you are using placeholders in the test title, this test will not be able to match the JSDoc to the test assertion. You will have to wrap that each block with a describe
and add a JSDoc to the describe
block. If you are not using parameters in the title, test.each
will work./**
* @remarks
* unit,acceptance
*/
test.each([{ name: 'value' }])('this will fail: $name', () => {
expect(true).toBe(true);
});
Generated using TypeDoc