bivrost-delay-adapter

3.2.2 • Public • Published

Bivrost delay adapter

Bivrost adapter enchantment to add request/respone delays for UI tests

yarn add bivrost-delay-adapter

Usage

import DataSource from 'bivrost/data/source';
import axiosAdapter from 'bivrost-axios-adapter';
import delayAdapter from 'bivrost-delay-adapter';
 
const delayedAxios = delayAdapter(axiosAdapter(), {
  request: 1000, // add 1sec delay before request
  response: 1000 // add 1sec delay after response
  error: 1000 // add 1sec delay after response with error
});
 
const api = bivrostApi({
  host: 'localhost',
  adapter: delayedAxios()
});
 
class UsersDataSource extends DataSource {
  static api = {
    loadAll: api('GET /users')
  }
 
  loadUsers(filters) {
    return this.invoke('loadAll', filters);
  }
}
 
const usersDataSource = new UsersDataSource();
 
// Will load users with 1sec delay before request and 1sec delay after response
usersDataSource.loadUsers().then(() => {
  console.log('done');
});

Bivrost allows to organize a simple interface to asyncronous APIs.

Other adapters

Dependents (0)

Package Sidebar

Install

npm i bivrost-delay-adapter

Weekly Downloads

2

Version

3.2.2

License

ISC

Unpacked Size

4.08 kB

Total Files

5

Last publish

Collaborators

  • tuchk4