Brick Modules for Compass Test Automation, One of Libraries in CTA-OSS Framework
This module provides the Brick class to extend. To implement a brick, you need Brick class in cta-brick to 'extends' and implement your own brick, see Usage. In the design, you probably have many bricks to process some works. Those bricks, you design, must 'extends' from Brick class in cta-brick. The Brick provides some useful methods to implement, see Structure.
We aim to give you brief guidelines here.
To create a brick for CTA-OSS Framework, we need to extend the class.
const Brick = require("cta-brick");
class SampleBrick extends Brick {
process(context) {
// process work here
}
}
module.exports = SampleBrick;
This example shows how to use Brick. We only implement the important method which is process().
Here is a structure of Brick Class.
class Brick {
constructor(cementHelper, configuration);
init(): Promise;
start(): void;
validate(context): Promise;
process(context): Promise;
health(data): void;
}
The Brick Class has five methods.
-
init() - to initialize the brick
-
start() - to start the brick
-
validate() - to perform validation
-
process() - to perform process
-
health() - to operate dependencies health check
To learn about Promise, click here.
In a constructor, the Brick uses dependencies injection to make the dependencies available within Brick. Those dependencies which are cementHelper and configuration are provided by cta-oss framework.
class SampleBrick extends Brick {
constructor(cementHelper, configuration) {
super(); // to bind the dependencies
}
}
module.exports = SampleBrick;
By calling super(), the cementHelper and configuration are bound and available within class context. They can be accesed in any method via this.cementHelper and this.configuration.
Here we're going to describe process in Brick.
In CTA-OSS, we can informally define two phases for Bricks.
-
In Initial Phase, Brick's init() and start() will be called to initialize, and then to start
-
In Process Phase, after Brick was started, it is ready for process. When there is incoming context, the Brick's validate() and process() will be called to validate, and then to process some works