UNPKG

approvals

Version:

Approval Tests Library - Capturing Human Intelligence

105 lines (103 loc) 5.28 kB
import * as cfg from "./config"; import { Namer } from "./Core/Namer"; import { ReporterLoader } from "./Reporting/ReporterFactory"; import { Scrubber, Scrubbers } from "./Scrubbers/Scrubbers"; import { Writer } from "./Core/Writer"; /** * Contains some helpful and util scrubbers that can be used for scrubbing data before saving to a received file. */ export { Scrubbers as scrubbers }; /** * Allows you to provide overrides to the default configuration. * * @example * const approvals = require('approvals'); * approvals.configure({ * reporters: ['p4merge'] * }); * * @param {*} overrideOptions */ export declare function configure(overrideOptions: cfg.Config): typeof module.exports; /** * Allows the creation of an approvals configuration object using any passed in options to override the defaults. * @param {Object} overrideOptions * @returns {Object} approvals config object with any options overridden. */ export declare function getConfig(overrideOptions?: cfg.Config): cfg.Config; /** * Configure approvals to hook into Mocha tests. * @param {*} optionalBaseDir - An optional folder to save approval files to. */ export declare function mocha(optionalBaseDir?: string): typeof module.exports; /** * `reporters` gives access to the `MultiReporter` * * @example * const MultiReporter = approvals.reporters.MultiReporter */ export declare const reporters: { MultiReporter: any; }; /** * * @example * // basic approval test * const approvals = require('approvals'); * approvals.verify(__dirname, 'sample-approval-test', "some text to verify"); * * @example * // basic approval test providing an option to override configuration * const approvals = require('approvals'); * approvals.verify(__dirname, 'sample-approval-test', "some text to verify", { normalizeLineEndingsTo: true }); * * @param {string} dirName - Typically `__dirname` but could be the base-directory (anywhere) to store both approved and received files. * @param {string} testName - A file name save string to call the file associated with this test. * @param {(string|Buffer)} data - Either the string to save as a text file or a Buffer that represents an image * @param {*} optionsOverride - An object that can contain configurational overrides as defined in the approvals configuration object. */ export declare function verify(dirName: string, testName: string, data: any, optionsOverride?: any): void; /** * You can pass as "data" any javascript object to be JSON.stringified and run verify against. * * @example * const approvals = require('approvals'); * approvals.verifyAndScrub(__dirname, 'sample-approval-test', { a: "some text in an object" }); * * @param {string} dirName - Typically `__dirname` but could be the base-directory (anywhere) to store both approved and received files. * @param {string} testName - A file name safe string to call the file associated with this test. * @param {(string|Buffer)} data - This can be any JavaScript object/array that will be JSON.stringified before running verify * @param {*} optionsOverride - An object that can contain configurational overrides as defined in the approvals configuration object. */ export declare function verifyAsJSON(dirName: string, testName: string, data: any, optionsOverride: any): void; /** * You can pass as "data" any javascript object to be JSON.stringified. Before we run verify the scrubber will be run against the complete string before running verify against it. * @example * // basic approval test with a custom scrubber * const approvals = require('approvals'); * const scrubber = approvals.scrubbers.multiScrubber([ * function (data) { * return (data || '').replace("some text", "some other text"); * }, * approvals.scrubbers.guidScrubber // to remove guids from the received data * }); * approvals.verifyAndScrub(__dirname, 'sample-approval-test', { a: "some text in an object" }, scrubber); * * @param {string} dirName - Typically `__dirname` but could be the base-directory (anywhere) to store both approved and received files. * @param {string} testName - A file name safe string to call the file associated with this test. * @param {(string|Buffer)} data - This can be any JavaScript object/array that will be JSON.stringified before running verify * @param {*} scrubber - A function that takes a string and returns a string. Approvals will call this if it exists to scrub the "data" before writing to any files. * @param {*} optionsOverride - An object that can contain configurational overrides as defined in the approvals configuration object. */ export declare function verifyAsJSONAndScrub(dirName: string, testName: string, data: any, scrubber: Scrubber, optionsOverride: any): void; /** * This allows you to take full control of naming and writing files before verifying. * * For an example that we use to generate the docs within the readme, check out the [test/readmeTests.mts](test/readmeTests.mts) in this project. * * @param {Object} namer * @param {Object} writer * @param {Function} [reporterFactory] * @param {Object} [optionsOverride] */ export declare function verifyWithControl(namer: Namer, writer: Writer, reporterFactory?: ReporterLoader | null, optionsOverride?: Partial<cfg.Config>): void;