diff --git a/tests/integration/buildcmd/build_integ_base.py b/tests/integration/buildcmd/build_integ_base.py index 3cc1e66f1d..13ba14f310 100644 --- a/tests/integration/buildcmd/build_integ_base.py +++ b/tests/integration/buildcmd/build_integ_base.py @@ -328,13 +328,18 @@ class BuildIntegEsbuildBase(BuildIntegBase): FUNCTION_LOGICAL_ID = "Function" # Everything should be minifed to one line and a second line for the sourcemap mapping MAX_MINIFIED_LINE_COUNT = 2 + MANIFEST_PATH: Optional[str] = None def _test_with_default_package_json( self, runtime, use_container, code_uri, expected_files, handler, architecture=None, build_in_source=None ): overrides = self.get_override(runtime, code_uri, architecture, handler) + manifest_path = str(Path(self.test_data_path, self.MANIFEST_PATH)) if self.MANIFEST_PATH else None cmdlist = self.get_command_list( - use_container=use_container, parameter_overrides=overrides, build_in_source=build_in_source + use_container=use_container, + parameter_overrides=overrides, + build_in_source=build_in_source, + manifest_path=manifest_path, ) LOG.info("Running Command: {}".format(cmdlist)) @@ -416,12 +421,17 @@ def _verify_built_artifact(self, build_dir, function_logical_id, expected_files) class BuildIntegNodeBase(BuildIntegBase): EXPECTED_FILES_PROJECT_MANIFEST = {"node_modules", "main.js"} EXPECTED_NODE_MODULES = {"minimal-request-promise"} - + CODE_URI = "Node" FUNCTION_LOGICAL_ID = "Function" + TEST_INVOKE = False + MANIFEST_PATH: Optional[str] = None def _test_with_default_package_json(self, runtime, use_container, relative_path, architecture=None): - overrides = self.get_override(runtime, "Node", architecture, "ignored") - cmdlist = self.get_command_list(use_container=use_container, parameter_overrides=overrides) + overrides = self.get_override(runtime, self.CODE_URI, architecture, "main.lambdaHandler") + manifest_path = str(Path(self.test_data_path, self.MANIFEST_PATH)) if self.MANIFEST_PATH else None + cmdlist = self.get_command_list( + use_container=use_container, parameter_overrides=overrides, manifest_path=manifest_path + ) LOG.info("Running Command: {}".format(cmdlist)) run_command(cmdlist, cwd=self.working_dir) @@ -433,6 +443,12 @@ def _test_with_default_package_json(self, runtime, use_container, relative_path, self.EXPECTED_NODE_MODULES, ) + expected = {"body": '{"message":"hello world!"}', "statusCode": 200} + if not SKIP_DOCKER_TESTS and self.TEST_INVOKE: + self._verify_invoke_built_function( + self.built_template, self.FUNCTION_LOGICAL_ID, self._make_parameter_override_arg(overrides), expected + ) + self._verify_resource_property( str(self.built_template), "OtherRelativePathResource", diff --git a/tests/integration/buildcmd/test_build_cmd.py b/tests/integration/buildcmd/test_build_cmd.py index 394964c4af..1a22c9cbb7 100644 --- a/tests/integration/buildcmd/test_build_cmd.py +++ b/tests/integration/buildcmd/test_build_cmd.py @@ -570,6 +570,23 @@ def test_building_default_package_json(self, runtime, use_container): self._test_with_default_package_json(runtime, use_container, self.test_data_path) +class TestBuildCommand_NodeFunctions_With_External_Manifest(BuildIntegNodeBase): + CODE_URI = "Node_without_manifest" + TEST_INVOKE = True + MANIFEST_PATH = "npm_manifest/package.json" + + @parameterized.expand( + [ + ("nodejs14.x",), + ("nodejs16.x",), + ("nodejs18.x",), + ] + ) + @pytest.mark.flaky(reruns=3) + def test_building_default_package_json(self, runtime): + self._test_with_default_package_json(runtime, False, self.test_data_path) + + class TestBuildCommand_EsbuildFunctions(BuildIntegEsbuildBase): template = "template_with_metadata_esbuild.yaml" @@ -608,6 +625,71 @@ def test_building_default_package_json( self._test_with_default_package_json(runtime, use_container, code_uri, expected_files, handler, architecture) +class TestBuildCommand_EsbuildFunctions_With_External_Manifest(BuildIntegEsbuildBase): + template = "template_with_metadata_esbuild.yaml" + MANIFEST_PATH = "Esbuild/npm_manifest/package.json" + + @parameterized.expand( + [ + ( + "nodejs14.x", + "Esbuild/Node_without_manifest", + {"main.js", "main.js.map"}, + "main.lambdaHandler", + False, + "x86_64", + ), + ( + "nodejs16.x", + "Esbuild/Node_without_manifest", + {"main.js", "main.js.map"}, + "main.lambdaHandler", + False, + "arm64", + ), + ( + "nodejs18.x", + "Esbuild/Node_without_manifest", + {"main.js", "main.js.map"}, + "main.lambdaHandler", + False, + "arm64", + ), + ( + "nodejs14.x", + "Esbuild/TypeScript_without_manifest", + {"app.js", "app.js.map"}, + "app.lambdaHandler", + False, + "x86_64", + ), + ( + "nodejs16.x", + "Esbuild/TypeScript_without_manifest", + {"app.js", "app.js.map"}, + "app.lambdaHandler", + False, + "arm64", + ), + ( + "nodejs18.x", + "Esbuild/TypeScript_without_manifest", + {"app.js", "app.js.map"}, + "app.lambdaHandler", + False, + "arm64", + ), + ] + ) + @pytest.mark.flaky(reruns=3) + def test_building_default_package_json( + self, runtime, code_uri, expected_files, handler, use_container, architecture + ): + if use_container and (SKIP_DOCKER_TESTS or SKIP_DOCKER_BUILD): + self.skipTest(SKIP_DOCKER_MESSAGE) + self._test_with_default_package_json(runtime, use_container, code_uri, expected_files, handler, architecture) + + @skipIf( ((IS_WINDOWS and RUNNING_ON_CI) and not CI_OVERRIDE), "Skip build tests on windows when running in CI unless overridden", diff --git a/tests/integration/testdata/buildcmd/Esbuild/Node_without_manifest/main.js b/tests/integration/testdata/buildcmd/Esbuild/Node_without_manifest/main.js new file mode 100644 index 0000000000..5ba65da324 --- /dev/null +++ b/tests/integration/testdata/buildcmd/Esbuild/Node_without_manifest/main.js @@ -0,0 +1,8 @@ +exports.lambdaHandler = async (event, context) => { + return { + statusCode: 200, + body: JSON.stringify({ + message: 'hello world!', + }), + }; +}; diff --git a/tests/integration/testdata/buildcmd/Esbuild/TypeScript_without_manifest/app.ts b/tests/integration/testdata/buildcmd/Esbuild/TypeScript_without_manifest/app.ts new file mode 100644 index 0000000000..84ffc9ea30 --- /dev/null +++ b/tests/integration/testdata/buildcmd/Esbuild/TypeScript_without_manifest/app.ts @@ -0,0 +1,24 @@ +import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'; + +export const lambdaHandler = async (event: APIGatewayProxyEvent): Promise => { + let response: APIGatewayProxyResult; + + try { + response = { + statusCode: 200, + body: JSON.stringify({ + message: 'hello world!', + }), + }; + } catch (err) { + console.log(err); + response = { + statusCode: 500, + body: JSON.stringify({ + message: 'some error happened', + }), + }; + } + + return response; +}; diff --git a/tests/integration/testdata/buildcmd/Esbuild/TypeScript_without_manifest/nested/function/app.ts b/tests/integration/testdata/buildcmd/Esbuild/TypeScript_without_manifest/nested/function/app.ts new file mode 100644 index 0000000000..84ffc9ea30 --- /dev/null +++ b/tests/integration/testdata/buildcmd/Esbuild/TypeScript_without_manifest/nested/function/app.ts @@ -0,0 +1,24 @@ +import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'; + +export const lambdaHandler = async (event: APIGatewayProxyEvent): Promise => { + let response: APIGatewayProxyResult; + + try { + response = { + statusCode: 200, + body: JSON.stringify({ + message: 'hello world!', + }), + }; + } catch (err) { + console.log(err); + response = { + statusCode: 500, + body: JSON.stringify({ + message: 'some error happened', + }), + }; + } + + return response; +}; diff --git a/tests/integration/testdata/buildcmd/Esbuild/npm_manifest/package.json b/tests/integration/testdata/buildcmd/Esbuild/npm_manifest/package.json new file mode 100644 index 0000000000..f7ad41fae9 --- /dev/null +++ b/tests/integration/testdata/buildcmd/Esbuild/npm_manifest/package.json @@ -0,0 +1,14 @@ +{ + "name": "npmdeps", + "version": "1.0.0", + "description": "", + "keywords": [], + "author": "", + "license": "APACHE2.0", + "main": "main.js", + "dependencies": { + "@types/aws-lambda": "^8.10.92", + "minimal-request-promise": "*", + "esbuild": "^0.14.14" + } +} \ No newline at end of file diff --git a/tests/integration/testdata/buildcmd/Node_without_manifest/main.js b/tests/integration/testdata/buildcmd/Node_without_manifest/main.js new file mode 100644 index 0000000000..1e03a33abc --- /dev/null +++ b/tests/integration/testdata/buildcmd/Node_without_manifest/main.js @@ -0,0 +1,13 @@ + +exports.lambdaHandler = async (event, context) => { + return { + statusCode: 200, + body: JSON.stringify({ + message: 'hello world!', + }), + } +}; + +exports.secondLambdaHandler = async (event, context) => { + return 'Hello Mars' +}; \ No newline at end of file diff --git a/tests/integration/testdata/buildcmd/npm_manifest/package.json b/tests/integration/testdata/buildcmd/npm_manifest/package.json new file mode 100644 index 0000000000..c95b709aec --- /dev/null +++ b/tests/integration/testdata/buildcmd/npm_manifest/package.json @@ -0,0 +1,11 @@ +{ + "name": "npmdeps", + "version": "1.0.0", + "description": "", + "keywords": [], + "author": "", + "license": "APACHE2.0", + "dependencies": { + "minimal-request-promise": "*" + } +} \ No newline at end of file