Ignore tests in lambda folder
davesag opened this issue · 6 comments
I'm just setting my lambda functions and have the following directory structure
src/
lambda/
hello.js
hello.test.js
Which follows how the rest of the app gets tested.
Unfortunately this means running netlify-lambda build src/lambda
results in my tests also being built and installed as if they are lambda functions.
Is there a way to exclude all *.test.js
or *.spec.js
files?
for now I work around this by simply adding this script in package.json
"lambda:build": "netlify-lambda build src/lambda",
"postlambda:build": "rm lambda/*.test.js",
but it would be nicer to exclude them during the lambda:build
step.
Somewhat unrelated but since you're using Webpack it might be helpful.. I stumbled upon this issue a while back and a couple days ago I added a way to resolve it within 8eecf0d2/netlify-local by allowing users to specify a files
array which can be used to compose a Webpack Configuration entry
property.
The bundle command docs probably give the best description of how it works, it also flattens nested handlers by replacing forward slashes with dashes (eg, "lambda/nested/handler.js" => "lambda-nested-handler.js"
).
You can use the logic programatically like so:
const netlifyLocal = require("netlify-local");
const netlifyConfig = netlifyLocal.parseNetlifyConfig("netlify.toml");
module.exports = {
entry: netlifyLocal.composeWebpackEntry(netlifyConfig),
...
}
As far as the issue itself goes, it's a bit of a pain this is the same behaviour as production - to request changes in the production environment you'll need to talk to Netlify Support.
@sw-yx is there a specific / technical support link I should be promoting?
hey @davesag , the really really easy way to do this is just dont put the lambda folder in src
:) you can put it in a foobar
folder if you like. just change your netlify serve _____
and netlify build _____
command accordingly
in fact i really dislike encouraging people to colocate lambda functions and client code. causes potential confusion. problem is we've been recommending it for a while.