GithubHelp home page GithubHelp logo

isabella232 / npm-registry-mock Goto Github PK

View Code? Open in Web Editor NEW

This project forked from npm/npm-registry-mock

0.0 0.0 0.0 672 KB

mock the npm registry

License: Other

Shell 6.66% JavaScript 93.34%

npm-registry-mock's Introduction

Build Status Dependency Status

#npm-registry-mock

##Mocked Packages

Currently mocked packages are:

underscore at 1.3.1, 1.3.3 and 1.5.1 while version 1.5.1 is the latest in this mocked registry.

request at 0.9.0, 0.9.5 and 2.27.0 while version 2.27.0 is the latest in this mocked registry.

test-package-with-one-dep at 0.0.0, with mocked dependency [email protected].

npm-test-peer-deps at 0.0.0, with a peer dependency on [email protected] and a dependency on [email protected].

test-repo-url-http at 0.0.0

test-repo-url-https at 0.0.1

test-repo-url-ssh at 0.0.1

mkdirp at 0.3.5

optimist at 0.6.0

clean at 2.1.6

async at 0.2.9, 0.2.10

checker at 0.5.1, 0.5.2

##Usage

Installing underscore 1.3.1:

var mr = require("npm-registry-mock")

mr({port: 1331}, function (err, s) {
  npm.load({registry: "http://localhost:1331"}, function () {
    npm.commands.install("/tmp", "[email protected]", function (err) {
      // assert npm behaves right...
      s.close() // shutdown server
    })
  })
})

Defining custom mock routes:

var mr = require("npm-registry-mock")

var customMocks = {
  "get": {
    "/mypackage": [500, {"ente" : true}]
  }
}

mr({port: 1331, mocks: customMocks}, function (err, s) {
  npm.load({registry: "http://localhost:1331"}, function () {
    npm.commands.install("/tmp", "mypackage", function (err) {
      // assert npm behaves right with an 500 error as response...
      s.close() // shutdown server
    })
  })
})

Limit the requests for each route:

mr({
    port: 1331,
    minReq: 1,
    maxReq: 5
  }, function (err, s) {

##Adding a new fixture

Although ideally we stick with the packages already mocked when writing new tests, in some cases it can be necessary to recreate a certain pathological or unusual scenario in the mock registry. In that case you can run

$ ./add-fixture.sh my-weird-package 1.2.3

to add that package to the fixtures directory.

##Breaking Changes for 1.0

  • the callback returns err, server now, instead of just server (npm#20)
  • options must be of type object
  • a "plugin" is injected via options.plugin, not as a mock being a function
  • a plugin does not override the default routes any more

npm-registry-mock's People

Contributors

robertkowalski avatar isaacs avatar iarna avatar bcoe avatar addaleax avatar domenic avatar evanlucas avatar othiym23 avatar arcanis avatar timoxley 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.