From 41e9d6e58550f6603d39b5227bd9635016af1028 Mon Sep 17 00:00:00 2001 From: Alan Plum Date: Fri, 20 Apr 2018 12:51:33 +0200 Subject: [PATCH] Add @arangodb/locals module (#5145) * Add @arangodb/locals module Extending Node's module object in TS is tricky so let's provide a fake module for compatibility. * Add testcase --- CHANGELOG | 3 +++ js/common/bootstrap/modules.js | 6 ++++++ js/common/tests/shell/shell-locals-spec.js | 13 +++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 js/common/tests/shell/shell-locals-spec.js diff --git a/CHANGELOG b/CHANGELOG index dad6e8dda0..7addde3a4f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -207,6 +207,9 @@ devel * fixed internal #2215's failedleader timeout, when in todo +* added `@arangodb/locals` module to expose the Foxx service context as an + alternative to using `module.context` directly. + v3.3.4 (XXXX-XX-XX) ------------------- diff --git a/js/common/bootstrap/modules.js b/js/common/bootstrap/modules.js index 745a201f7d..0460a52fd4 100644 --- a/js/common/bootstrap/modules.js +++ b/js/common/bootstrap/modules.js @@ -92,6 +92,9 @@ function require (path) { assert(path, 'missing path'); assert(typeof path === 'string', 'path must be a string'); + if (path === '@arangodb/locals') { + return {context: module.context}; + } return Module._load(path, module); } @@ -631,6 +634,9 @@ Module.Module = Module; global.require = function (request) { + if (request === '@arangodb/locals') { + return {}; + } return Module._load(request); }; }()); diff --git a/js/common/tests/shell/shell-locals-spec.js b/js/common/tests/shell/shell-locals-spec.js new file mode 100644 index 0000000000..8797658e3a --- /dev/null +++ b/js/common/tests/shell/shell-locals-spec.js @@ -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); + }); +});