Private
constructorShould not be called by hand. Use the fromDir and fromProject static methods instead.
Private
stateDefines a number of new scenarios, using the base scenario as a template.
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.
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:
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.A callback for setting up test cases for each scenario.
Private
iterateProduces 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.
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.
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.
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.
Static
fromInstantiates 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.
path to a test codebase on the filesystem to use for base scenario.
see fromDir.
a new Scenarios
instance.
Static
fromInstantiates 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.
a callback that should return a new Project instance. This callback is not executed at this point, it is only executed during forEachScenario.
a new Senarios
instance.
Generated using TypeDoc
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 forScenario
.Scenarios
is used to: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.
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.
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:
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: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.