1.0.3 • Published 5 years ago
protractor-backend-mock-plugin v1.0.3
Protractor backend mock plugin
Protractor plugin used to mock backend calls.
Usage
Add NPM dependency to your
package.json:npm install --save-dev protractor-backend-mock-pluginAdd & Configure Protractor plugin:
// protractor.conf.js exports.config = { plugins: [ { package: 'protractor-backend-mock-plugin', // config backend: [8080, 'localhost'], fake: [9999, 'localhost'] } ] }Use Nock to mock results from
fakeserver:npm install --save-dev nockimport * 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 | |
+--------+ | +---------+ +------+ +------+ |
+-------------------------------------------+