Skip to content

Commit

Permalink
[#11]add test to include arbitrary library
Browse files Browse the repository at this point in the history
Add test to make it possible to include arbitrary library into the
function
  • Loading branch information
pedrosnk committed Oct 13, 2016
1 parent bf8e4c2 commit 6968ebb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/domain/sandbox/SandboxRequire.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SandboxRequire {
generateRequire() {
return (requireName) => {
let requestedModule;
if (this.module[requireName] !== undefined) {
if (this.module && this.module[requireName] !== undefined) {
requestedModule = this.module[requireName]();
} else if (this.globalModules.indexOf(requireName) !== -1) {
requestedModule = requireFunction(requireName);
Expand Down
25 changes: 25 additions & 0 deletions test/integration/domain/http/routers/FunctionsRouter.text.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,30 @@ describe('FunctionRouter integration', () => {
}, done);
});
});

describe('require arbitrary library inside function', () => {
before((done) => {
const code = `
const _ = require('lodash');
const people = [{name: 'John'}, {name: 'Doe'}];
function main(req, res) {
const names = _.map(people, 'name');
res.send({ names });
}
`;

request(routes)
.put('/functions/function-router-run/test4').send({ code })
.expect(200).expect('content-type', /json/, done);
});

it('should uses the arbitrary library properly', (done) => {
request(routes)
.put('/functions/function-router-run/test4/run')
.expect(200)
.expect('content-type', /json/)
.expect({ names: ['John', 'Doe']}, done);
});
});
});
});

0 comments on commit 6968ebb

Please sign in to comment.