New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

npm-registry-mock

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-registry-mock - npm Package Compare versions

Comparing version

to
0.2.0

test/fixtures/async/-/async-0.1.0.tgz

55

index.js

@@ -1,32 +0,43 @@

var nock = require("nock")
var hock = require("hock")
var predefinedMocks = require("./lib/predefines.js").predefinedMocks
module.exports = start
function start (url, cb) {
function start (port, cb) {
var mocks = predefinedMocks
if (typeof url == "function") {
cb = url
url = "http://localhost:1331/"
if (typeof port == "function") {
cb = port
port = 1331
}
if (typeof url == "object") {
mocks = url.mocks
url = url.url || "http://localhost:1331/"
if (typeof port == "object") {
mocks = port.mocks
port = port.port || 1331
}
hock.createHock(port, function(err, hockServer) {
for (var method in mocks) {
for (var route in mocks[method]) {
var status = mocks[method][route][0]
var customTarget = mocks[method][route][1]
var isTarball = /.tgz$/.test(route)
if (isTarball) {
var target = __dirname + "/fixtures/" + route;
if (customTarget && typeof customTarget == 'string')
target = customTarget
for (var method in mocks) {
for (var route in mocks[method]) {
var status = mocks[method][route][0]
var handler = mocks[method][route][1]
var isTarball = /.tgz$/.test(route)
if (isTarball) {
nock(url)[method](route).replyWithFile(status, __dirname + "/fixtures/" + route);
} else if (handler) {
nock(url)[method](route).reply(status, handler)
} else {
var res = require("./fixtures/" + route)
nock(url)[method](route).reply(status, res)
hockServer[method](route).replyWithFile(status, target);
} else {
if (!customTarget)
var res = require("./fixtures/" + route)
else
try {
var res = require(customTarget)
} catch (e) {
var res = customTarget
}
hockServer[method](route).reply(status, res)
}
}
}
}
cb && cb()
cb && cb(hockServer)
})
}

4

package.json
{
"name": "npm-registry-mock",
"version": "0.1.0",
"version": "0.2.0",
"description": "mock the npm registry",

@@ -10,3 +10,3 @@ "main": "index.js",

"dependencies": {
"nock": "~0.22.1"
"hock": "~0.2.0"
},

@@ -13,0 +13,0 @@ "devDependencies": {

@@ -9,3 +9,3 @@ [![Build Status](https://travis-ci.org/robertkowalski/npm-registry-mock.png?branch=master)](https://travis-ci.org/robertkowalski/npm-registry-mock)

Currently mocked packages are `underscore` at `1.3.1` and `1.5.1` while version `1.5.1` is the latest in this mocked registry.
Currently mocked packages are `underscore` at 1.3.1 and 1.5.1 while version 1.5.1 is the latest in this mocked registry.

@@ -17,6 +17,7 @@ Installing underscore 1.3.1:

mr("http://localhost:1331", function () {
mr(1331, function (s) {
npm.load({registry: "http://localhost:1331"}, function () {
npm.commands.install("/tmp", "underscore@1.3.1", function (err) {
// assert npm behaves right...
s.close() // shutdown server
})

@@ -34,10 +35,11 @@ })

"get": {
"/mypackage": [500, function handler (uri, requestBody) { return {"ente200": "true" } }]
"/mypackage": [500, {"ente" : true}]
}
}
mr({url: "http://localhost:1331", mocks: customMocks}, function () {
mr({port: 1331, mocks: customMocks}, function (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
})

@@ -44,0 +46,0 @@ })

@@ -18,3 +18,4 @@ var assert = require("assert")

// config
var address = "http://localhost:1331"
var port = 1331
var address = "http://localhost:" + port
var real = "http://registry.npmjs.org"

@@ -39,6 +40,7 @@ var conf = {

it("returns the underscore json", function (done) {
mr(address, function () {
mr(port, function (s) {
var client = new RC(conf)
client.get("/underscore", function (er, data, raw, res) {
assert.equal(data._id, "underscore")
s.close()
done(er)

@@ -54,3 +56,3 @@ })

it("sends the module as tarball (version specified)", function (done) {
mr(address, function () {
mr(port, function (s) {
npm.load({registry: address}, function () {

@@ -61,2 +63,3 @@ npm.commands.install(tempdir, "underscore@1.3.1", function (err) {

assert.equal(version, "1.3.1")
s.close()
done()

@@ -68,3 +71,3 @@ })

it("sends the module as tarball (no version specified -- latest)", function (done) {
mr(address, function () {
mr(port, function (s) {
npm.load({registry: address}, function () {

@@ -75,2 +78,3 @@ npm.commands.install(tempdir, "underscore", function (err) {

assert.equal(version, "1.5.1")
s.close()
done()

@@ -87,7 +91,9 @@ })

"get": {
"/ente200": [200, function handler (uri, requestBody) { return {"ente200": "true" } }],
"/ente400": [400, function handler (uri, requestBody) { return {"ente400": "true"} }]
"/ente200": [200, {ente200: "true"}],
"/ente400": [400, {ente400: "true"}],
"/async/-/async-0.1.0.tgz": [200, __dirname + "/fixtures/async/-/async-0.1.0.tgz"],
"/async/0.1.0": [200, __dirname + "/fixtures/async/0.1.0"],
}
}
mr({url: address, mocks: customMocks}, function () {
mr({port: 1331, mocks: customMocks}, function (s) {
request(address + "/ente200", function (er, res) {

@@ -99,3 +105,10 @@ assert.deepEqual(res.body, JSON.stringify({ente200: "true"}))

assert.equal(res.statusCode, 400)
done(er)
npm.load({registry: address}, function () {
npm.commands.install(tempdir, "async@0.1.0", function (err) {
var exists = fs.existsSync(tempdir + "/node_modules/async/package.json")
assert.ok(exists)
s.close()
done()
})
})
})

@@ -102,0 +115,0 @@ })