1.0.3 • Published 3 years ago

protractor-backend-mock-plugin v1.0.3

Weekly downloads
37
License
Apache-2.0
Repository
github
Last release
3 years ago

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 | |
+--------+   | +---------+             +------+ +------+ |
             +-------------------------------------------+