-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add edge function templates to functions:create command #4731
Conversation
β¦jj/addEdgeFuncTemplate
Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
@eduardoboucas thanks for reviewing! I was also wondering about tests -- I updated the existing tests for the serverless function templates so they match the new workflow (the additional prompt at the beginning) and have tested out the edge function templates a lot manually, but I should probably add a few test cases for the edge function templates too, right? |
Yes, that would be great! |
Added one test, but I wanted to include a case where the user specified a custom edge functions directory as well, something like: test('should use specified edge function directory when found', async (t) => {
const siteInfo = {
admin_url: 'https://app.netlify.com/sites/site-name/overview',
ssl_url: 'https://site-name.netlify.app/',
id: 'site_id',
name: 'site-name',
build_settings: { repo_url: 'https://github.com/owner/repo' },
}
const routes = [
{
path: 'accounts',
response: [{ slug: 'test-account' }],
},
{ path: 'sites/site_id/service-instances', response: [] },
{ path: 'sites/site_id', response: siteInfo },
{
path: 'sites',
response: [siteInfo],
},
{ path: 'sites/site_id', method: 'patch', response: {} },
]
await withSiteBuilder('site-with-custom-edge-functions-dir', async (builder) => {
builder.withNetlifyToml({ config: { build: { edge_functions: 'somethingEdgy' } } })
await builder.buildAsync()
const createFunctionQuestions = [
{
question: "Select the type of function you'd like to create",
answer: answerWithValue(CONFIRM),
},
{
question: 'Select the language of your function',
answer: answerWithValue(CONFIRM),
},
{
question: 'Pick a template',
answer: answerWithValue(CONFIRM),
},
{
question: 'Name your function',
answer: answerWithValue(CONFIRM),
},
{
question: 'What route do you want your edge function to be invoked on?',
answer: answerWithValue('/test'),
},
]
await withMockApi(routes, async ({ apiUrl }) => {
const childProcess = execa(cliPath, ['functions:create'], {
env: {
NETLIFY_API_URL: apiUrl,
NETLIFY_SITE_ID: 'site_id',
NETLIFY_AUTH_TOKEN: 'fake-token',
},
cwd: builder.directory,
})
handleQuestions(childProcess, createFunctionQuestions)
await childProcess
t.is(await fs.fileExistsAsync(`${builder.directory}/somethingEdgy/hello/hello.js`, true))
})
})
}) However, it keeps failing -- I've been trying to debug it for over an hour now and not sure what else to try or how to get more visibility into why it's failing. Manually testing shows if the edge functions directory is configured in the TOML but doesn't exist, it gets created and the templates are added to it. Not sure if I'm missing something here or if this test is necessary π€ |
β¦jj/addEdgeFuncTemplate
π Thanks for submitting a pull request! π
Summary
Summary
Fixes #https://github.com/netlify/pod-compute/issues/99
Adds edge function templates for JS and TS for the functions:create command.
Opened a new PR because my https://github.com/netlify/cli/pull/4689was getting messy, especially after trying to merge changes from main π«
For us to review and ship your PR efficiently, please perform the following steps:
passes our tests.
A picture of a cute animal (not mandatory, but encouraged)