lucasconstantino / now-we-test Goto Github PK
View Code? Open in Web Editor NEWTest your Now deployed Node.js lambdas locally
License: MIT License
Test your Now deployed Node.js lambdas locally
License: MIT License
Routes using query string might be rebuild to wrong paths.
i.e.:
For routes:
"routes": [
{
"src": "/(?<id>.*)",
"dest": "/src/hooks/$id.js",
"headers": { "Access-Control-Allow-Origin": "*" }
}
]
And request
/foo?bar=tor`
The resolved path is currently:
/src/hooks/foo?bar=tor.js
Hi, this module works well with happy paths, but I can't seem to test broken paths.
My lambda calls an external service. I mock the service to throw an error and then handle the error within my code. However, these lines (https://github.com/lucasconstantino/now-we-test/blob/master/lib/simulator.js#L56-L69) seem to capture the thrown error and not let my lambda handle the error.
Any insight would be appreciated.
I cannot reach any routes deeper than /
.
Here's my now.json routes section:
"routes": [
{ "src": "/", "dest": "/services/index.js" },
{ "src": "/locations", "methods": ["GET"], "dest": "/services/locations/read.js" },
{ "src": "/users", "methods": ["GET"], "dest": "/services/users/read.js" },
{ "src": "/users/(?<id>[^/]*)", "methods": ["GET"], "dest": "/services/users/read.js?id=$id" },
{ "src": "/users", "methods": ["POST"], "dest": "/services/users/create.js" }
]
If I try to reach /locations, I get the error Expected lambda file not found
. Deployed on Now 2.0, this works, so there is a problem with the now-we-test
server reaching the .js files specified in the routes.
Here is a JSFiddle of the event.
https://jsfiddle.net/5n0whef7/1/
Essentially in the serve.js file, it's looping through my routes, finds a matching route, and then returns the route after the matching route as the value.
If the req.url is "/api/auth", then the right route is returned. If the req.url is "/api/auth/signin", then the .find() function returns the wrong value.
I was looking at the code and I can't saw nowhere the method send
of supertest lib, I guess without that it is not possible to test the POST method right? Can you provide some examples how do you test the POST methods?
Thanks for advance.
Hey, @Meesayen, perhaps we can work on a pull-request to add TypeScript support based on your fork? Thanks for the work, by the way ;)
It would be great to support the @now/node@canary
builder. For the purpose of this simulator that should be easy since it will simply do the same thing as @now/node
here I think.
I can make a PR if you're open to this idea.
Would totally understand if you don't want to bother with this, but for those of us not well versed in Regex would it be possible to add //comments in the code explaining what's happening here. Or maybe just comments here if you don't want them in the code. Thank you!
Found in lib/commands/serve.js
req.url.match(new RegExp(
^${src.replace(/(?<[a-z]+>/, '(')}$))
dest.replace(new RegExp('\\$' + id),
$+{${id}})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.