Git Product home page Git Product logo

hypergard's Introduction

HyperGard

Build Status

Options

applyMiddlewareStack

Allows you to pass an array of middleware function to wrap around each fetch.

Each middleware function should:

  • Have a method signature with arguments url, options, and next
  • Return the remaining stack return next(url, options) so the promise chain isn't broken

Example of Middleware for accessing calls before fetch. (Replaces beforeFetch and uniqueFetchHeaders functionality)

function setCustomHeader(url, options, next) {
  var newOptions = Object.assign({}, options, {
    headers: {
      'X-MoneyTrace': 'hey nowwwww',
    }
  });

  // Call next piece of middleware
  return next(url, newOptions);
}

Example of Middleware for accessing calls after fetch (Replaces afterFetchSuccess and afterFetchFailure functionality)

function loggerMiddleware(url, options, next) {
  // Call next piece of middleware
  var promiseChain = next(url, options);

  // Log any 401
  promiseChain.catch(function(error) {
      if (error.status === '401') {
        mockLogger.log('Unauthorized', {error: error});
      }
    })

  // Return un-caught promise chain
  return promiseChain;
}

Example of Applying middleware stack

Middleware will be called based on order of array.

hyperGard.applyMiddlewareStack([
  setCustomHeader,
  loggerMiddleware,
]);

Running Tests

Install Dependencies

$ npm run setup

Running tests to manually validate a patchset

$ npm test

Running tests during development

$ gulp test

That gulp test command will load up Chrome. Click the "Debug" button and then open the JavaScript Console to see the test results. You can also use console methods to be able to debug your tests.

Note that if you make a code change, you cannot simply reload http://localhost:8080/debug.html in Chrome. You have to stop the gulp test process with Control+C and then rerun the command (there's probably a better way to handle that, but it does the job for now).

hypergard's People

Contributors

ctreatma avatar johnriv avatar kristakhare avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.