The universe module manages a namespaced object which is copied from the "universe" scope to the feature scope for each new feature, and is copied from the feature scope to the scenario scope for each new scenario. Most of the steps and service make use of the Universe for their internal state. So for example values that are set in a "universe" context persist in all steps unless they are masked by value set in a "feature" or "scenario" context. Values that are set in a "scenario" context are not persisted into other scenarios.
The universe module is comparable to the Cucumber World object, but it's entirely independent. The cukelib
module uses the _cukelib
namespace, so for example all of it's active services are in the universe's _cukelib._services
object. You may directly use GetSet steps and support for general access to the _cukelib
universe namespace and associated steps. Alternatively you can define and use your own namespaces. Although.
If you're ever confused about the state of the Universe you can insert diagnostic steps into your feature files to inspect all or part of the universe/feature/scenario state.
Use GetSet steps and support for general access to the _cukelib
universe namespace and associated steps.
Note. The universe should be initialized before any any hooks or steps that use the cukelib
facilities.
You mostly don't need to worry about this because this is generally done automatically by the service's initialize
functions, and they will complain if it isn't initialized.
Typical usage:
const { get, set } = require('cukelib').universe..namespaceFactory(`_cukelib`);
This example exposes get
and set
for the _cukelib
namespace.
The complete list of namespaceFactory
functions are:
This returns the current execution context. Essentially it will be 'universe' within a BeforeFeatures
hook, 'feature' within a BeforeFeature
hook, and scenario
within Before/After
hooks and step functions. (In general the context is not well defined in AfterFeature
or AfterFeatures
hooks.)
The following operate in on the current scenario's copy of the namespace object in a "scenario" context. They operate on the "feature" or "universe" copy of the object when in they are used in the respective "feature" or "universe" context.
Essentially a wrapper around lodash get as _.get(<scenario object>, path)
Essentially a wrapper around lodash set as _.set(<scenario object>, path, value)
Essentially a wrapper around lodash has as _.has(<scenario object>, path)
Essentially a wrapper around lodash unset as _.unset(<scenario object>, path)
Like get
but reaches into the containing "feature" context object.
Like get
but reaches into the containing "universe" context object.
This initializes the universe namespace and copies initObject
onto the universe context object.
Wrapper for node util.inspect
. If arg1
is a string the context object at that path will be inspected, Otherwise the whole object will be inspected. If the second argument is supplied then that will be passed to util.inspect
as an options argument.
const { universe } = require('cukelib');
... or standalone ...
const universe = require('cukelib/lib/universe');