Socket
Socket
Sign inDemoInstall

moog-require

Package Overview
Dependencies
Maintainers
12
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moog-require - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

5

package.json
{
"name": "moog-require",
"version": "1.1.1",
"version": "2.0.0",
"description": "moog-require extends moog with support for type definitions in local files and npm modules.",

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

"lodash": "^4.0.0",
"moog": "^1.0.0",
"moog": "^2.0.0",
"resolve": "^1.7.1",

@@ -17,2 +17,3 @@ "resolve-from": "^4.0.0"

"devDependencies": {
"bluebird": "^3.5.3",
"mocha": "^5.0.0"

@@ -19,0 +20,0 @@ },

@@ -351,2 +351,8 @@ [![Build Status](https://travis-ci.org/punkave/moog-require.svg?branch=master)](https://travis-ci.org/punkave/moog-require)

2.0.0: powered by `moog` version 2.x. This is a large and intentional bc break to support async/await
rather than callbacks. No direct code changes in this module, as all of the changes in `moog` itself,
involve instantiation, not definition. However the tests have been rewritten to match expectations
for moog 2.x, which is designed for async/await, not callbacks. The 1.x series of moog-require and moog
will be supported and maintained at least as long as Apostrophe 2.x (at least until the end of 2023).
1.1.1: use `importFresh` to avoid bugs when two instances of `moog-require` are

@@ -353,0 +359,0 @@ loading the same module definitions. Previously if modules created by

12

test/node_modules/failingBeforeConstructAsync/index.js

@@ -0,11 +1,11 @@

const Promise = require('bluebird');
module.exports = {
color: 'blue',
beforeConstruct: function(self, options, callback) {
beforeConstruct: async function(self, options) {
self._options = options;
// a wild error appears!
return setImmediate(function() {
return callback(new Error('I have failed.'));
});
await Promise.delay(100);
throw new Error('I have failed.');
},
construct: function(self, options) { }
};
};

@@ -0,11 +1,13 @@

const Promise = require('bluebird');
module.exports = {
color: 'blue',
beforeConstruct: function(self, options) { },
construct: function(self, options, callback) {
construct: async function(self, options) {
self._options = options;
// a wild error appears!
return setImmediate(function() {
return callback(new Error('I have failed.'));
});
await Promise.delay(100);
throw new Error('I have failed.');
}
};
};
module.exports = {
color: 'blue',
age: 30,
beforeConstruct: function(self, options, callback) {
beforeConstruct: async function(self, options) {
self._options = options;
return setImmediate(callback);
},
construct: function(self, options) { }
};
};

@@ -5,6 +5,5 @@ module.exports = {

beforeConstruct: function(self, options) { },
construct: function(self, options, callback) {
construct: async function(self, options) {
self._options = options;
return setImmediate(callback);
}
};

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

var assert = require('assert');
const assert = require('assert');
const _ = require('lodash');

@@ -14,3 +15,3 @@ // console.log = function(s) {

var synth = require('../index.js')({
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -23,14 +24,8 @@ root: module

});
it('has a `createAll` method', function() {
assert(synth.createAll);
});
it('has a `bridge` method', function() {
assert(synth.bridge);
});
});
describe('synth.create', function() {
var synth;
let synth;
it('should create a subclass with no options', function(done) {
it('should create a subclass with no options', async function() {
synth = require('../index.js')({

@@ -45,11 +40,8 @@ localModules: __dirname + '/project_modules',

synth.create('testModule', {}, function(err, testModule) {
assert(!err);
assert(testModule);
assert(testModule._options.color === 'blue');
return done();
});
const testModule = await synth.create('testModule', {});
assert(testModule);
assert(testModule._options.color === 'blue');
});
it('should create a subclass with overrides of default options', function(done) {
it('should create a subclass with overrides of default options', async function() {
synth = require('../index.js')({

@@ -66,10 +58,7 @@ localModules: __dirname + '/project_modules',

synth.create('testModule', {}, function(err, testModule) {
assert(!err);
assert(testModule._options.color === 'red');
return done();
});
const testModule = await synth.create('testModule', {});
assert(testModule._options.color === 'red');
});
it('should create a subclass with overrides of default options in localModules folder and npm', function(done) {
it('should create a subclass with overrides of default options in localModules folder and npm', async function() {
synth = require('../index.js')({

@@ -87,10 +76,7 @@ localModules: __dirname + '/project_modules',

synth.create('testModuleTwo', {}, function(err, testModuleTwo) {
assert(!err);
assert(testModuleTwo._options.color === 'red');
return done();
});
const testModuleTwo = await synth.create('testModuleTwo', {});
assert(testModuleTwo._options.color === 'red');
});
it('should create a subclass with overrides of default options at runtime', function(done) {
it('should create a subclass with overrides of default options at runtime', async function() {
synth = require('../index.js')({

@@ -105,10 +91,7 @@ localModules: __dirname + '/project_modules',

synth.create('testModule', { color: 'purple' }, function(err, testModule) {
assert(!err);
assert(testModule._options.color === 'purple');
return done();
});
const testModule = await synth.create('testModule', { color: 'purple' });
assert(testModule._options.color === 'purple');
});
it('should create a subclass with a new name using the `extend` property', function(done) {
it('should create a subclass with a new name using the `extend` property', async function() {
synth = require('../index.js')({

@@ -126,14 +109,8 @@ localModules: __dirname + '/project_modules',

synth.create('myTestModuleExtend', {}, function(err, myTestModule) {
if (err) {
console.error(err);
}
assert(!err);
assert(myTestModule);
assert(myTestModule._options.color === 'red');
return done();
});
const myTestModule = await synth.create('myTestModuleExtend', {});
assert(myTestModule);
assert(myTestModule._options.color === 'red');
});
it('should create a subclass with a new name by extending a module defined in localModules', function(done) {
it('should create a subclass with a new name by extending a module defined in localModules', async function() {
synth = require('../index.js')({

@@ -151,12 +128,8 @@ localModules: __dirname + '/project_modules',

synth.create('myTestModule', {}, function(err, myTestModule) {
assert(!err);
assert(myTestModule);
assert(myTestModule._options.color === 'purple');
assert(myTestModule._options.newProperty === 42);
return done();
});
const myTestModule = await synth.create('myTestModule', {});
assert(myTestModule._options.color === 'purple');
assert(myTestModule._options.newProperty === 42);
});
it('should create a subclass of a subclass', function(done) {
it('should create a subclass of a subclass', async function() {
synth = require('../index.js')({

@@ -177,16 +150,11 @@ localModules: __dirname + '/project_modules',

synth.create('myTestModule', {}, function(err, myTestModule) {
assert(!err);
assert(myTestModule);
assert(myTestModule._options.color === 'blue');
synth.create('mySubTestModule', {}, function(err, mySubTestModule) {
assert(!err);
assert(mySubTestModule);
assert(mySubTestModule._options.color === 'orange');
return done();
});
});
const myTestModule = await synth.create('myTestModule', {});
assert(myTestModule);
assert(myTestModule._options.color === 'blue');
const mySubTestModule = await synth.create('mySubTestModule', {});
assert(mySubTestModule);
assert(mySubTestModule._options.color === 'orange');
});
it('should create a subclass when both parent and subclass are in npm', function(done) {
it('should create a subclass when both parent and subclass are in npm', async function() {
synth = require('../index.js')({

@@ -201,14 +169,8 @@ localModules: __dirname + '/project_modules',

synth.create('testModuleThree', {}, function(err, testModuleThree) {
if (err) {
console.error(err);
}
assert(!err);
assert(testModuleThree);
assert(testModuleThree._options.age === 30);
return done();
});
const testModuleThree = await synth.create('testModuleThree', {});
assert(testModuleThree);
assert(testModuleThree._options.age === 30);
});
it('should create a subclass when the parent is an npm dependency of the subclass', function(done) {
it('should create a subclass when the parent is an npm dependency of the subclass', async function() {
synth = require('../index.js')({

@@ -223,8 +185,5 @@ localModules: __dirname + '/project_modules',

synth.create('testModuleFour', {}, function(err, testModuleFour) {
assert(!err);
assert(testModuleFour);
assert(testModuleFour._options.age === 70);
return done();
});
const testModuleFour = await synth.create('testModuleFour', {});
assert(testModuleFour);
assert(testModuleFour._options.age === 70);
});

@@ -236,5 +195,5 @@

describe('synth.createAll', function() {
var synth;
let synth;
it('should create two subclasses', function(done) {
it('should create two subclasses', async function() {
synth = require('../index.js')({

@@ -250,11 +209,8 @@ localModules: __dirname + '/project_modules',

synth.createAll({}, {}, function(err, modules) {
assert(!err);
assert(modules.testModule);
assert(modules.testModuleTwo);
return done();
});
const modules = await createAll(synth, {}, {});
assert(modules.testModule);
assert(modules.testModuleTwo);
});
it('should create two subclasses with runtime options passed using `specific` options', function(done) {
it('should create two subclasses with runtime options passed using `specific` options', async function() {
synth = require('../index.js')({

@@ -270,16 +226,13 @@ localModules: __dirname + '/project_modules',

synth.createAll({}, {
const modules = await createAll(synth, {}, {
testModule: { color: 'green' },
testModuleTwo: { color: 'green' }
}, function(err, modules) {
assert(!err);
assert(modules.testModule);
assert(modules.testModule._options.color === 'green');
assert(modules.testModuleTwo);
assert(modules.testModuleTwo._options.color === 'green');
return done();
});
assert(modules.testModule);
assert(modules.testModule._options.color === 'green');
assert(modules.testModuleTwo);
assert(modules.testModuleTwo._options.color === 'green');
});
it('should create two subclasses with runtime options passed using `global` options', function(done) {
it('should create two subclasses with runtime options passed using `global` options', async function() {
synth = require('../index.js')({

@@ -295,71 +248,14 @@ localModules: __dirname + '/project_modules',

synth.createAll({ color: 'green' }, { }, function(err, modules) {
assert(!err);
assert(modules.testModule);
assert(modules.testModule._options.color === 'green');
assert(modules.testModuleTwo);
assert(modules.testModuleTwo._options.color === 'green');
return done();
});
const modules = await createAll(synth, { color: 'green' }, { })
assert(modules.testModule);
assert(modules.testModule._options.color === 'green');
assert(modules.testModuleTwo);
assert(modules.testModuleTwo._options.color === 'green');
});
});
describe('synth.bridge', function() {
it('should run successfully', function(done) {
var synth = require('../index.js')({
localModules: __dirname + '/project_modules',
root: module
});
synth.define({
'testModule': { },
'testModuleTwo': { }
});
synth.createAll({ }, { }, function(err, modules) {
synth.bridge(modules);
assert(!err);
assert(modules.testModule);
assert(modules.testModuleTwo);
return done();
});
});
it('should pass modules to each other', function(done) {
var synth = require('../index.js')({
localModules: __dirname + '/project_modules',
root: module
});
synth.define({
'testModule': {
construct: function(self, options) {
self.setBridge = function(modules) {
self.otherModule = modules.testModuleTwo;
};
}
},
'testModuleTwo': {
construct: function(self, options) {
self.setBridge = function(modules) {
self.otherModule = modules.testModule;
};
}
}
});
synth.createAll({ }, { }, function(err, modules) {
assert(!err);
synth.bridge(modules);
assert(modules.testModule.otherModule);
assert(modules.testModuleTwo.otherModule);
return done();
});
});
});
describe('module structure', function() {
it('should accept a `defaultBaseClass` that is inherited by empty definitions', function(done) {
var synth = require('../index.js')({
it('should accept a `defaultBaseClass` that is inherited by empty definitions', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -374,8 +270,5 @@ defaultBaseClass: 'testModule',

synth.createAll({ }, { }, function(err, modules) {
assert(!err);
assert(modules.newModule);
assert(modules.newModule._options.color === 'blue');
return done();
});
const modules = await createAll(synth, { }, { });
assert(modules.newModule);
assert(modules.newModule._options.color === 'blue');
});

@@ -387,4 +280,4 @@

it('should accept a synchronous `construct` method', function(done) {
var synth = require('../index.js')({
it('should accept a synchronous `construct` method', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -398,11 +291,8 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(!err);
assert(modules.testModule);
return done();
});
const modules = await createAll(synth, { }, { });
assert(modules.testModule);
});
it('should accept an asynchronous `construct` method', function(done) {
var synth = require('../index.js')({
it('should accept an asynchronous `construct` method', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -416,11 +306,8 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(!err);
assert(modules.testModuleTwo);
return done();
});
const modules = await createAll(synth, { }, { });
assert(modules.testModuleTwo);
});
it('should accept a synchronous `beforeConstruct` method', function(done) {
var synth = require('../index.js')({
it('should accept a synchronous `beforeConstruct` method', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -434,11 +321,8 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(!err);
assert(modules.testModule);
return done();
});
const modules = await createAll(synth, { }, { });
assert(modules.testModule);
});
it('should accept an asynchronous `beforeConstruct` method', function(done) {
var synth = require('../index.js')({
it('should accept an asynchronous `beforeConstruct` method', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -452,7 +336,4 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(!err);
assert(modules.testBeforeConstructAsync);
return done();
});
const modules = await createAll(synth, { }, { });
assert(modules.testBeforeConstructAsync);
});

@@ -464,4 +345,4 @@

it('should catch a synchronous Error during `construct`', function(done) {
var synth = require('../index.js')({
it('should catch a synchronous Error during `construct`', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -475,11 +356,13 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(err);
assert(err.message === 'I have failed.');
return done();
});
try {
const modules = await createAll(synth, {}, {});
assert(false);
} catch (e) {
assert(e.message === 'I have failed.');
return;
}
});
it('should catch an asynchronous Error during `construct`', function(done) {
var synth = require('../index.js')({
it('should catch an asynchronous Error during `construct`', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -493,11 +376,13 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(err);
assert(err.message === 'I have failed.');
return done();
});
try {
const modules = await createAll(synth, {}, {});
} catch (e) {
assert(e.message === 'I have failed.');
return;
}
assert(false);
});
it('should catch a synchronous Error during `beforeConstruct`', function(done) {
var synth = require('../index.js')({
it('should catch a synchronous Error during `beforeConstruct`', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -511,11 +396,14 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(err);
assert(err.message === 'I have failed.');
return done();
});
try {
const modules = await createAll(synth, {}, {});
assert(false);
} catch (e) {
assert(e.message === 'I have failed.');
return;
}
});
it('should catch an asynchronous Error during `beforeConstruct`', function(done) {
var synth = require('../index.js')({
it('should catch an asynchronous Error during `beforeConstruct`', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -529,7 +417,10 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(err);
assert(err.message === 'I have failed.');
return done();
});
try {
const modules = await createAll(synth, {}, {});
assert(false);
} catch (e) {
assert(e.message === 'I have failed.');
return;
}
});

@@ -544,4 +435,4 @@ });

it('should call both the project-level `construct` and the npm module\'s `construct`', function(done) {
var synth = require('../index.js')({
it('should call both the project-level `construct` and the npm module\'s `construct`', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -557,12 +448,9 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(!err);
assert(modules.testDifferentConstruct._options);
assert(modules.testDifferentConstruct._differentOptions);
return done();
});
const modules = await createAll(synth, {}, {});
assert(modules.testDifferentConstruct._options);
assert(modules.testDifferentConstruct._differentOptions);
});
it('should call both the project-level `beforeConstruct` and the npm module\'s `beforeConstruct`', function(done) {
var synth = require('../index.js')({
it('should call both the project-level `beforeConstruct` and the npm module\'s `beforeConstruct`', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -578,12 +466,9 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(!err);
assert(modules.testDifferentConstruct._bcOptions);
assert(modules.testDifferentConstruct._bcDifferentOptions);
return done();
});
const modules = await createAll(synth, {}, {});
assert(modules.testDifferentConstruct._bcOptions);
assert(modules.testDifferentConstruct._bcDifferentOptions);
});
it('should override the project-level `construct` using a definitions-level `construct`', function(done) {
var synth = require('../index.js')({
it('should override the project-level `construct` using a definitions-level `construct`', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -602,13 +487,10 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(!err);
assert(modules.testDifferentConstruct._options);
assert(!modules.testDifferentConstruct._differentOptions);
assert(modules.testDifferentConstruct._definitionsLevelOptions);
return done();
});
const modules = await createAll(synth, {}, {});
assert(modules.testDifferentConstruct._options);
assert(!modules.testDifferentConstruct._differentOptions);
assert(modules.testDifferentConstruct._definitionsLevelOptions);
});
it('should override the project-level `beforeConstruct` using a definitions-level `beforeConstruct`', function(done) {
var synth = require('../index.js')({
it('should override the project-level `beforeConstruct` using a definitions-level `beforeConstruct`', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -627,9 +509,6 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(!err);
assert(modules.testDifferentConstruct._bcOptions);
assert(!modules.testDifferentConstruct._bcDifferentOptions);
assert(modules.testDifferentConstruct._bcDefinitionsLevelOptions);
return done();
});
const modules = await createAll(synth, {}, {});
assert(modules.testDifferentConstruct._bcOptions);
assert(!modules.testDifferentConstruct._bcDifferentOptions);
assert(modules.testDifferentConstruct._bcDefinitionsLevelOptions);
});

@@ -641,4 +520,4 @@

it('should respect baseClass-first order-of-operations for `beforeConstruct` and `construct`', function(done) {
var synth = require('../index.js')({
it('should respect baseClass-first order-of-operations for `beforeConstruct` and `construct`', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -652,14 +531,11 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(!err);
assert(modules.testOrderOfOperations._bcOrderOfOperations[0] === 'notlast');
assert(modules.testOrderOfOperations._bcOrderOfOperations[1] === 'last');
assert(modules.testOrderOfOperations._orderOfOperations[0] === 'first');
assert(modules.testOrderOfOperations._orderOfOperations[1] === 'second');
return done();
});
const modules = await createAll(synth, {}, {});
assert(modules.testOrderOfOperations._bcOrderOfOperations[0] === 'notlast');
assert(modules.testOrderOfOperations._bcOrderOfOperations[1] === 'last');
assert(modules.testOrderOfOperations._orderOfOperations[0] === 'first');
assert(modules.testOrderOfOperations._orderOfOperations[1] === 'second');
});
it('should respect baseClass-first order-of-operations for `beforeConstruct` and `construct` with subclassing', function(done) {
var synth = require('../index.js')({
it('should respect baseClass-first order-of-operations for `beforeConstruct` and `construct` with subclassing', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -681,12 +557,9 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(!err);
assert(modules.subTestOrderOfOperations._bcOrderOfOperations[0] === 'first');
assert(modules.subTestOrderOfOperations._bcOrderOfOperations[1] === 'notlast');
assert(modules.subTestOrderOfOperations._bcOrderOfOperations[2] === 'last');
assert(modules.subTestOrderOfOperations._orderOfOperations[0] === 'first');
assert(modules.subTestOrderOfOperations._orderOfOperations[1] === 'second');
assert(modules.subTestOrderOfOperations._orderOfOperations[2] === 'third');
return done();
});
const modules = await createAll(synth, {}, {});
assert(modules.subTestOrderOfOperations._bcOrderOfOperations[0] === 'first');
assert(modules.subTestOrderOfOperations._bcOrderOfOperations[1] === 'notlast');
assert(modules.subTestOrderOfOperations._bcOrderOfOperations[2] === 'last');
assert(modules.subTestOrderOfOperations._orderOfOperations[0] === 'first');
assert(modules.subTestOrderOfOperations._orderOfOperations[1] === 'second');
assert(modules.subTestOrderOfOperations._orderOfOperations[2] === 'third');
});

@@ -696,4 +569,4 @@ });

describe('bundles', function() {
it('should expose two new modules via a bundle', function(done) {
var synth = require('../index.js')({
it('should expose two new modules via a bundle', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -709,10 +582,7 @@ root: module,

synth.createAll({ }, { }, function(err, modules) {
assert(!err);
assert(modules.bundleModuleOne);
assert(modules.bundleModuleOne._options.color === 'blue');
assert(modules.bundleModuleTwo);
assert(modules.bundleModuleTwo._options.color === 'blue');
return done();
});
const modules = await createAll(synth, {}, {});
assert(modules.bundleModuleOne);
assert(modules.bundleModuleOne._options.color === 'blue');
assert(modules.bundleModuleTwo);
assert(modules.bundleModuleTwo._options.color === 'blue');
});

@@ -722,4 +592,4 @@ });

describe('metadata', function() {
it('should expose correct dirname metadata for npm, project level, and explicitly defined classes in the chain', function(done) {
var synth = require('../index.js')({
it('should expose correct dirname metadata for npm, project level, and explicitly defined classes in the chain', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -734,26 +604,20 @@ root: module

synth.create('metadataExplicit', { }, function(err, module) {
if (err) {
console.error(err);
}
assert(!err);
assert(module);
assert(module.__meta);
assert(module.__meta.chain);
assert(module.__meta.chain[0]);
assert(module.__meta.chain[0].dirname === __dirname + '/node_modules/metadataNpm');
assert(module.__meta.chain[1]);
assert(module.__meta.chain[1].dirname === __dirname + '/project_modules/metadataNpm');
assert(module.__meta.chain[2]);
assert(module.__meta.chain[2].dirname === __dirname + '/project_modules/metadataProject');
assert(module.__meta.chain[3]);
assert(module.__meta.chain[3].dirname === __dirname + '/project_modules/metadataExplicit');
return done();
});
const m = await synth.create('metadataExplicit', { });
assert(m);
assert(m.__meta);
assert(m.__meta.chain);
assert(m.__meta.chain[0]);
assert(m.__meta.chain[0].dirname === __dirname + '/node_modules/metadataNpm');
assert(m.__meta.chain[1]);
assert(m.__meta.chain[1].dirname === __dirname + '/project_modules/metadataNpm');
assert(m.__meta.chain[2]);
assert(m.__meta.chain[2].dirname === __dirname + '/project_modules/metadataProject');
assert(m.__meta.chain[3]);
assert(m.__meta.chain[3].dirname === __dirname + '/project_modules/metadataExplicit');
});
});
describe('error handling', function() {
it('should prevent cyclical module definitions', function(done) {
var synth = require('../index.js')({
describe('error handling', async function() {
it('should prevent cyclical module definitions', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -772,6 +636,8 @@ root: module

synth.createAll({ }, { }, function(err, modules) {
assert(err);
return done();
});
try {
const modules = await createAll(synth, {}, {});
assert(false);
} catch (e) {
return;
}
});

@@ -781,4 +647,4 @@ });

describe('replace option', function() {
it('should substitute a replacement type when replace option is used', function() {
var synth = require('../index.js')({
it('should substitute a replacement type when replace option is used', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -789,3 +655,3 @@ root: module

synth.define('replaceTestReplacement');
var instance = synth.create('replaceTestOriginal', {});
let instance = await synth.create('replaceTestOriginal', {});
assert(instance._options);

@@ -798,4 +664,4 @@ assert(!instance._options.color);

describe('improve option', function() {
it('should substitute an implicit subclass when improve option is used', function() {
var synth = require('../index.js')({
it('should substitute an implicit subclass when improve option is used', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -806,3 +672,3 @@ root: module

synth.define('improveTestReplacement');
var instance = synth.create('improveTestOriginal', {});
let instance = await synth.create('improveTestOriginal', {});
assert(instance._options);

@@ -812,4 +678,4 @@ assert(instance._options.color === 'red');

});
it('should require the original for you if needed', function() {
var synth = require('../index.js')({
it('should require the original for you if needed', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -819,3 +685,3 @@ root: module

synth.define('improveTestReplacement');
var instance = synth.create('improveTestOriginal', {});
let instance = await synth.create('improveTestOriginal', {});
assert(instance._options);

@@ -828,4 +694,4 @@ assert(instance._options.color === 'red');

describe('nestedModuleSubdirs option', function() {
it('should load a module from a regular folder without the nesting feature enabled', function() {
var synth = require('../index.js')({
it('should load a module from a regular folder without the nesting feature enabled', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -835,8 +701,8 @@ root: module

synth.define('testModuleSimple');
var instance = synth.create('testModuleSimple', {});
let instance = await synth.create('testModuleSimple', {});
assert(instance._options);
assert(instance._options.color === 'red');
});
it('should load a module from a nested or non-nested folder with the nesting option enabled', function() {
var synth = require('../index.js')({
it('should load a module from a nested or non-nested folder with the nesting option enabled', async function() {
let synth = require('../index.js')({
localModules: __dirname + '/project_modules',

@@ -847,7 +713,7 @@ nestedModuleSubdirs: true,

synth.define('testModuleSimple');
var instance = synth.create('testModuleSimple', {});
let instance = await synth.create('testModuleSimple', {});
assert(instance._options);
assert(instance._options.color === 'red');
synth.define('nestedModule');
var instance = synth.create('nestedModule', {});
instance = await synth.create('nestedModule', {});
assert(instance._options);

@@ -859,1 +725,22 @@ assert(instance._options.color === 'green');

});
async function createAll(synth, globalOptions, specificOptions) {
const self = synth;
const result = {};
const defined = Object.keys(self.definitions);
const explicit = defined.filter(function(type) {
return self.definitions[type].__meta.explicit === true;
});
for (let name of explicit) {
const options = applyOptions(name);
const obj = await self.create(name, options);
result[name] = obj;
}
return result;
function applyOptions(name) {
return { ...globalOptions, ...(specificOptions[name] || {}) };
}
}
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