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

amd-ish

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amd-ish - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

2

package.json
{
"name": "amd-ish",
"description": "AMD style wrapper for node modules. Exposes factory via define.amd.factory for easy unit testing.",
"version": "0.0.7",
"version": "0.0.8",
"main": "src/define",

@@ -6,0 +6,0 @@ "dependencies": {

@@ -5,4 +5,5 @@ var aka,

modules = {},
mocks = {},
path = require('path'),
relPattern = /^[./]/,
relPattern = /^[.]/,
slice = Array.prototype.slice;

@@ -12,3 +13,3 @@

var module = resolveModuleFromArgs(callsite()[1].getFileName(), slice.call(arguments));
if(!factory) {
if (!factory) {
execFactory(module);

@@ -25,7 +26,27 @@ }

return module;
},
register: function (moduleId, result) {
moduleId = normalizeModuleId(moduleId, callsite()[1].getFileName());
var module = {
id: moduleId,
filename: moduleId,
result: result
};
mocks[module.id] = module;
return module;
},
unregister: function (moduleId) {
mocks[normalizeModuleId(moduleId, callsite()[1].getFileName())] = undefined;
}
};
function isRelative(moduleId) {
return relPattern.test(moduleId);
}
function normalizeModuleId(moduleId, filename) {
if(relPattern.test(moduleId)) {
if (isRelative(moduleId)) {
moduleId = path.normalize(path.resolve(path.dirname(filename), moduleId));

@@ -62,3 +83,3 @@ if (!path.extname('.js')) {

return module;
return mocks[module.id] || modules[module.id];
}

@@ -70,3 +91,3 @@

}
return modules[moduleId];
return mocks[moduleId] || modules[moduleId];
}

@@ -73,0 +94,0 @@

@@ -26,3 +26,3 @@ describe('define', function () {

it('should be able to inject a defined module result', function() {
it('should be able to inject a defined module result', function () {
define(['jasmine-injector'], callback);

@@ -33,3 +33,3 @@

it('should not execute the factory when called from define.amd.factory', function() {
it('should not execute the factory when called from define.amd.factory', function () {
var factory = define.amd.factory('./modules/module2');

@@ -39,2 +39,23 @@

});
describe('amd.register', function () {
beforeEach(function () {
define.amd.register('jasmine-injector', 'Awesome!');
});
it('should register a result for a module', function () {
define(['jasmine-injector'], callback);
expect(callback).toHaveBeenCalledWith('Awesome!');
});
it('should allow for unregistering modules (i.e.: clearing cache)', function () {
define.amd.unregister('jasmine-injector');
define(['jasmine-injector'], callback);
expect(callback).toHaveBeenCalledWith(jasmine.any(Function));
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc