/cta-brick

Primary LanguageJavaScriptOtherNOASSERTION

cta-brick

Build Status Coverage Status codecov

Brick Modules for Compass Test Automation, One of Libraries in CTA-OSS Framework

General Overview

Overview

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.

Guidelines

We aim to give you brief guidelines here.

  1. Brick Class Usage
  2. Brick Class Structure
  3. Brick Class Constructor
  4. Process in Brick

1. Brick Class Usage

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().

back to top

2. Brick Class Structure

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.

back to top

3. Brick Class Constructor

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.

back to top

4. Process in Brick

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

back to top


To Do