/** * Jest transformer that will scan a program file (i.e. CLI run file) and make it a module * for the CLIRunner instance to run so that jest mocks to work on it. * * Usage: * * In your jest.config.js add this transformer * * { * // other config * transform: { * "\\.[jt]sx?$": "/lib/testing/CLIScriptTester/cliTransformer.js", * }, * // Configuration for setting up a cli script * globals: { * cliTransformer: { * cliScripts: [ '.*bin/.*.[jt]s' ] * } * } * } * * The cliTransformer's options are controlled by adding a globals entry in your jest config for cliTransformer * * The only option at the moment is to add a list of regex strings for 'cliScripts' that should match those scripts * that you intend to transform. Please make sure that you are not transforming unintended files. */ import type { Transformer, TransformerCreator } from "@jest/transform"; import type { ecmaVersion } from "acorn"; /** * The string can be a RegExp string */ type ScriptPaths = string; interface CLITransformerOptions { /** * Scripts that don't have the @CLITestTransform comment can still be transformed * by supplying script paths here. * * Note: if you are using a transform that doesn't preserve comments, you would need to use * this or edit your transoform config to keep comments. */ cliScripts: ScriptPaths[]; /** * Ecmascript Version */ ecmaVersion: ecmaVersion; } declare const cliTransformerFactory: { createTransformer: TransformerCreator, CLITransformerOptions>; }; export default cliTransformerFactory;