pinguet62 / protractor-backend-mock-plugin

Protractor plugin to mock backend calls, using Express.js & Nock

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Protractor backend mock plugin

Maintained

GitHub Actions

Protractor plugin used to mock backend calls.

Usage

  1. Add NPM dependency to your package.json:

    npm install --save-dev protractor-backend-mock-plugin
  2. Add & Configure Protractor plugin:

    // protractor.conf.js
    exports.config = {
        plugins: [
            {
                package: 'protractor-backend-mock-plugin',
                // config
                backend: [8080, 'localhost'],
                fake: [9999, 'localhost']
            }
        ]
    }
  3. Use Nock to mock results from fake server:

    npm install --save-dev nock
    import * as nock from 'nock';
    beforeEach(() => {
      nock('http://localhost:9999').get(`/user/me`).reply(200, {id: 42, name: 'John Doe'})
    });

How it works?

An Express.js server is started locally, to intercept webapp calls. In order to intercept and mock calls (using nock), request must be emitted inside NodeJS application. So all request are redirected to another URL, defined by fake section.

             +-------------------------------------------+
             |               NodeJS                      |
+--------+   | +---------+             +------+ +------+ |
| Webapp + --> | Backend + --> proxy ->| Nock | | Fake | |
+--------+   | +---------+             +------+ +------+ |
             +-------------------------------------------+

About

Protractor plugin to mock backend calls, using Express.js & Nock

License:Apache License 2.0


Languages

Language:TypeScript 100.0%