Class Scenarios

This is your entry point to this library. Do not use the new Scenarios() constructor, instead use its static methods fromDir and fromProject.

Scenarios is a separate class and not a plural for Scenario.

Scenarios is used to:

  1. Capture a base scenario by calling fromDir or fromProject.

    At this point, the base scenario is represented by a CallbackCreateProject — a callback that, when invoked, will create and return a Project instance representing a codebase in memory.

    fromDir captures a codebase into memory from disk.

    fromProject captures a codebase from a Project instance. You can represent a codebase with a JSON-like structure and feed it into Project.constructor to create a Project instance.

  2. Create a matrix of test cases by by calling expand. expand acccepts a record of key-value pairs where keys are names of scenarios and values are CallbackMutateProject callbacks.

    The callbacks are not executed just yet, so no Project or Scenario instances are created at this point.

  3. If you keep the result of expand in a separate module, you can import that module into multiple test files. In each of those files, you can:

    • call skip to remove a scenario from the matrix;
    • call only to select a single scenario from the matrix;
    • call map to append a new CallbackMutateProject callback to all sceanarios in the matrix.
  4. Finally, you call forEachScenario. It does the following:

    • for each scenario defined in the matrix, it creates a new Scenario instance;

    • for each Scenario instance, forEachScenario executes the callback that you pass into it;

    • inside the callback, you receive the Scenario instance as an argument and use it to define test cases with a test suite of your choice (QUnit, Mocha, Jest, etc).

    • at certain point inside the callback (typically, a beforeEach hook of your test suite), you call Scenario.prepare, which in turn will:

  5. Now, if you run a file that does scenarios.forEachScenario with your test suite, it will run the tests defined in the callback passed to forEachScenario for each scenario in the matrix.

Hierarchy

  • Scenarios

Constructors

Properties

state: State

Methods

  • Defines a number of new scenarios, using the base scenario as a template.

    Parameters

    • variants: Record<string, CallbackMutateProject>

      a key-value hash representing derived scenarios: the key is the name of a new scenario while the value is a CallbackMutateProject — a callback used to modify a test codebase to produce a unique scenario.

    Returns Scenarios

    a new derived Scenarios instance containing multiple named CallbackMutateProject and a reference to the base scenario (the one that this method was invoked on).

    Note: this method does not create Scenario instances. Those instances will only be created during Senarios.forEachScenario.

  • This method is a step that makes Scenarios do actual work. It has two purposes:

    1. It iterates over all defined scenarios (variants). For each scenario, it instantiates a Scenario instance and runs Scenario.prepare on it.
    2. It lets you define test cases for each scenario, using a test suite of your choice. You do it in a callback that you pass to forEachScenario as an argument. Typically, in a beforeEach hook of your test suite, you would run Scenario.prepare to emit the correpsonding project to the filesystem and apply all CallbackMutateProject to it.

    Parameters

    • callbackDefineTests: CallbackDefineTests

      A callback for setting up test cases for each scenario.

    Returns void

  • Produces a new Scenarios instance by deriving new scenarios (aka variants) from each of the previously defined ones.

    If the Scenarios instance only contains a base scenario, then adds one derived scenario on top of it. The name of the derived scenario will be the same as the base one.

    Parameters

    • name: string

      The name of the new scenario. It will be used to identify the new scenario variation.

      The name of the new scenario will be composed of the original name and the new name in the
      form of: <existing>-<new>.

      When applied to a `Scenarios` instance that only has a base scenario defined, then the new
      name will be used and the original name will be omitted.
    • callbackMutateProject: CallbackMutateProject

      a callback that will be applied to each scenario. It will be run against a test codebase that will be emitted for this scenario during forEachScenario.

      Note that the callback will not replace existing <a href="../types/CallbackMutateProject.html" class="tsd-kind-type-alias">CallbackMutateProject</a> callbacks,
      but rather append to them.

    Returns Scenarios

    A new Scenarios instance created based on the instanced the method was invoked on. The new instance will have the new CallbackMutateProject callback appended to all scenarios.

  • Parameters

    • variantName: string

      name of scenario to keep. Note: names of derived scenarios are prepended with name name of the base scenario: -.

    Returns Scenarios

    a new Scenarios instance with the given scenario only. Also keeps the base scenario.

  • Instantiates a new Scenarios instance, referencing a path to a test codebase on the filesystem to use as a base scenario.

    Delegates to Project.fromDir. Note: fromDir is not executed at this point. The path is stored as a callback closure which is only executed during forEachScenario to produce a Project, which is then written to disk.

    Parameters

    • appPath: string

      path to a test codebase on the filesystem to use for base scenario.

    • as: "lib" | "app" = 'app'

      see fromDir.

    Returns Scenarios

    a new Scenarios instance.

  • Instantiates a new Scenarios instance using a given Project instance.

    Use this method if you want to define a test codebase in the code of your test file rather than on a filesystem. See Project for more info.

    Parameters

    Returns Scenarios

    a new Senarios instance.

Generated using TypeDoc