/cta-expresswrapper

Primary LanguageJavaScriptOtherNOASSERTION

cta-expresswrapper

Build Status Coverage Status codecov

Web Application using Express (expressjs.com) Modules for Compass Test Automation, One of Libraries in CTA-OSS Framework

General Overview

Overview

In this module, cta-expresswrapper, we're implementing cta-tool using Express as web application.

Guidelines

We aim to give you brief guidelines here.

  1. Usage
  2. Structure
  3. Constructor
  4. Configuration
  5. Express.listen() via ExpressWrapper.start()

1. Usage

'use strict';

const ExpressWrapper = require('cta-expresswrapper');

const instance = new ExpressWrapper(dependencies, configuration);
instance.start();

We use ExpressWrapper.start() to start the Express.

back to top

2. Structure

In cta-expresswrapper, the ExpressWrapper class is extending Tool from cta-tool and is exported.

'use strict';

const Tool = require('cta-tool');

class ExpressWrapper extends Tool {
  ...
}

module.exports = ExpressWrapper;

back to top

3. Constructor

Because the ExpressWrapper class is extending Tool, its constructor has dependencies and configuration as parameters.

class ExpressWrapper extends Tool {
  constructor(dependencies, configuration) {
    ...
    super(dependencies, configuration);
    ...
  }
}

back to top

4. Configuration

ExpressWrapper uses configuration via constructor.

class ExpressWrapper extends Tool {
  constructor(dependencies, configuration) {
    ...
    super(dependencies, configuration);
    ...
  }
}

Because of Tool (cta-tool) extension, the configuration needs to have these fields.

  • name - define the tool name
  • singleton - indicate whether the tool is singleton
  • properties - provide properties

Port for Express to listen to

ExpressWrapper uses port (number) in properties. Here is an example:

const configuration = {
  name: 'my-express',
  module: 'cta-expresswrapper',
  properties: {
    port: 3000,
  },
};

back to top

5. Express.listen() via ExpressWrapper.start()

In ExpressWrapper class, it provides start() to use Express.listen(port).

const express = require('express');
const http = require('http');

class ExpressWrapper extends Tool {
  constructor(dependencies, configuration) {
    ...
    this.app = express();
    this.server = http.createServer(this.app);
    this.port = this.properties.port;
    ...
  }

  start() {
    ...
    this.server.listen(this.port);
    ...
  }
}

back to top


To Do


Considerations

  • Should we specify the version of Express in package.json because it's dependency?