You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a Wing app runs in the simulator, all user-authored inflight code is executed in child Node processes (see sandbox.ts). If the compiler injected HTTP mocking code in each child process, then it's possible to simulate the behavior of uniformly mocking an HTTP endpoint across all inflight functions.
Perhaps these mocks could be configured through a preflight API of some kind (just a sketch):
bringcloud;bringhttp;// methods that can only be called in preflightletmock=http.mockUrl("http://localhost:3000");mock.response(status: 201,body: "success");newcloud.Function(inflight()=>{let res =http.get("http://localhost:3000");assert(req.status==201);});
Internally, code would be inserted at the beginning of each child process's bundled code that initializes the appropriate mock(s).
The only downside of this approach is that the mocking effect would only apply to code using Node.js's fetch function, like Wing's built-in http module. For example, if an inflight function ran util.shell("curl http://localhost:3000"), the response would not be mocked. But this may be a reasonable tradeoff.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Inspired by https://twitter.com/mattpocockuk/status/1841074839446003927
When a Wing app runs in the simulator, all user-authored inflight code is executed in child Node processes (see sandbox.ts). If the compiler injected HTTP mocking code in each child process, then it's possible to simulate the behavior of uniformly mocking an HTTP endpoint across all inflight functions.
Perhaps these mocks could be configured through a preflight API of some kind (just a sketch):
Internally, code would be inserted at the beginning of each child process's bundled code that initializes the appropriate mock(s).
The only downside of this approach is that the mocking effect would only apply to code using Node.js's
fetch
function, like Wing's built-inhttp
module. For example, if an inflight function ranutil.shell("curl http://localhost:3000")
, the response would not be mocked. But this may be a reasonable tradeoff.Beta Was this translation helpful? Give feedback.
All reactions