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.5.3

49

index.js

@@ -1,2 +0,3 @@

var path = require('path')
var path = require("path")
var fs = require("fs")

@@ -19,3 +20,3 @@ var hock = require("hock")

}
hock.createHock(port, function(err, hockServer) {
hock.createHock(port, function (err, hockServer) {
if (typeof mocks == "function") {

@@ -25,29 +26,37 @@ mocks(hockServer)

mocks = extendRoutes(mocks || {})
for (var method in mocks) {
for (var route in mocks[method]) {
Object.keys(mocks).forEach(function (method) {
Object.keys(mocks[method]).forEach(function (route) {
var status = mocks[method][route][0]
var customTarget = mocks[method][route][1]
var isTarball = /(.tgz|.js)$/.test(route)
if (isTarball) {
var target = __dirname + path.sep + "fixtures" + route.replace(/\//g, path.sep);
if (customTarget && typeof customTarget == 'string')
target = customTarget
var target
hockServer[method](route).replyWithFile(status, target);
} else {
if (customTarget && typeof customTarget === "string")
target = customTarget
else
target = __dirname + path.sep + "fixtures" + route.replace(/\//g, path.sep)
fs.lstat(target, function (err, stats) {
if (err) return next()
if (stats.isDirectory()) return next()
return hockServer[method](route).replyWithFile(status, target)
})
function next() {
var res
if (!customTarget) {
var res = require(__dirname + path.sep + "fixtures" + route.replace(/\//g, path.sep))
res = require(__dirname + path.sep + "fixtures" + route.replace(/\//g, path.sep))
res = JSON.stringify(res).replace(/http:\/\/registry\.npmjs\.org/ig, 'http://localhost:' + port)
return hockServer[method](route).reply(status, res)
}
else {
try {
var res = require(customTarget)
} catch (e) {
var res = customTarget
}
try {
res = require(customTarget)
} catch (e) {
res = customTarget
}
hockServer[method](route).reply(status, res)
}
}
}
})
})
}

@@ -54,0 +63,0 @@ cb && cb(hockServer)

{
"name": "npm-registry-mock",
"version": "0.5.2",
"version": "0.5.3",
"description": "mock the npm registry",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -156,2 +156,18 @@ var assert = require("assert")

})
it("can hande custom data for js files", function (done) {
var customMocks = {
"get": {
"/package.js": [200, {"ente" : true}],
"/shrinkwrap.js": [200, {"ente" : true}]
}
}
mr({port: 1331, mocks: customMocks}, function (s) {
request(address + "/package.js", function (er, res) {
assert.equal(res.body, JSON.stringify({"ente" : true}))
s.close()
done()
})
})
})
it("overwrites the predefined routes, if custom one given", function (done) {

@@ -158,0 +174,0 @@ var customMocks = {