Giter Club home page Giter Club logo

nock-vcr's Introduction

#Nock-VCR

Like the Ruby VCR gem, record your test-suite's HTTP interactions and replay them during future runs for speedy, deterministic, and accurate tests. Built atop nock's testing and recording capability.

Installation

npm install nock-vcr

Usage

In your tests, require nock-vcr. Then use insertCassette to mark the start of where recording - and later playback - should begin and ejectCassette where it should end. Recorded "cassettes" - nock code to mock the transactions - will be saved under test/cassettes!

For example:

nvcr = require 'nock-vcr'

fs = require 'fs'
http = require 'http'

requestComplete = false

describe 'using nock-vcr', ->
  context 'insert a cassette, and eject it when it is done', ->
    beforeEach (done)->
      nvcr.insertCassette 'Your cassette name here'
      options = method: 'GET', host: 'google.com', port: 80, path: '/'
      http.request(options, (res)=>
        res.on 'end', =>
          requestComplete = true
          nvcr.ejectCassette()
          done()
      ).end()

    it 'creates a cassette', ->
      expect(requestComplete).to.be.true

You can force nock-vcr to record all the time by passing and setting a record option of insertCassette to the string 'ALL', or by setting the environment variable NOCK_VCR_MODE to the same value.

Notes

Currently this runs on top of a modified version of nock that corrects a bug in the code generated during recording as well as a way to re-activate mocking after a restore.

Upcoming Features

  • More options that can affect the recording behavior.
  • Hooks into popular testing frameworks.

nock-vcr's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nock-vcr's Issues

Hook into Jasmine framework automatically

This would take the form of:

  • Easy configuration
  • Automatically naming cassettes after the describe enclosure they are in.
  • Automatically ejecting cassettes when the before is finished.

Hook into Mocha frameworks automatically

Ideally this would take the form of:

  • automatically naming tapes after the describe/context they are in
  • automatically ejecting when the done method is triggered.

Not saving port number

Thanks for the work you;ve done here, it's really helpful!

One thing I've bumped into is that I'm making an request to a port (3000) on my local computer. The generated cassette doesn't save this, so following requests fail. If I manually modify the port number on the cassette it works perfectly, but it's a bit inconvenient, it would be great if the port number was automatically added.

Cheers!

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.