Coder Social home page Coder Social logo

mocking-server's Introduction

Running the server

{MockingServer} = require 'mocking-server'

server = new MockingServer
server.httpsListen {
  key: "#{__dirname}/ssl/foo.com.key"
  cert: "#{__dirname}/ssl/foo.com.cert"
  port: 12001
  name: "foo"
}, (e) ->

You can httpsListen multiple (key, cert, port) triples at once.

API

Required header:
  X-Mocking-Server: API

/mock
  req: {...}
  res: {}

/clear-expectations
  req: {}
  res: {
    unmet_expectations: []
    unexpected_requests: []
    message: "..."
  }

/get-last-request-matching
  req: {expectation:{...}}
  res: {} or {
    request: {
      method: "..."
      url: "/...?..."
      headers: {...}
      text: "..."
    }
  }

Properties

method
url           # If the hostname is specified, it must match exactly
              # If the (pathname + querystring) is specified, it must match exactly
req_body      # Exact match
req_headers   # Exact match apart from ignoring Content-Length

code          # default: 200
res_headers   # Content-Length will always be added
res_body      # default: empty string

UIAutomation integration example

// in your helper.js
#import "node_modules/mocking-server/uiautomation/mocking-client.js"
mocking_server.SERVER_URL = "https://mocking-server.theshopkeep.com";
mocking_server.EXTRA_CURL_FLAGS = ['--insecure', '-x', '127.0.0.1:8888'];

// in your test abstraction, after the test runs
assert_then_clear_http_expectations({
  error: function(e) {
    UIALogger.logFail(e.message);
    // handle the failure in your framework-specific way
  }
})

// in some test
mock_post({
  url: "skynet.mil/activate",
  req_headers: {
    'Content-Type': 'application/json'
  },
  req_body: "{}"
});
target.frontMostApp().mainWindow().buttons()["Don't Click This!"].tap();

mocking-server's People

Contributors

glyuck avatar andrewschaaf avatar

Watchers

James Cloos avatar Tom Davies 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.