mirror of https://gitee.com/bigwinds/arangodb
Add @arangodb/locals module (3.3) (#5148)
* Add @arangodb/locals module Extending Node's module object in TS is tricky so let's provide a fake module for compatibility. * Add testcase
This commit is contained in:
parent
507418d9a4
commit
a566ff6e73
|
@ -27,9 +27,13 @@ v3.3.8 (XXXX-XX-XX)
|
||||||
- populated: database directory must exist and contain specific files already
|
- populated: database directory must exist and contain specific files already
|
||||||
- any: any state allowed
|
- any: any state allowed
|
||||||
|
|
||||||
|
* added `@arangodb/locals` module to expose the Foxx service context as an
|
||||||
|
alternative to using `module.context` directly.
|
||||||
|
|
||||||
* supervision can be put into maintenance mode
|
* supervision can be put into maintenance mode
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
v3.3.7 (2018-04-11)
|
v3.3.7 (2018-04-11)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,9 @@
|
||||||
function require (path) {
|
function require (path) {
|
||||||
assert(path, 'missing path');
|
assert(path, 'missing path');
|
||||||
assert(typeof path === 'string', 'path must be a string');
|
assert(typeof path === 'string', 'path must be a string');
|
||||||
|
if (path === '@arangodb/locals') {
|
||||||
|
return {context: module.context};
|
||||||
|
}
|
||||||
return Module._load(path, module);
|
return Module._load(path, module);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -631,6 +634,9 @@
|
||||||
Module.Module = Module;
|
Module.Module = Module;
|
||||||
|
|
||||||
global.require = function (request) {
|
global.require = function (request) {
|
||||||
|
if (request === '@arangodb/locals') {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
return Module._load(request);
|
return Module._load(request);
|
||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*globals describe, it */
|
||||||
|
'use strict';
|
||||||
|
const expect = require('chai').expect;
|
||||||
|
|
||||||
|
describe('@arangodb/locals', () => {
|
||||||
|
const context = {hello: 'world'};
|
||||||
|
it('should expose module.context', () => {
|
||||||
|
module.context = context;
|
||||||
|
const locals = require('@arangodb/locals');
|
||||||
|
expect(locals.context).to.equal(module.context);
|
||||||
|
expect(locals.context).to.equal(context);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue