Local development tooling
Brandon Phillips
Similar to AWS SAM (https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-invoke.html) or Google Cloud Functions Framework (https://cloud.google.com/functions/docs/functions-framework).
I.e. the ability to run functions locally. It's expensive and slow to have to run and test code in a stitch project remotely all the time even for small changes.
Drew DiPalma
Hi Folks!
As part of our upcoming re-brand of "Stitch" to "Realm" we'll also be migrating our feedback forum and joining the rest of MongoDB at feedback.mongodb.com, as part of that transition, we'll be shutting down this forum. We're still keeping track of this feedback and all of the related comments/discussions, but all future updates will be made here:
https://feedback.mongodb.com/forums/923521-realm/suggestions/40550575-local-development-tooling
Drew DiPalma
Merged in a post:
Local context variable emulation
K
Kolton Kulis
Hi, I'm trying to setup unit tests for my Stitch functions that I can run locally on my computer and working on an automated build system that will push them to stitch after the tests pass.
Obviously context.functions presents a problem when I'm trying to run tests on my local machine, but I have created a work around.
I'm emulating the behavior of context by writing my own local version of context that can execute other js files. It also does its own version of context.values to grab configuration data for me. I haven't needed to create context.services, context.user, or context.request yet, but I may need to eventually write it. I pull context into my Stitch function like so and it allows me to run the Stitch function locally:
var context = require('../../PlatformFunctions/context');
I'm attaching two screenshots of context.js in action. The screenshots show the mocha test case, the function/values that are being called, and the test case results.
I posted the context.js code below.
Start Code
//Supports calling up to five arguments
function callExternalFunction(importedFunction, args){
let numberOfArgs = args.length;
if(numberOfArgs === 1)
return importedFunction(args[0]);
else if(numberOfArgs ===2)
return importedFunction(args[0], args[1]);
else if(numberOfArgs === 3)
return importedFunction(args[0], args[1],args[2]);
else if(numberOfArgs === 4)
return importedFunction(args[0], args[1],args[2],args[3]);
else if(numberOfArgs === 5)
return importedFunction(args[0], args[1],args[2],args[3],args[4]);
else
return importedFunction();
}
let context = {
functions : {
execute(functionName,...args){
let importedFunction = require(context.currentDirectory + functionName);
return callExternalFunction(importedFunction, args);
}
},
values : {
get(valuesName){
return require(context.currentDirectory + valuesName + ".json");
}
},
currentDirectory : process.cwd() + "/"
};
module.exports = context;
End Code
Feature Request:
Anyway, the above context.js file has been very useful for me. I would love it if there was something like this created by you guys that emulates the context behavior locally. It could be a js file you give clients that can run on their local node.js for testing. context.js seems to work for my purposes, but it is only my version of how I think context works (I cannot be absolutely sure I emulated it correctly). I would like it if there was some context.js testing file that is blessed by the Mongo team and kept up to date as new features are added.
Michael Bell
Proposal: I would prefer to develop locally in my preferred IDE. The ability to execute stich functions locally through the stitch cli would make it faster and easier to test functionality and run unit tests.
I imagine this would entail setting up a tunnel that provides the stitch context and associated http/ crypto libraries etc
Rhuan Samary Barreto
This is essential for me! Please implement this!