import { mock } from 'node:test'; import type { BaseEnvironment, BaseEnvironmentOptions, BaseGenerator, BaseGeneratorOptions, GetGeneratorConstructor, InstantiateOptions, PromptAnswers } from '@yeoman/types'; import type { DefaultEnvironmentApi, DefaultGeneratorApi } from '../types/type-helpers.js'; import { type DummyPromptOptions, TestAdapter, type TestAdapterOptions } from './adapter.js'; import RunContext, { BasicRunContext, type RunContextSettings } from './run-context.js'; export type CreateEnv = (options: BaseEnvironmentOptions) => Promise; /** * Dependencies can be path (autodiscovery) or an array [, ] */ export type Dependency = string | Parameters; /** * Collection of unit test helpers. (mostly related to Mocha syntax) * @class YeomanTest */ export declare class YeomanTest { settings?: RunContextSettings; environmentOptions?: BaseEnvironmentOptions; generatorOptions?: BaseGeneratorOptions; adapterOptions?: Omit; /** * @deprecated * Create a function that will clean up the test directory, * cd into it. Intended for use * as a callback for the mocha `before` hook. * * @param dir - path to the test directory * @returns mocha callback */ setUpTestDirectory(dir: string): () => void; /** * @deprecated * Clean-up the test directory and cd into it. * Call given callback after entering the test directory. * @param dir - path to the test directory * @param cb - callback executed after setting working directory to dir * @example * testDirectory(path.join(__dirname, './temp'), function () { * fs.writeFileSync('testfile', 'Roses are red.'); * }); */ testDirectory(dir: string, callback?: (error?: any) => unknown): unknown; /** * @deprecated * Answer prompt questions for the passed-in generator * @param generator - a Yeoman generator or environment * @param answers - an object where keys are the * generators prompt names and values are the answers to * the prompt questions * @param options - Options or callback * @example * mockPrompt(angular, {'bootstrap': 'Y', 'compassBoostrap': 'Y'}); */ mockPrompt(environmentOrGenerator: BaseGenerator | DefaultEnvironmentApi, mockedAnswers?: PromptAnswers, options?: DummyPromptOptions): void; /** * @deprecated * Restore defaults prompts on a generator. * @param generator or environment */ restorePrompt(environmentOrGenerator: BaseGenerator | DefaultEnvironmentApi): void; /** * @deprecated * Provide mocked values to the config * @param generator - a Yeoman generator * @param localConfig - localConfig - should look just like if called config.getAll() */ mockLocalConfig(generator: BaseGenerator, localConfig: any): void; /** * Create a mocked generator */ createMockedGenerator(GeneratorClass?: any): ReturnType; /** * Create a simple, dummy generator */ createDummyGenerator(Generator?: GetGeneratorConstructor, contents?: Record void>): new (...arguments_: any[]) => GenParameter; /** * Create a generator, using the given dependencies and controller arguments * Dependecies can be path (autodiscovery) or an array [{generator}, {name}] * * @param name - the name of the generator * @param dependencies - paths to the generators dependencies * @param args - arguments to the generator; * if String, will be split on spaces to create an Array * @param options - configuration for the generator * @param localConfigOnly - passes localConfigOnly to the generators * @example * var deps = ['../../app', * '../../common', * '../../controller', * '../../main', * [createDummyGenerator(), 'testacular:app'] * ]; * var angular = createGenerator('angular:app', deps); */ createGenerator(name: string | GetGeneratorConstructor, options?: { dependencies?: Dependency[]; localConfigOnly?: boolean; } & InstantiateOptions): Promise; /** * Shortcut to the Environment's createEnv. * * @param {...any} args - environment constructor arguments. * @returns {Object} environment instance * * Use to test with specific Environment version: * let createEnv; * before(() => { * createEnv = stub(helper, 'createEnv').callsFake(Environment.creatEnv); * }); * after(() => { * createEnv.restore(); * }); */ createEnv(options: BaseEnvironmentOptions): Promise; /** * Creates a test environment. * * @param {Function} - environment constructor method. * @param {Object} - Options to be passed to the environment * const env = createTestEnv(require('yeoman-environment').createEnv); */ createTestEnv(environmentContructor?: CreateEnv, options?: BaseEnvironmentOptions): Promise; /** * Creates a TestAdapter using helpers default options. */ createTestAdapter(options?: TestAdapterOptions): TestAdapter; /** * Get RunContext type * @return {RunContext} */ getRunContextType(): typeof RunContext; /** * Run the provided Generator * @param GeneratorOrNamespace - Generator constructor or namespace */ run(GeneratorOrNamespace: string | GetGeneratorConstructor, settings?: RunContextSettings, environmentOptions?: BaseEnvironmentOptions): RunContext; /** * Prepare a run context * @param {String|Function} GeneratorOrNamespace - Generator constructor or namespace * @return {RunContext} */ create(GeneratorOrNamespace: string | GetGeneratorConstructor, settings?: RunContextSettings, environmentOptions?: BaseEnvironmentOptions): RunContext; /** * Prepare temporary dir without generator support. * Generator and environment will be undefined. */ prepareTemporaryDir(settings?: RunContextSettings): BasicRunContext; } declare const defaultHelpers: YeomanTest; export default defaultHelpers; export declare const createHelpers: (options: any) => YeomanTest;