Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pinguet62/protractor-backend-mock-plugin
Protractor plugin to mock backend calls, using Express.js & Nock
https://github.com/pinguet62/protractor-backend-mock-plugin
angular mock protractor
Last synced: about 2 months ago
JSON representation
Protractor plugin to mock backend calls, using Express.js & Nock
- Host: GitHub
- URL: https://github.com/pinguet62/protractor-backend-mock-plugin
- Owner: pinguet62
- License: apache-2.0
- Created: 2018-06-12T08:16:21.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-10T16:36:51.000Z (about 2 years ago)
- Last Synced: 2024-10-19T01:17:25.043Z (2 months ago)
- Topics: angular, mock, protractor
- Language: TypeScript
- Size: 396 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Protractor _backend mock_ plugin
[![Maintained](https://img.shields.io/badge/maintained%3F-yes-brightgreen.svg?style=flat)](https://github.com/pinguet62)
[![GitHub Actions](https://github.com/pinguet62/protractor-backend-mock-plugin/workflows/CI/badge.svg?branch=master)](https://github.com/pinguet62/protractor-backend-mock-plugin/actions?query=workflow%3ACI+branch%3Amaster)
Protractor plugin used to mock backend calls.
## Usage
1. Add NPM dependency to your `package.json`:
```bash
npm install --save-dev protractor-backend-mock-plugin
```2. [Add & Configure Protractor plugin](https://github.com/angular/protractor/blob/master/docs/plugins.md#using-plugins):
```javascript
// protractor.conf.js
exports.config = {
plugins: [
{
package: 'protractor-backend-mock-plugin',
// config
backend: [8080, 'localhost'],
fake: [9999, 'localhost']
}
]
}
```3. Use [Nock](https://github.com/node-nock/nock) to mock results from `fake` server:
```bash
npm install --save-dev nock
```
```javascript
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](http://expressjs.com) 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.```txt
+-------------------------------------------+
| NodeJS |
+--------+ | +---------+ +------+ +------+ |
| Webapp + --> | Backend + --> proxy ->| Nock | | Fake | |
+--------+ | +---------+ +------+ +------+ |
+-------------------------------------------+
```