From 7bfd4eab9dd96822e2f416abdc57d82a7b7b36b7 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 29 May 2024 12:08:30 +0200 Subject: [PATCH] feat: add `timeout` config prop for functions (#5683) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Antonio Rodríguez Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/zip-it-and-ship-it/src/config.ts | 1 + packages/zip-it-and-ship-it/src/main.ts | 2 + packages/zip-it-and-ship-it/src/manifest.ts | 3 + .../runtimes/node/in_source_config/index.ts | 5 + .../src/runtimes/node/index.ts | 8 +- .../src/runtimes/runtime.ts | 1 + .../__snapshots__/list_function.test.ts.snap | 1 + .../__snapshots__/list_functions.test.ts.snap | 25 +++++ .../list_functions_files.test.ts.snap | 94 +++++++++++++++++++ .../.netlify/functions-internal/server.json | 3 +- .../.netlify/functions-internal/server.mjs | 1 + .../runtimes/node/in_source_config.test.ts | 14 +++ .../zip-it-and-ship-it/tests/v2api.test.ts | 10 +- 13 files changed, 165 insertions(+), 3 deletions(-) diff --git a/packages/zip-it-and-ship-it/src/config.ts b/packages/zip-it-and-ship-it/src/config.ts index b364ad1c30..21109a192b 100644 --- a/packages/zip-it-and-ship-it/src/config.ts +++ b/packages/zip-it-and-ship-it/src/config.ts @@ -22,6 +22,7 @@ interface FunctionConfig { zipGo?: boolean name?: string generator?: string + timeout?: number // Temporary configuration property, only meant to be used by the deploy // configuration API. Once we start emitting ESM files for all ESM functions, diff --git a/packages/zip-it-and-ship-it/src/main.ts b/packages/zip-it-and-ship-it/src/main.ts index 17481ee4a6..7ae4afdcf3 100644 --- a/packages/zip-it-and-ship-it/src/main.ts +++ b/packages/zip-it-and-ship-it/src/main.ts @@ -29,6 +29,7 @@ export interface ListedFunction { schedule?: string displayName?: string generator?: string + timeout?: number inputModuleFormat?: ModuleFormat } @@ -151,6 +152,7 @@ const getListedFunction = function ({ displayName: config.name, extension, generator: config.generator, + timeout: config.timeout, mainFile, name, runtime: runtime.name, diff --git a/packages/zip-it-and-ship-it/src/manifest.ts b/packages/zip-it-and-ship-it/src/manifest.ts index cc33379888..76a7a2e6b8 100644 --- a/packages/zip-it-and-ship-it/src/manifest.ts +++ b/packages/zip-it-and-ship-it/src/manifest.ts @@ -38,6 +38,7 @@ interface ManifestFunction { displayName?: string bundler?: string generator?: string + timeout?: number priority?: number trafficRules?: TrafficRules } @@ -81,11 +82,13 @@ const formatFunctionForManifest = ({ runtimeVersion, runtimeAPIVersion, schedule, + timeout, }: FunctionResult): ManifestFunction => { const manifestFunction: ManifestFunction = { bundler, displayName, generator, + timeout, invocationMode, buildData: { runtimeAPIVersion }, mainFile, diff --git a/packages/zip-it-and-ship-it/src/runtimes/node/in_source_config/index.ts b/packages/zip-it-and-ship-it/src/runtimes/node/in_source_config/index.ts index ebb2c1d235..5b9e0f51c5 100644 --- a/packages/zip-it-and-ship-it/src/runtimes/node/in_source_config/index.ts +++ b/packages/zip-it-and-ship-it/src/runtimes/node/in_source_config/index.ts @@ -25,6 +25,7 @@ export type ISCValues = { trafficRules?: TrafficRules name?: string generator?: string + timeout?: number } export interface StaticAnalysisResult extends ISCValues { @@ -187,6 +188,10 @@ export const parseSource = (source: string, { functionName }: FindISCDeclaration result.generator = configExport.generator } + if (typeof configExport.timeout === 'number') { + result.timeout = configExport.timeout + } + if (configExport.method !== undefined) { result.methods = normalizeMethods(configExport.method, functionName) } diff --git a/packages/zip-it-and-ship-it/src/runtimes/node/index.ts b/packages/zip-it-and-ship-it/src/runtimes/node/index.ts index 286ba3fa42..6502860790 100644 --- a/packages/zip-it-and-ship-it/src/runtimes/node/index.ts +++ b/packages/zip-it-and-ship-it/src/runtimes/node/index.ts @@ -141,7 +141,12 @@ const zipFunction: ZipFunction = async function ({ invocationMode = INVOCATION_MODE.Background } - const { trafficRules, generator: staticAnalysisGenerator, name: staticAnalysisName } = staticAnalysisResult + const { + trafficRules, + generator: staticAnalysisGenerator, + name: staticAnalysisName, + timeout: staticAnalysisTimeout, + } = staticAnalysisResult const outputModuleFormat = extname(finalMainFile) === MODULE_FILE_EXTENSION.MJS ? MODULE_FORMAT.ESM : MODULE_FORMAT.COMMONJS @@ -154,6 +159,7 @@ const zipFunction: ZipFunction = async function ({ displayName: staticAnalysisName || config?.name, entryFilename: zipPath.entryFilename, generator: staticAnalysisGenerator || config?.generator || getInternalValue(isInternal), + timeout: staticAnalysisTimeout || config?.timeout, inputs, includedFiles, staticAnalysisResult, diff --git a/packages/zip-it-and-ship-it/src/runtimes/runtime.ts b/packages/zip-it-and-ship-it/src/runtimes/runtime.ts index 3121b16639..9a9c830b22 100644 --- a/packages/zip-it-and-ship-it/src/runtimes/runtime.ts +++ b/packages/zip-it-and-ship-it/src/runtimes/runtime.ts @@ -48,6 +48,7 @@ export interface ZipFunctionResult { config: FunctionConfig displayName?: string generator?: string + timeout?: number inputs?: string[] includedFiles?: string[] invocationMode?: InvocationMode diff --git a/packages/zip-it-and-ship-it/tests/__snapshots__/list_function.test.ts.snap b/packages/zip-it-and-ship-it/tests/__snapshots__/list_function.test.ts.snap index 0d9ea4af5a..f17f9e932e 100644 --- a/packages/zip-it-and-ship-it/tests/__snapshots__/list_function.test.ts.snap +++ b/packages/zip-it-and-ship-it/tests/__snapshots__/list_function.test.ts.snap @@ -12,5 +12,6 @@ exports[`listFunction > V2 API > listFunction includes metadata properties when "runtimeAPIVersion": 2, "schedule": undefined, "srcFile": undefined, + "timeout": undefined, } `; diff --git a/packages/zip-it-and-ship-it/tests/__snapshots__/list_functions.test.ts.snap b/packages/zip-it-and-ship-it/tests/__snapshots__/list_functions.test.ts.snap index 84151c15f3..81328c760c 100644 --- a/packages/zip-it-and-ship-it/tests/__snapshots__/list_functions.test.ts.snap +++ b/packages/zip-it-and-ship-it/tests/__snapshots__/list_functions.test.ts.snap @@ -12,6 +12,7 @@ exports[`listFunctions > V2 API > listFunctions includes runtimeAPIVersion when "runtimeAPIVersion": 2, "schedule": undefined, "srcFile": undefined, + "timeout": undefined, } `; @@ -28,6 +29,7 @@ exports[`listFunctions > v1 > Can list function main files from multiple source "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -40,6 +42,7 @@ exports[`listFunctions > v1 > Can list function main files from multiple source "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -52,6 +55,7 @@ exports[`listFunctions > v1 > Can list function main files from multiple source "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -64,6 +68,7 @@ exports[`listFunctions > v1 > Can list function main files from multiple source "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": undefined, + "timeout": undefined, }, ] `; @@ -81,6 +86,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions() "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -93,6 +99,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions() "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -105,6 +112,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions() "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -117,6 +125,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions() "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -129,6 +138,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions() "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -141,6 +151,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions() "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -153,6 +164,7 @@ exports[`listFunctions > v1 > Can list function main files with listFunctions() "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": undefined, + "timeout": undefined, }, ] `; @@ -170,6 +182,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio "runtimeAPIVersion": 1, "schedule": "@daily", "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -182,6 +195,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio "runtimeAPIVersion": 1, "schedule": "@daily", "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -194,6 +208,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio "runtimeAPIVersion": 1, "schedule": "@daily", "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -206,6 +221,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio "runtimeAPIVersion": 1, "schedule": "@daily", "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -218,6 +234,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio "runtimeAPIVersion": 1, "schedule": "@daily", "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -230,6 +247,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio "runtimeAPIVersion": 1, "schedule": "@daily", "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -242,6 +260,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio "runtimeAPIVersion": 1, "schedule": "@daily", "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -254,6 +273,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio "runtimeAPIVersion": 1, "schedule": "@daily", "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -266,6 +286,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio "runtimeAPIVersion": 1, "schedule": "@daily", "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -278,6 +299,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio "runtimeAPIVersion": 1, "schedule": "@daily", "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -290,6 +312,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio "runtimeAPIVersion": 1, "schedule": "@daily", "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -302,6 +325,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio "runtimeAPIVersion": 1, "schedule": "@daily", "srcFile": undefined, + "timeout": undefined, }, { "displayName": undefined, @@ -314,6 +338,7 @@ exports[`listFunctions > v1 > listFunctions includes in-source config declaratio "runtimeAPIVersion": 1, "schedule": "@daily", "srcFile": undefined, + "timeout": undefined, }, ] `; diff --git a/packages/zip-it-and-ship-it/tests/__snapshots__/list_functions_files.test.ts.snap b/packages/zip-it-and-ship-it/tests/__snapshots__/list_functions_files.test.ts.snap index d05afadc03..702414cd7c 100644 --- a/packages/zip-it-and-ship-it/tests/__snapshots__/list_functions_files.test.ts.snap +++ b/packages/zip-it-and-ship-it/tests/__snapshots__/list_functions_files.test.ts.snap @@ -13,6 +13,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": ".netlify/internal-functions/function.js", + "timeout": undefined, }, { "displayName": undefined, @@ -25,6 +26,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -37,6 +39,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/package.json", + "timeout": undefined, }, { "displayName": undefined, @@ -49,6 +52,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": ".netlify/internal-functions/function_internal.js", + "timeout": undefined, }, { "displayName": undefined, @@ -61,6 +65,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -73,6 +78,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/package.json", + "timeout": undefined, }, { "displayName": undefined, @@ -85,6 +91,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "netlify/functions/function.js", + "timeout": undefined, }, { "displayName": undefined, @@ -97,6 +104,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -109,6 +117,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/package.json", + "timeout": undefined, }, { "displayName": undefined, @@ -121,6 +130,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "netlify/functions/function_user.js", + "timeout": undefined, }, { "displayName": undefined, @@ -133,6 +143,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -145,6 +156,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/package.json", + "timeout": undefined, }, ] `; @@ -162,6 +174,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": ".netlify/internal-functions/function.js", + "timeout": undefined, }, { "displayName": undefined, @@ -174,6 +187,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -186,6 +200,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/package.json", + "timeout": undefined, }, { "displayName": undefined, @@ -198,6 +213,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": ".netlify/internal-functions/function_internal.js", + "timeout": undefined, }, { "displayName": undefined, @@ -210,6 +226,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -222,6 +239,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/package.json", + "timeout": undefined, }, { "displayName": undefined, @@ -234,6 +252,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "netlify/functions/function.js", + "timeout": undefined, }, { "displayName": undefined, @@ -246,6 +265,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -258,6 +278,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/package.json", + "timeout": undefined, }, { "displayName": undefined, @@ -270,6 +291,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "netlify/functions/function_user.js", + "timeout": undefined, }, { "displayName": undefined, @@ -282,6 +304,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -294,6 +317,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/package.json", + "timeout": undefined, }, ] `; @@ -311,6 +335,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": ".netlify/internal-functions/function.js", + "timeout": undefined, }, { "displayName": undefined, @@ -323,6 +348,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": ".netlify/internal-functions/function_internal.js", + "timeout": undefined, }, { "displayName": undefined, @@ -335,6 +361,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "netlify/functions/function.js", + "timeout": undefined, }, { "displayName": undefined, @@ -347,6 +374,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "netlify/functions/function_user.js", + "timeout": undefined, }, ] `; @@ -364,6 +392,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": ".netlify/internal-functions/function.js", + "timeout": undefined, }, { "displayName": undefined, @@ -376,6 +405,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": ".netlify/internal-functions/function_internal.js", + "timeout": undefined, }, { "displayName": undefined, @@ -388,6 +418,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "netlify/functions/function.js", + "timeout": undefined, }, { "displayName": undefined, @@ -400,6 +431,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "netlify/functions/function_user.js", + "timeout": undefined, }, ] `; @@ -417,6 +449,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": ".netlify/internal-functions/function.js", + "timeout": undefined, }, { "displayName": undefined, @@ -429,6 +462,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -441,6 +475,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/package.json", + "timeout": undefined, }, { "displayName": undefined, @@ -453,6 +488,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": ".netlify/internal-functions/function_internal.js", + "timeout": undefined, }, { "displayName": undefined, @@ -465,6 +501,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -477,6 +514,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/package.json", + "timeout": undefined, }, { "displayName": undefined, @@ -489,6 +527,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "netlify/functions/function.js", + "timeout": undefined, }, { "displayName": undefined, @@ -501,6 +540,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -513,6 +553,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/package.json", + "timeout": undefined, }, { "displayName": undefined, @@ -525,6 +566,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "netlify/functions/function_user.js", + "timeout": undefined, }, { "displayName": undefined, @@ -537,6 +579,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -549,6 +592,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "node_modules/test/package.json", + "timeout": undefined, }, ] `; @@ -566,6 +610,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": ".netlify/internal-functions/function.js", + "timeout": undefined, }, { "displayName": undefined, @@ -578,6 +623,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": ".netlify/internal-functions/function_internal.js", + "timeout": undefined, }, { "displayName": undefined, @@ -590,6 +636,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "netlify/functions/function.js", + "timeout": undefined, }, { "displayName": undefined, @@ -602,6 +649,7 @@ exports[`listFunctionsFiles > Can list all function files from multiple source d "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "netlify/functions/function_user.js", + "timeout": undefined, }, ] `; @@ -619,6 +667,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test.zip", + "timeout": undefined, }, { "displayName": undefined, @@ -631,6 +680,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test.js", + "timeout": undefined, }, { "displayName": undefined, @@ -643,6 +693,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "five/index.ts", + "timeout": undefined, }, { "displayName": undefined, @@ -655,6 +706,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "four.js/four.js.js", + "timeout": undefined, }, { "displayName": undefined, @@ -667,6 +719,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "one/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -679,6 +732,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "two/three.json", + "timeout": undefined, }, { "displayName": undefined, @@ -691,6 +745,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "two/two.js", + "timeout": undefined, }, { "displayName": undefined, @@ -703,6 +758,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test", + "timeout": undefined, }, ] `; @@ -720,6 +776,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test.zip", + "timeout": undefined, }, { "displayName": undefined, @@ -732,6 +789,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test.js", + "timeout": undefined, }, { "displayName": undefined, @@ -744,6 +802,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "five/index.ts", + "timeout": undefined, }, { "displayName": undefined, @@ -756,6 +815,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "four.js/four.js.js", + "timeout": undefined, }, { "displayName": undefined, @@ -768,6 +828,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "one/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -780,6 +841,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "two/two.js", + "timeout": undefined, }, { "displayName": undefined, @@ -792,6 +854,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "two/three.json", + "timeout": undefined, }, { "displayName": undefined, @@ -804,6 +867,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test", + "timeout": undefined, }, ] `; @@ -821,6 +885,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test.zip", + "timeout": undefined, }, { "displayName": undefined, @@ -833,6 +898,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test.js", + "timeout": undefined, }, { "displayName": undefined, @@ -845,6 +911,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "five/index.ts", + "timeout": undefined, }, { "displayName": undefined, @@ -857,6 +924,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "four.js/four.js.js", + "timeout": undefined, }, { "displayName": undefined, @@ -869,6 +937,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "one/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -881,6 +950,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "two/two.js", + "timeout": undefined, }, { "displayName": undefined, @@ -893,6 +963,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test", + "timeout": undefined, }, ] `; @@ -910,6 +981,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test.zip", + "timeout": undefined, }, { "displayName": undefined, @@ -922,6 +994,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test.js", + "timeout": undefined, }, { "displayName": undefined, @@ -934,6 +1007,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "five/index.ts", + "timeout": undefined, }, { "displayName": undefined, @@ -946,6 +1020,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "four.js/four.js.js", + "timeout": undefined, }, { "displayName": undefined, @@ -958,6 +1033,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "one/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -970,6 +1046,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "two/two.js", + "timeout": undefined, }, { "displayName": undefined, @@ -982,6 +1059,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test", + "timeout": undefined, }, ] `; @@ -999,6 +1077,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test.zip", + "timeout": undefined, }, { "displayName": undefined, @@ -1011,6 +1090,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test.js", + "timeout": undefined, }, { "displayName": undefined, @@ -1023,6 +1103,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "five/index.ts", + "timeout": undefined, }, { "displayName": undefined, @@ -1035,6 +1116,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "five/util.ts", + "timeout": undefined, }, { "displayName": undefined, @@ -1047,6 +1129,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "four.js/four.js.js", + "timeout": undefined, }, { "displayName": undefined, @@ -1059,6 +1142,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "one/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -1071,6 +1155,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "two/two.js", + "timeout": undefined, }, { "displayName": undefined, @@ -1083,6 +1168,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "two/three.json", + "timeout": undefined, }, { "displayName": undefined, @@ -1095,6 +1181,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test", + "timeout": undefined, }, ] `; @@ -1112,6 +1199,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test.zip", + "timeout": undefined, }, { "displayName": undefined, @@ -1124,6 +1212,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test.js", + "timeout": undefined, }, { "displayName": undefined, @@ -1136,6 +1225,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "five/index.ts", + "timeout": undefined, }, { "displayName": undefined, @@ -1148,6 +1238,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "four.js/four.js.js", + "timeout": undefined, }, { "displayName": undefined, @@ -1160,6 +1251,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "one/index.js", + "timeout": undefined, }, { "displayName": undefined, @@ -1172,6 +1264,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "two/two.js", + "timeout": undefined, }, { "displayName": undefined, @@ -1184,6 +1277,7 @@ exports[`listFunctionsFiles > Can list all function files with listFunctionsFile "runtimeAPIVersion": undefined, "schedule": undefined, "srcFile": "test", + "timeout": undefined, }, ] `; diff --git a/packages/zip-it-and-ship-it/tests/fixtures-esm/v2-api-name-generator/.netlify/functions-internal/server.json b/packages/zip-it-and-ship-it/tests/fixtures-esm/v2-api-name-generator/.netlify/functions-internal/server.json index 27f7bfdc7b..f892dff1f6 100644 --- a/packages/zip-it-and-ship-it/tests/fixtures-esm/v2-api-name-generator/.netlify/functions-internal/server.json +++ b/packages/zip-it-and-ship-it/tests/fixtures-esm/v2-api-name-generator/.netlify/functions-internal/server.json @@ -1,7 +1,8 @@ { "config": { "name": "should not be respected, ISC takes precedence", - "generator": "should not be respected, ISC takes precedence" + "generator": "should not be respected, ISC takes precedence", + "timeout": 30 }, "version": 1 } diff --git a/packages/zip-it-and-ship-it/tests/fixtures-esm/v2-api-name-generator/.netlify/functions-internal/server.mjs b/packages/zip-it-and-ship-it/tests/fixtures-esm/v2-api-name-generator/.netlify/functions-internal/server.mjs index fd82de5f8f..c6a9c555ef 100644 --- a/packages/zip-it-and-ship-it/tests/fixtures-esm/v2-api-name-generator/.netlify/functions-internal/server.mjs +++ b/packages/zip-it-and-ship-it/tests/fixtures-esm/v2-api-name-generator/.netlify/functions-internal/server.mjs @@ -3,4 +3,5 @@ export default () => new Response('hello world') export const config = { name: 'SSR Function', generator: 'next-runtime@1.2.3', + timeout: 60, } diff --git a/packages/zip-it-and-ship-it/tests/unit/runtimes/node/in_source_config.test.ts b/packages/zip-it-and-ship-it/tests/unit/runtimes/node/in_source_config.test.ts index 5f7a3d1888..19b031525f 100644 --- a/packages/zip-it-and-ship-it/tests/unit/runtimes/node/in_source_config.test.ts +++ b/packages/zip-it-and-ship-it/tests/unit/runtimes/node/in_source_config.test.ts @@ -718,4 +718,18 @@ describe('V2 API', () => { generator: 'bar@1.2.3', }) }) + + test('Understands timeout', () => { + const source = ` + export default async () => new Response("Hello!") + export const config = { timeout: 60 }` + + const isc = parseSource(source, options) + expect(isc).toEqual({ + inputModuleFormat: 'esm', + routes: [], + runtimeAPIVersion: 2, + timeout: 60, + }) + }) }) diff --git a/packages/zip-it-and-ship-it/tests/v2api.test.ts b/packages/zip-it-and-ship-it/tests/v2api.test.ts index 859d4be115..467d2369d3 100644 --- a/packages/zip-it-and-ship-it/tests/v2api.test.ts +++ b/packages/zip-it-and-ship-it/tests/v2api.test.ts @@ -529,7 +529,7 @@ describe.runIf(semver.gte(nodeVersion, '18.13.0'))('V2 functions API', () => { }) }) - test('Name and Generator are taken from ISC and take precedence over deploy config', async () => { + test('Name, Generator and Timeout are taken from ISC and take precedence over deploy config', async () => { const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test' }) const manifestPath = join(tmpDir, 'manifest.json') @@ -548,7 +548,15 @@ describe.runIf(semver.gte(nodeVersion, '18.13.0'))('V2 functions API', () => { }) expect(func.displayName).toBe('SSR Function') + expect(func.timeout).toBe(60) expect(func.generator).toBe('next-runtime@1.2.3') + + const manifestString = await readFile(manifestPath, { encoding: 'utf8' }) + const manifest = JSON.parse(manifestString) + expect(manifest.functions).toHaveLength(1) + expect(manifest.functions[0].timeout).toEqual(60) + expect(manifest.functions[0].displayName).toEqual('SSR Function') + expect(manifest.functions[0].generator).toEqual('next-runtime@1.2.3') }) testMany(