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

glue

Package Overview
Dependencies
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glue - npm Package Compare versions

Comparing version 2.0.0-rc3 to 2.0.0-rc4

test/plugins/helloworld.js

19

lib/index.js

@@ -30,3 +30,4 @@ // Load modules

/*
var config1 = {
// Example manifest
var manifest = {
server: {

@@ -73,8 +74,5 @@ cache: 'redis',

Hoek.assert(typeof manifest === 'object', 'Invalid manifest');
Hoek.assert(typeof options === 'object', 'Invalid options');
Hoek.assert(typeof callback === 'function', 'Invalid callback');
Joi.assert(options, internals.schema.options, 'Invalid options');
Joi.assert(manifest, internals.schema.manifest, 'Invalid manifest options');
Joi.assert(manifest, internals.schema.manifest, 'Invalid manifest');

@@ -167,7 +165,6 @@ // Create server

var item = config[i];
if (typeof item === 'string' || typeof item.engine === 'string') {
if (typeof item === 'string') {
item = { engine: item };
}
if (typeof item === 'string') {
item = { engine: item };
}
if (typeof item.engine === 'string') {
var strategy = item.engine;

@@ -201,2 +198,4 @@ if (relativeTo && strategy[0] === '.') {

Hoek.assert(plugin.length > 0, 'Invalid plugin configuration');
plugin.forEach(function (instance) {

@@ -203,0 +202,0 @@

{
"name": "glue",
"description": "Server composer for hapi.js",
"version": "2.0.0-rc3",
"version": "2.0.0-rc4",
"repository": "git://github.com/hapijs/glue",

@@ -19,3 +19,3 @@ "main": "index",

"boom": "2.x.x",
"hapi": "8.0.0-rc8",
"hapi": "8.x.x",
"hoek": "2.x.x",

@@ -22,0 +22,0 @@ "items": "1.x.x",

@@ -19,6 +19,6 @@ #glue

+ `options` - an object having
* 'relativeTo' - (optional) a file-system path string that is used to resolve loading modules with `require`. Used in `server.cache` and `plugins[name]`
* 'preConnections' - (optional) a callback function that is called prior to adding connections to the server. The function signature is `function (server)` where:
* 'relativeTo' - a file-system path string that is used to resolve loading modules with `require`. Used in `server.cache` and `plugins[name]`
* 'preConnections' - a callback function that is called prior to adding connections to the server. The function signature is `function (server)` where:
+ `server` - is the server object returned from `new Server(options)`.
* 'prePlugins' - (optional) a callback function that is called prior to registering plugins with the server. The function signature is `function (server)` where:
* 'prePlugins' - a callback function that is called prior to registering plugins with the server. The function signature is `function (server)` where:
+ `server` - is the server object with all connections selected.

@@ -25,0 +25,0 @@ + `callback` - the callback function with signature `function (err, server)` where:

@@ -24,24 +24,5 @@ // Load modules

it('composes server', function (done) {
it('composes server with an empty manifest', function (done) {
var manifest = {
server: {
cache: '../node_modules/catbox-memory',
app: {
my: 'special-value'
}
},
connections: [
{
labels: ['api', 'nasty', 'test']
},
{
host: 'localhost',
labels: ['api', 'nice']
}
],
plugins: {
'../test/plugins/--test1': null
}
};
var manifest = {};

@@ -51,20 +32,14 @@ Glue.compose(manifest, function (err, server) {

expect(err).to.not.exist();
server.start(function (err) {
expect(err).to.not.exist();
server.stop(function () {
server.connections[0].inject('/test1', function (res) {
expect(res.result).to.equal('testing123special-value');
done();
});
});
});
expect(server.connections).length(1);
done();
});
});
it('composes server (empty)', function (done) {
it('composes server with server.cache as a string', function (done) {
var manifest = {};
var manifest = {
server: {
cache: '../node_modules/catbox-memory'
}
};

@@ -78,9 +53,7 @@ Glue.compose(manifest, function (err, server) {

it('composes server (default)', function (done) {
it('composes server with server.cache as an array', function (done) {
var manifest = {
plugins: {
'../test/plugins/--custom': {
path: '/abc'
}
server: {
cache: ['../node_modules/catbox-memory']
}

@@ -92,18 +65,7 @@ };

expect(err).to.not.exist();
server.start(function (err) {
expect(err).to.not.exist();
server.stop(function () {
server.inject('/abc', function (res) {
expect(res.result).to.equal('/abc');
done();
});
});
});
done();
});
});
it('composes server (cache.engine)', function (done) {
it('composes server with server.cache.engine as a string', function (done) {

@@ -114,20 +76,3 @@ var manifest = {

engine: '../node_modules/catbox-memory'
},
app: {
my: 'special-value'
}
},
connections: [
{
port: 0,
labels: ['api', 'nasty', 'test']
},
{
host: 'localhost',
port: 0,
labels: ['api', 'nice']
}
],
plugins: {
'../test/plugins/--test1': null
}

@@ -139,18 +84,7 @@ };

expect(err).to.not.exist();
server.start(function (err) {
expect(err).to.not.exist();
server.stop(function () {
server.connections[0].inject('/test1', function (res) {
expect(res.result).to.equal('testing123special-value');
done();
});
});
});
done();
});
});
it('composes server (cache array)', function (done) {
it('composes server with server.cache.engine as a function', function (done) {

@@ -160,21 +94,4 @@ var manifest = {

cache: [{
engine: '../node_modules/catbox-memory'
}],
app: {
my: 'special-value'
}
},
connections: [
{
port: 0,
labels: ['api', 'nasty', 'test']
},
{
host: 'localhost',
port: 0,
labels: ['api', 'nice']
}
],
plugins: {
'../test/plugins/--test1': null
engine: require('catbox-memory')
}]
}

@@ -186,42 +103,28 @@ };

expect(err).to.not.exist();
server.start(function (err) {
done();
});
});
expect(err).to.not.exist();
server.stop(function () {
it('composes server with server.cache.engine resolved using options.relativeTo', function (done) {
server.connections[0].inject('/test1', function (res) {
var manifest = {
server: {
cache: '../../node_modules/catbox-memory'
}
};
expect(res.result).to.equal('testing123special-value');
done();
});
});
});
Glue.compose(manifest, { relativeTo: __dirname + '/plugins' }, function (err, server) {
expect(err).to.not.exist();
done();
});
});
it('composes server (engine function)', function (done) {
it('composes server with connections array having multiple entries', function (done) {
var manifest = {
server: {
cache: {
engine: require('catbox-memory')
},
app: {
my: 'special-value'
}
},
connections: [
{
port: 0,
labels: ['api', 'nasty', 'test']
},
{
host: 'localhost',
port: 0,
labels: ['api', 'nice']
}
],
plugins: {
'../test/plugins/--test1': null
}
{labels: 'a'},
{labels: 'b'}
]
};

@@ -232,33 +135,12 @@

expect(err).to.not.exist();
server.start(function (err) {
expect(err).to.not.exist();
server.stop(function () {
server.connections[0].inject('/test1', function (res) {
expect(res.result).to.equal('testing123special-value');
done();
});
});
});
expect(server.connections).length(2);
done();
});
});
it('composes server (string port)', function (done) {
it('composes server with plugins having a plugin with null options', function (done) {
var manifest = {
connections: [
{
port: '0',
labels: ['api', 'nasty', 'test']
},
{
host: 'localhost',
port: 0,
labels: ['api', 'nice']
}
],
plugins: {
'../test/plugins/--test1': {}
'../test/plugins/helloworld.js': null
}

@@ -270,75 +152,31 @@ };

expect(err).to.not.exist();
server.start(function (err) {
expect(err).to.not.exist();
server.stop();
server.connections[0].inject('/test1', function (res) {
expect(res.result).to.equal('testing123');
done();
});
});
expect(server.plugins.helloworld).to.exist();
expect(server.plugins.helloworld.hello).to.equal('world');
done();
});
});
it('composes server (relative and absolute paths)', function (done) {
it('composes server with plugins having a plugin registered with options', function (done) {
var manifest = {
server: {
cache: {
engine: '../../node_modules/catbox-memory'
},
app: {
my: 'special-value'
}
},
connections: [
{
port: 0,
labels: ['api', 'nasty', 'test']
},
{
host: 'localhost',
port: 0,
labels: ['api', 'nice']
}
],
plugins: {
'./--test2': null
'../test/plugins/helloworld.js': {who: 'earth'}
}
};
manifest.plugins[__dirname + '/plugins/--test1'] = null;
Glue.compose(manifest, function (err, server) {
Glue.compose(manifest, { relativeTo: __dirname + '/plugins' }, function (err, server) {
expect(err).to.not.exist();
server.start(function (err) {
expect(err).to.not.exist();
server.stop(function () {
server.connections[0].inject('/test1', function (res) {
expect(res.result).to.equal('testing123special-value');
done();
});
});
});
expect(server.plugins.helloworld).to.exist();
expect(server.plugins.helloworld.hello).to.equal('earth');
done();
});
});
it('composes server with ports', function (done) {
it('composes server with plugins having a plugin with null options and null register options', function (done) {
var manifest = {
connections: [
{
port: 8000
},
{
port: '8001'
}
],
plugins: {}
plugins: {
'../test/plugins/helloworld.js': [{}]
}
};

@@ -349,2 +187,4 @@

expect(err).to.not.exist();
expect(server.plugins.helloworld).to.exist();
expect(server.plugins.helloworld.hello).to.equal('world');
done();

@@ -354,13 +194,11 @@ });

it('validates server config after defaults applied', function (done) {
it('composes server with plugins having a plugin registered with register options', function (done) {
var manifest = {
connections: [
{
routes: {
timeout: {}
}
}
],
plugins: {}
plugins: {
'../test/plugins/route.js': [{
options: { ignored: true },
routes: { prefix: '/third/planet' }
}]
}
};

@@ -371,2 +209,4 @@

expect(err).to.not.exist();
expect(server.plugins.route).to.exist();
expect(server.plugins.route.prefix).to.equal('/third/planet');
done();

@@ -376,46 +216,19 @@ });

it('composes server with plugin registration options', function (done) {
/*
it('composes server with plugins having a plugin loaded multiple times', function (done) {
var manifest = {
server: {
app: {
my: 'special-value'
}
},
connections: [
{
port: 0,
labels: ['a', 'b']
},
{
port: 0,
labels: ['b', 'c']
}
{labels: 'a'},
{labels: 'b'}
],
plugins: {
'../test/plugins/--custom': [
'../test/plugins/route.js': [
{
options: {
path: '/'
}
},
{
select: 'a',
options: {
path: '/a'
}
routes: { prefix: '/a' }
},
{
select: 'b',
options: {
path: '/b'
}
},
{
routes: {
prefix: '/steve'
},
options: {
path: '/a'
}
routes: { prefix: '/b' }
}

@@ -429,69 +242,21 @@ ]

expect(err).to.not.exist();
var server1 = server.connections[0];
var server2 = server.connections[1];
server1.inject('/', function (res) {
expect(res.statusCode).to.equal(200);
expect(res.result).to.equal('/');
server2.inject('/', function (res) {
expect(res.statusCode).to.equal(200);
expect(res.result).to.equal('/');
server1.inject('/a', function (res) {
expect(res.statusCode).to.equal(200);
expect(res.result).to.equal('/a');
server2.inject('/a', function (res) {
expect(res.statusCode).to.equal(404);
server1.inject('/b', function (res) {
expect(res.statusCode).to.equal(200);
expect(res.result).to.equal('/b');
server2.inject('/b', function (res) {
expect(res.statusCode).to.equal(200);
expect(res.result).to.equal('/b');
server1.inject('/steve/a', function (res) {
expect(res.statusCode).to.equal(200);
expect(res.result).to.equal('/a');
server2.inject('/steve/a', function (res) {
expect(res.statusCode).to.equal(200);
expect(res.result).to.equal('/a');
done();
});
});
});
});
});
});
});
});
expect(server.select('a').plugins.route.prefix).to.equal('/a');
expect(server.select('b').plugins.route.prefix).to.equal('/b');
done();
});
});
*/
it('composes server with inner deps', function (done) {
it('composes server with plugins resolved using options.relativeTo', function (done) {
var manifest = {
connections: [{}],
plugins: {
'../test/plugins/--deps1': null,
'../test/plugins/--deps2': null
'./helloworld.js': null
}
};
Glue.compose(manifest, function (err, server) {
Glue.compose(manifest, { relativeTo: __dirname + '/plugins' }, function (err, server) {
expect(err).to.not.exist();
expect(server.plugins.helloworld.hello).to.equal('world');
done();

@@ -549,49 +314,122 @@ });

it('errors on invalid plugin', function (done) {
it('throws on bogus options.realativeTo path (server.cache)', function (done) {
var manifest = {
connections: [{}],
plugins: {
'../test/plugins/--fail': null
server: {
cache: './catbox-memory'
}
};
Glue.compose(manifest, function (err, server) {
expect(function () {
expect(err).to.exist();
done();
});
Glue.compose(manifest, { relativeTo: __dirname + '/badpath' }, function () { });
}).to.throw(/Cannot find module/);
done();
});
it('throws on server with missing inner deps', function (done) {
it('throws on bogus options.realativeTo path (plugins)', function (done) {
var manifest = {
connections: [{ host: 'localhost' }],
plugins: {
'../test/plugins/--deps1': null
'./helloworld.js': null
}
};
Glue.compose(manifest, function (err, server) {
expect(function () {
expect(function () {
server.start();
}).to.throw('Plugin --deps1 missing dependency --deps2 in connection: http://localhost');
Glue.compose(manifest, { relativeTo: __dirname + '/badpath' }, function () { });
}).to.throw(/Cannot find module/);
done();
});
done();
});
it('throws on options not an object', function (done) {
var manifest = {};
expect(function () {
Glue.compose(manifest, 'hello', function () { });
}).to.throw(/Invalid options/);
done();
});
it('throws on invalid manifest options', function (done) {
it('throws on callback not a function', function (done) {
var manifest = {};
expect(function () {
Glue.compose(manifest, 'hello');
}).to.throw(/Invalid callback/);
done();
});
it('throws on invalid manifest (not an object)', function (done) {
var manifest = 'hello';
expect(function () {
Glue.compose(manifest, function () { });
}).to.throw(/Invalid manifest/);
done();
});
it('throws on invalid manifest (server not an object)', function (done) {
var manifest = {
server: {
app: {
my: 'special-value'
}
},
connections: [
],
server: 'hello'
};
expect(function () {
Glue.compose(manifest, function () { });
}).to.throw(/Invalid manifest/);
done();
});
it('throws on invalid manifest (connections not an array)', function (done) {
var manifest = {
connections: 'hello'
};
expect(function () {
Glue.compose(manifest, function () { });
}).to.throw(/Invalid manifest/);
done();
});
it('throws on invalid manifest (connections must have at least one entry)', function (done) {
var manifest = {
connections: []
};
expect(function () {
Glue.compose(manifest, function () { });
}).to.throw(/Invalid manifest/);
done();
});
it('throws on invalid manifest (plugins not an object)', function (done) {
var manifest = {
plugins: 'hello'
};
expect(function () {
Glue.compose(manifest, function () { });
}).to.throw(/Invalid manifest/);
done();
});
it('throws on invalid plugin configuration', function (done) {
var manifest = {
plugins: {
'./--loaded': {}
'../test/plugins/helloworld.js': []
}

@@ -603,5 +441,5 @@ };

Glue.compose(manifest, function () { });
}).to.throw(/Invalid manifest options/);
}).to.throw(/Invalid plugin configuration/);
done();
});
});
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