yeoman-test

  • Version 8.3.0
  • Published
  • 82.4 kB
  • 7 dependencies
  • MIT license

Install

npm i yeoman-test
yarn add yeoman-test
pnpm add yeoman-test

Overview

Test utilities for Yeoman generators

Index

Variables

Functions

Classes

Type Aliases

Variables

variable context

const context: TestContext;

    variable defaultHelpers

    const defaultHelpers: YeomanTest;

      variable result

      const result: RunResult<BaseGenerator>;
      • Provides a proxy for last executed context result.

      Functions

      function createHelpers

      createHelpers: (options: any) => YeomanTest;

        Classes

        class RunContext

        class RunContext<GeneratorType extends BaseGenerator = BaseGenerator>
        extends RunContextBase<GeneratorType>
        implements Promise<RunResult<GeneratorType>> {}

          property [Symbol.toStringTag]

          readonly [Symbol.toStringTag]: string;

            method catch

            catch: <TResult = never>(
            onrejected?: (reason: any) => TResult | PromiseLike<TResult>
            ) => Promise<RunResult<GeneratorType> | TResult>;

              method finally

              finally: (
              onfinally?: (() => void) | undefined
              ) => Promise<RunResult<GeneratorType>>;

                method then

                then: <TResult1 = RunResult<GeneratorType>, TResult2 = never>(
                onfulfilled?: (
                value: RunResult<GeneratorType>
                ) => TResult1 | PromiseLike<TResult1>,
                onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>
                ) => Promise<TResult1 | TResult2>;

                  class RunContextBase

                  class RunContextBase<
                  GeneratorType extends BaseGenerator = DefaultGeneratorApi
                  > extends EventEmitter {}

                    constructor

                    constructor(
                    generatorType?: any,
                    settings?: RunContextSettings,
                    envOptions?: any,
                    helpers?: YeomanTest
                    );
                    • This class provide a run context object to façade the complexity involved in setting up a generator for testing

                      Parameter Generator

                      Namespace or generator constructor. If the later is provided, then namespace is assumed to be 'gen:test' in all cases

                      Parameter settings

                      {this}

                    property askedQuestions

                    readonly askedQuestions: AskedQuestions;

                      property completed

                      completed: boolean;

                        property editor

                        editor: MemFsEditor;

                          property env

                          env: IfAny<any, BaseEnvironment, any>;

                            property environmentPromise

                            protected environmentPromise?: PromiseRunResult<GeneratorType>;

                              property envOptions

                              readonly envOptions: any;

                                property generator

                                generator: BaseGenerator;

                                  property memFs

                                  memFs: Store<MemFsEditorFile>;

                                    property mockedGeneratorFactory

                                    mockedGeneratorFactory: MockedGeneratorFactory<IfAny<any, BaseGenerator, any>>;

                                      property mockedGenerators

                                      readonly mockedGenerators: Record<string, BaseGenerator>;

                                        property settings

                                        readonly settings: RunContextSettings;

                                          property spawnStub

                                          spawnStub?: any;

                                            property targetDirectory

                                            targetDirectory?: string;

                                              method assertNotBuild

                                              protected assertNotBuild: () => void;

                                                method build

                                                build: () => Promise<void>;
                                                • Build the generator and the environment. {RunContext|false} this

                                                method cd

                                                cd: (dirPath: string) => this;
                                                • Parameter dirPath

                                                  Directory path (relative to CWD). Prefer passing an absolute file path for predictable results run context instance

                                                  Deprecated

                                                  Change directory without deleting directory content.

                                                method cleanTestDirectory

                                                cleanTestDirectory: (force?: boolean) => void;
                                                • Clean the directory used for tests inside inDir/inTmpDir

                                                  Parameter force

                                                  force directory cleanup for not tmpdir

                                                method cleanup

                                                cleanup: () => void;
                                                • Clean the directory used for tests inside inDir/inTmpDir

                                                  Parameter force

                                                  force directory cleanup for not tmpdir

                                                method cleanupTemporaryDir

                                                cleanupTemporaryDir: () => void;
                                                • Clean the directory used for tests inside inDir/inTmpDir

                                                  Parameter force

                                                  force directory cleanup for not tmpdir

                                                method commitFiles

                                                commitFiles: () => this;
                                                • Commit mem-fs files.

                                                method doInDir

                                                doInDir: (cb: (folderPath: string) => void) => this;
                                                • Register an callback to prepare the destination folder.

                                                  Parameter cb

                                                  callback who'll receive the folder path as argument this - run context instance

                                                method inDir

                                                inDir: (dirPath: string, cb?: (folderPath: string) => void) => this;
                                                • Parameter dirPath

                                                  Directory path (relative to CWD). Prefer passing an absolute file path for predictable results

                                                  Parameter cb

                                                  callback who'll receive the folder path as argument run context instance

                                                  Deprecated

                                                  Clean the provided directory, then change directory into it

                                                method inTmpDir

                                                inTmpDir: (cb?: (folderPath: string) => void) => this;
                                                • Cleanup a temporary directory and change the CWD into it

                                                  This method is called automatically when creating a RunContext. Only use it if you need to use the callback.

                                                  Parameter cb

                                                  callback who'll receive the folder path as argument this - run context instance

                                                method on

                                                on: (eventName: string | symbol, listener: (...args: any[]) => void) => this;

                                                  method onBeforePrepare

                                                  onBeforePrepare: (callback: (this: this) => void | Promise<void>) => this;
                                                  • Execute callback prefore parepare

                                                    Parameter callback

                                                    Returns

                                                  method onEnvironment

                                                  onEnvironment: (
                                                  callback: (this: this, env: IfAny<any, BaseEnvironment, any>) => any
                                                  ) => this;
                                                  • Execute callback after environment is ready

                                                    Parameter callback

                                                    Returns

                                                  method onGenerator

                                                  onGenerator: (callback: (this: this, generator: GeneratorType) => any) => this;
                                                  • Execute callback after generator is ready

                                                    Parameter callback

                                                    Returns

                                                  method onTargetDirectory

                                                  onTargetDirectory: (
                                                  callback: (this: this, targetDirectory: string) => any
                                                  ) => this;
                                                  • Execute callback after targetDirectory is set

                                                    Parameter callback

                                                    Returns

                                                  method prepare

                                                  prepare: () => Promise<void>;

                                                    method restore

                                                    restore: () => this;
                                                    • Restore cwd to initial cwd. {this} run context instance

                                                    method run

                                                    run: () => PromiseRunResult<GeneratorType>;
                                                    • Run the generator on the environment and promises a RunResult instance. {PromiseRunResult} Promise a RunResult instance.

                                                    method toPromise

                                                    protected toPromise: () => PromiseRunResult<GeneratorType>;
                                                    • Return a promise representing the generator run process Promise resolved on end or rejected on error

                                                    method withAdapterOptions

                                                    withAdapterOptions: (options: Omit<TestAdapterOptions, 'mockedAnswers'>) => this;
                                                    • TestAdapter options.

                                                    method withAnswers

                                                    withAnswers: (
                                                    answers: PromptAnswers,
                                                    options?: Omit<DummyPromptOptions, 'mockedAnswers'>
                                                    ) => this;
                                                    • Mock answers for prompts

                                                      Parameter answers

                                                      Answers to the prompt questions

                                                      Parameter options

                                                      Options or callback. {this}

                                                    method withArguments

                                                    withArguments: (args: string | string[]) => this;
                                                    • Provide arguments to the run context

                                                      Parameter args

                                                      command line arguments as Array or space separated string

                                                    method withEnvironment

                                                    withEnvironment: (cb: any) => this;
                                                    • Create an environment

                                                      This method is called automatically when creating a RunContext. Only use it if you need to use the callback.

                                                      Parameter cb

                                                      callback who'll receive the folder path as argument {this} run context instance

                                                    method withFiles

                                                    withFiles: {
                                                    (files: Record<string, string | Record<string, unknown>>): this;
                                                    (
                                                    relativePath: string,
                                                    files: Record<string, string | Record<string, unknown>>
                                                    ): this;
                                                    };
                                                    • Add files to mem-fs. Files will be resolved relative to targetDir.

                                                      Files with Object content will be merged to existing content. To avoid merging, JSON.stringify the content.

                                                    method withGenerators

                                                    withGenerators: (dependencies: Dependency[]) => this;
                                                    • Provide dependent generators

                                                      Parameter dependencies

                                                      paths to the generators dependencies {this}

                                                      Example 1

                                                      var angular = new RunContext('../../app'); angular.withGenerators([ '../../common', '../../controller', '../../main', [helpers.createDummyGenerator(), 'testacular:app'] ]); angular.on('end', function () { // assert something });

                                                    method withKeepFsState

                                                    withKeepFsState: () => this;
                                                    • Don't reset mem-fs state cleared to aggregate snapshots from multiple runs.

                                                    method withLocalConfig

                                                    withLocalConfig: (localConfig: any) => this;
                                                    • Mock the local configuration with the provided config

                                                      Parameter localConfig

                                                      should look just like if called config.getAll()

                                                    method withLookups

                                                    withLookups: (lookups: LookupOptions | LookupOptions[]) => this;
                                                    • Run lookup on the environment.

                                                      Parameter lookups

                                                      lookup to run.

                                                    method withMockedGeneratorFactory

                                                    withMockedGeneratorFactory: (
                                                    mockedGeneratorFactory: MockedGeneratorFactory
                                                    ) => this;

                                                      method withMockedGenerators

                                                      withMockedGenerators: (namespaces: string[]) => this;
                                                      • Create mocked generators

                                                        Parameter namespaces

                                                        namespaces of mocked generators this

                                                        Example 1

                                                        var angular = helpers .create('../../app') .withMockedGenerators([ 'foo:app', 'foo:bar', ]) .run() .then(runResult => assert(runResult .mockedGenerators['foo:app'] .calledOnce));

                                                      method withOptions

                                                      withOptions: (
                                                      options: Partial<
                                                      Omit<
                                                      GetGeneratorOptions<GeneratorType>,
                                                      'env' | 'namespace' | 'resolved'
                                                      >
                                                      >
                                                      ) => this;
                                                      • Provide options to the run context

                                                        Parameter options

                                                        command line options (e.g. --opt-one=foo) {this}

                                                      method withPrompts

                                                      withPrompts: (
                                                      answers: PromptAnswers,
                                                      options?: Omit<DummyPromptOptions, 'mockedAnswers'>
                                                      ) => this;
                                                      • Parameter answers

                                                        Answers to the prompt questions

                                                        Parameter options

                                                        Options or callback.

                                                        Parameter

                                                        {Function} [options.callback] - Callback.

                                                        Parameter

                                                        {Boolean} [options.throwOnMissingAnswer] - Throw if a answer is missing. {this}

                                                        Deprecated

                                                        Mock the prompt with dummy answers

                                                      method withSpawnMock

                                                      withSpawnMock: (
                                                      options?:
                                                      | ((...args: any[]) => any)
                                                      | {
                                                      stub?: (...args: any[]) => any;
                                                      registerSinonDefaults?: boolean;
                                                      callback?: (stub: any) => void | Promise<void>;
                                                      }
                                                      ) => this;

                                                        method withYoRc

                                                        withYoRc: (content: string | Record<string, unknown>) => this;
                                                        • Add .yo-rc.json to mem-fs.

                                                          Parameter content

                                                          Returns

                                                        method withYoRcConfig

                                                        withYoRcConfig: (key: string, content: Record<string, unknown>) => this;
                                                        • Add a generator config to .yo-rc.json

                                                        class RunResult

                                                        class RunResult<GeneratorType extends BaseGenerator = BaseGenerator> {}
                                                        • This class provides utilities for testing generated content.

                                                        constructor

                                                        constructor(options: RunResultOptions<GeneratorType>);

                                                          property askedQuestions

                                                          readonly askedQuestions: AskedQuestions;

                                                            property cwd

                                                            cwd: string;

                                                              property env

                                                              env: any;

                                                                property fs

                                                                fs: MemFsEditor;

                                                                  property generator

                                                                  generator: BaseGenerator;

                                                                    property memFs

                                                                    memFs: Store<MemFsEditorFile>;

                                                                      property mockedGenerators

                                                                      mockedGenerators: any;

                                                                        property oldCwd

                                                                        oldCwd: string;

                                                                          property options

                                                                          options: RunResultOptions<GeneratorType>;

                                                                            property spawnStub

                                                                            spawnStub?: any;

                                                                              method assertEqualsFileContent

                                                                              assertEqualsFileContent: {
                                                                              (file: string, expectedContent: string): void;
                                                                              (pairs: [string, string][]): void;
                                                                              };
                                                                              • Assert that a file's content is the same as the given string

                                                                                Parameter file

                                                                                path to a file

                                                                                Parameter expectedContent

                                                                                the expected content of the file

                                                                                Parameter pairs

                                                                                an array of arrays, where each subarray is a [String, String] pair

                                                                                Example 1

                                                                                result.assertEqualsFileContent( 'data.js', 'const greeting = "Hello";\nexport default { greeting }' );

                                                                                Assert that each file in an array of file-string pairs equals its corresponding string

                                                                                Example 2

                                                                                result.assertEqualsFileContent([ ['data.js', 'const greeting = "Hello";\nexport default { greeting }'], ['user.js', 'export default {\n name: 'Coleman',\n age: 0\n}'] ]);

                                                                              method assertFile

                                                                              assertFile: (path: string | string[]) => void;
                                                                              • Assert that a file exists

                                                                                Parameter path

                                                                                path to a file

                                                                                Parameter paths

                                                                                an array of paths to files

                                                                                Example 1

                                                                                result.assertFile('templates/user.hbs');

                                                                                Assert that each files in the array exists

                                                                                Example 2

                                                                                result.assertFile(['templates/user.hbs', 'templates/user/edit.hbs']);

                                                                              method assertFileContent

                                                                              assertFileContent: {
                                                                              (file: string, reg: string | RegExp): void;
                                                                              (pairs: [string, string | RegExp][]): void;
                                                                              };
                                                                              • Assert that a file's content matches a regex or string

                                                                                Parameter file

                                                                                path to a file

                                                                                Parameter reg

                                                                                regex / string that will be used to search the file

                                                                                Parameter pairs

                                                                                an array of arrays, where each subarray is a [String, RegExp] pair

                                                                                Example 1

                                                                                result.assertFileContent('models/user.js', /App.User = DS.Model.extend/); result.assertFileContent('models/user.js', 'App.User = DS.Model.extend');

                                                                                Assert that each file in an array of file-regex pairs matches its corresponding regex

                                                                                Example 2

                                                                                var arg = [ [ 'models/user.js', /App.User = DS.Model.extend/ ], [ 'controllers/user.js', /App.UserController = Ember.ObjectController.extend/ ] ] result.assertFileContent(arg);

                                                                              method assertJsonFileContent

                                                                              assertJsonFileContent: (filename: string, content: Record<string, any>) => void;
                                                                              • Assert a JSON file contains the provided keys

                                                                                Parameter filename

                                                                                Parameter content

                                                                                An object of key/values the file should contains

                                                                              method assertNoFile

                                                                              assertNoFile: (files: string | string[]) => void;
                                                                              • Assert that a file doesn't exist

                                                                                Parameter file

                                                                                path to a file

                                                                                Parameter pairs

                                                                                an array of paths to files

                                                                                Example 1

                                                                                result.assertNoFile('templates/user.hbs');

                                                                                Assert that each of an array of files doesn't exist

                                                                                Example 2

                                                                                result.assertNoFile(['templates/user.hbs', 'templates/user/edit.hbs']);

                                                                              method assertNoFileContent

                                                                              assertNoFileContent: {
                                                                              (file: string, reg: RegExp | string): void;
                                                                              (pairs: [string, string | RegExp][]): void;
                                                                              };
                                                                              • Assert that a file's content does not match a regex / string

                                                                                Parameter file

                                                                                path to a file

                                                                                Parameter reg

                                                                                regex / string that will be used to search the file

                                                                                Parameter pairs

                                                                                an array of arrays, where each subarray is a [String, RegExp] pair var arg = [ [ 'models/user.js', /App.User \ DS.Model.extend/ ], [ 'controllers/user.js', /App.UserController = Ember.ObjectController.extend/ ] ] result.assertNoFileContent(arg);

                                                                                Example 1

                                                                                result.assertNoFileContent('models/user.js', /App.User = DS.Model.extend/); result.assertNoFileContent('models/user.js', 'App.User = DS.Model.extend');

                                                                                Assert that each file in an array of file-regex pairs does not match its corresponding regex

                                                                              method assertNoJsonFileContent

                                                                              assertNoJsonFileContent: (
                                                                              filename: string,
                                                                              content: Record<string, any>
                                                                              ) => void;
                                                                              • Assert a JSON file does not contain the provided keys

                                                                                Parameter filename

                                                                                Parameter content

                                                                                An object of key/values the file should not contain

                                                                              method assertNoObjectContent

                                                                              assertNoObjectContent: (
                                                                              object: Record<string, unknown>,
                                                                              content: Record<string, any>
                                                                              ) => void;
                                                                              • Assert an object does not contain the provided keys

                                                                                Parameter obj

                                                                                Object that should not match the given pattern

                                                                                Parameter content

                                                                                An object of key/values the object should not contain

                                                                              method assertObjectContent

                                                                              assertObjectContent: (
                                                                              object: Record<string, unknown>,
                                                                              content: Record<string, any>
                                                                              ) => void;
                                                                              • Assert an object contains the provided keys

                                                                                Parameter obj

                                                                                Object that should match the given pattern

                                                                                Parameter content

                                                                                An object of key/values the object should contains

                                                                              method assertTextEqual

                                                                              assertTextEqual: (value: string, expected: string) => void;
                                                                              • Assert that two strings are equal after standardization of newlines

                                                                                Parameter value

                                                                                a string

                                                                                Parameter expected

                                                                                the expected value of the string

                                                                                Example 1

                                                                                result.assertTextEqual('I have a yellow cat', 'I have a yellow cat');

                                                                              method cleanup

                                                                              cleanup: () => this;
                                                                              • Deletes the test directory recursively.

                                                                              method create

                                                                              create: <GeneratorType extends BaseGenerator = IfAny<any, BaseGenerator, any>>(
                                                                              GeneratorOrNamespace: string | GetGeneratorConstructor<GeneratorType>,
                                                                              settings?: RunContextSettings,
                                                                              envOptions?: BaseEnvironmentOptions
                                                                              ) => import('./run-context.js').default<GeneratorType>;
                                                                              • Create another RunContext reusing the settings. See helpers.create api

                                                                              method dumpFilenames

                                                                              dumpFilenames: () => this;
                                                                              • Dumps the name of each file to the console.

                                                                              method dumpFiles

                                                                              dumpFiles: (...files: string[]) => this;
                                                                              • Either dumps the contents of the specified files or the name and the contents of each file to the console.

                                                                              method getSnapshot

                                                                              getSnapshot: (
                                                                              filter?: any
                                                                              ) => Record<string, { contents: string; stateCleared: string }>;
                                                                              • Return an object with fs changes.

                                                                                Parameter filter

                                                                                parameter forwarded to mem-fs-editor#dump

                                                                              method getSpawnArgsUsingDefaultImplementation

                                                                              getSpawnArgsUsingDefaultImplementation: () => any;

                                                                                method getStateSnapshot

                                                                                getStateSnapshot: (
                                                                                filter?: any
                                                                                ) => Record<string, { stateCleared?: string; state?: string }>;
                                                                                • Return an object with filenames with state.

                                                                                  Parameter filter

                                                                                  parameter forwarded to mem-fs-editor#dump

                                                                                  Returns

                                                                                  {Object}

                                                                                method restore

                                                                                restore: () => this;
                                                                                • Reverts to old cwd.

                                                                                  Returns

                                                                                  this

                                                                                class TestAdapter

                                                                                class TestAdapter extends BaseTestAdapter {}

                                                                                  constructor

                                                                                  constructor(options?: TestAdapterOptions);

                                                                                    class YeomanTest

                                                                                    class YeomanTest {}
                                                                                    • Collection of unit test helpers. (mostly related to Mocha syntax) YeomanTest

                                                                                    property adapterOptions

                                                                                    adapterOptions?: Omit<TestAdapterOptions, 'mockedAnswers'>;

                                                                                      property environmentOptions

                                                                                      environmentOptions?: BaseEnvironmentOptions;

                                                                                        property generatorOptions

                                                                                        generatorOptions?: BaseGeneratorOptions;

                                                                                          property settings

                                                                                          settings?: RunContextSettings;

                                                                                            method create

                                                                                            create: <GeneratorType extends BaseGenerator = IfAny<any, BaseGenerator, any>>(
                                                                                            GeneratorOrNamespace: string | GetGeneratorConstructor<GeneratorType>,
                                                                                            settings?: RunContextSettings,
                                                                                            envOptions?: BaseEnvironmentOptions
                                                                                            ) => RunContext<GeneratorType>;
                                                                                            • Prepare a run context

                                                                                              Parameter GeneratorOrNamespace

                                                                                              Generator constructor or namespace {RunContext}

                                                                                            method createDummyGenerator

                                                                                            createDummyGenerator: <
                                                                                            GenParameter extends BaseGenerator = IfAny<any, BaseGenerator, any>
                                                                                            >(
                                                                                            Generator?: GetGeneratorConstructor<GenParameter>,
                                                                                            contents?: Record<string, (...args: any[]) => void>
                                                                                            ) => new (...args: any[]) => GenParameter;
                                                                                            • Create a simple, dummy generator

                                                                                            method createEnv

                                                                                            createEnv: (options: BaseEnvironmentOptions) => Promise<DefaultEnvironmentApi>;
                                                                                            • Shortcut to the Environment's createEnv.

                                                                                              Parameter 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(); });

                                                                                            method createGenerator

                                                                                            createGenerator: <
                                                                                            GeneratorType extends BaseGenerator = IfAny<any, BaseGenerator, any>
                                                                                            >(
                                                                                            name: string | GetGeneratorConstructor<GeneratorType>,
                                                                                            options?: {
                                                                                            dependencies?: Dependency[];
                                                                                            localConfigOnly?: boolean;
                                                                                            } & InstantiateOptions<GeneratorType>
                                                                                            ) => Promise<GeneratorType>;
                                                                                            • Create a generator, using the given dependencies and controller arguments Dependecies can be path (autodiscovery) or an array [{generator}, {name}]

                                                                                              Parameter name

                                                                                              the name of the generator

                                                                                              Parameter dependencies

                                                                                              paths to the generators dependencies

                                                                                              Parameter args

                                                                                              arguments to the generator; if String, will be split on spaces to create an Array

                                                                                              Parameter options

                                                                                              configuration for the generator

                                                                                              Parameter localConfigOnly

                                                                                              passes localConfigOnly to the generators

                                                                                              Example 1

                                                                                              var deps = ['../../app', '../../common', '../../controller', '../../main', [createDummyGenerator(), 'testacular:app'] ]; var angular = createGenerator('angular:app', deps);

                                                                                            method createMockedGenerator

                                                                                            createMockedGenerator: (
                                                                                            GeneratorClass?: any
                                                                                            ) => SinonSpiedInstance<IfAny<any, BaseGenerator, any>>;
                                                                                            • Create a mocked generator

                                                                                            method createTestAdapter

                                                                                            createTestAdapter: (options?: TestAdapterOptions) => TestAdapter;
                                                                                            • Creates a TestAdapter using helpers default options.

                                                                                            method createTestEnv

                                                                                            createTestEnv: (
                                                                                            envContructor?: CreateEnv,
                                                                                            options?: BaseEnvironmentOptions
                                                                                            ) => Promise<BaseEnvironment>;
                                                                                            • Creates a test environment.

                                                                                              Parameter

                                                                                              {Function} - environment constructor method.

                                                                                              Parameter

                                                                                              {Object} - Options to be passed to the environment const env = createTestEnv(require('yeoman-environment').createEnv);

                                                                                            method getRunContextType

                                                                                            getRunContextType: () => typeof RunContext;
                                                                                            • Get RunContext type {RunContext}

                                                                                            method mockLocalConfig

                                                                                            mockLocalConfig: (generator: BaseGenerator, localConfig: any) => void;
                                                                                            • Parameter generator

                                                                                              a Yeoman generator

                                                                                              Parameter localConfig

                                                                                              localConfig - should look just like if called config.getAll()

                                                                                              Deprecated

                                                                                              Provide mocked values to the config

                                                                                            method mockPrompt

                                                                                            mockPrompt: (
                                                                                            envOrGenerator: BaseGenerator | DefaultEnvironmentApi,
                                                                                            mockedAnswers?: PromptAnswers,
                                                                                            options?: DummyPromptOptions
                                                                                            ) => void;
                                                                                            • Parameter generator

                                                                                              a Yeoman generator or environment

                                                                                              Parameter answers

                                                                                              an object where keys are the generators prompt names and values are the answers to the prompt questions

                                                                                              Parameter options

                                                                                              Options or callback

                                                                                              Example 1

                                                                                              mockPrompt(angular, {'bootstrap': 'Y', 'compassBoostrap': 'Y'});

                                                                                              Deprecated

                                                                                              Answer prompt questions for the passed-in generator

                                                                                            method prepareTemporaryDir

                                                                                            prepareTemporaryDir: (
                                                                                            settings?: RunContextSettings
                                                                                            ) => BasicRunContext<BaseGenerator>;
                                                                                            • Prepare temporary dir without generator support. Generator and environment will be undefined.

                                                                                            method restorePrompt

                                                                                            restorePrompt: (envOrGenerator: BaseGenerator | DefaultEnvironmentApi) => void;
                                                                                            • Parameter generator

                                                                                              or environment

                                                                                              Deprecated

                                                                                              Restore defaults prompts on a generator.

                                                                                            method run

                                                                                            run: <GeneratorType extends BaseGenerator = IfAny<any, BaseGenerator, any>>(
                                                                                            GeneratorOrNamespace: string | GetGeneratorConstructor<GeneratorType>,
                                                                                            settings?: RunContextSettings,
                                                                                            envOptions?: BaseEnvironmentOptions
                                                                                            ) => RunContext<GeneratorType>;
                                                                                            • Run the provided Generator

                                                                                              Parameter GeneratorOrNamespace

                                                                                              Generator constructor or namespace

                                                                                            method setUpTestDirectory

                                                                                            setUpTestDirectory: (dir: string) => () => void;
                                                                                            • Parameter dir

                                                                                              path to the test directory

                                                                                              Returns

                                                                                              mocha callback

                                                                                              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.

                                                                                            method testDirectory

                                                                                            testDirectory: (dir: string, cb?: (error?: any) => unknown) => unknown;
                                                                                            • Parameter dir

                                                                                              path to the test directory

                                                                                              Parameter cb

                                                                                              callback executed after setting working directory to dir

                                                                                              Example 1

                                                                                              testDirectory(path.join(__dirname, './temp'), function () { fs.writeFileSync('testfile', 'Roses are red.'); });

                                                                                              Deprecated

                                                                                              Clean-up the test directory and cd into it. Call given callback after entering the test directory.

                                                                                            Type Aliases

                                                                                            type Dependency

                                                                                            type Dependency = string | Parameters<DefaultEnvironmentApi['register']>;
                                                                                            • Dependencies can be path (autodiscovery) or an array [, ]

                                                                                            type RunContextSettings

                                                                                            type RunContextSettings = {
                                                                                            /**
                                                                                            * Automatically run this generator in a tmp dir
                                                                                            * @default true
                                                                                            */
                                                                                            tmpdir?: boolean;
                                                                                            cwd?: string;
                                                                                            oldCwd?: string;
                                                                                            forwardCwd?: boolean;
                                                                                            autoCleanup?: boolean;
                                                                                            memFs?: Store<MemFsEditorFile>;
                                                                                            /**
                                                                                            * File path to the generator (only used if Generator is a constructor)
                                                                                            */
                                                                                            resolved?: string;
                                                                                            /**
                                                                                            * Namespace (only used if Generator is a constructor)
                                                                                            * @default 'gen:test'
                                                                                            */
                                                                                            namespace?: string;
                                                                                            };
                                                                                            • Provides settings for creating a RunContext.

                                                                                            type RunResultOptions

                                                                                            type RunResultOptions<GeneratorType extends BaseGenerator> = {
                                                                                            generator: GeneratorType;
                                                                                            /**
                                                                                            * The environment of the generator.
                                                                                            */
                                                                                            env: DefaultEnvironmentApi;
                                                                                            envOptions: BaseEnvironmentOptions;
                                                                                            /**
                                                                                            * The working directory after running the generator.
                                                                                            */
                                                                                            cwd: string;
                                                                                            /**
                                                                                            * The working directory before on running the generator.
                                                                                            */
                                                                                            oldCwd: string;
                                                                                            /**
                                                                                            * The file-system of the generator.
                                                                                            */
                                                                                            memFs: Store<MemFsEditorFile>;
                                                                                            fs?: MemFsEditor;
                                                                                            /**
                                                                                            * The mocked generators of the context.
                                                                                            */
                                                                                            mockedGenerators: Record<string, BaseGenerator>;
                                                                                            spawnStub?: any;
                                                                                            settings: RunContextSettings;
                                                                                            helpers: YeomanTest;
                                                                                            askedQuestions: AskedQuestions;
                                                                                            };
                                                                                            • Provides options for RunResults.

                                                                                            Package Files (6)

                                                                                            Dependencies (7)

                                                                                            Dev Dependencies (17)

                                                                                            Peer Dependencies (4)

                                                                                            Badge

                                                                                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/yeoman-test.

                                                                                            • Markdown
                                                                                              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/yeoman-test)
                                                                                            • HTML
                                                                                              <a href="https://www.jsdocs.io/package/yeoman-test"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>