Skip to content
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

test: test building npm and Typescript projects using external manifest file. #5283

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions tests/integration/buildcmd/build_integ_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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",
Expand Down
67 changes: 67 additions & 0 deletions tests/integration/buildcmd/test_build_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,24 @@ 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(
[
("nodejs12.x",),
("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"

Expand Down Expand Up @@ -576,6 +594,55 @@ 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",
),
(
"nodejs12.x",
moelasmar marked this conversation as resolved.
Show resolved Hide resolved
"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",
),
(
"nodejs12.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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
exports.lambdaHandler = async (event, context) => {
return {
statusCode: 200,
body: JSON.stringify({
message: 'hello world!',
}),
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';

export const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
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;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';

export const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
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;
};
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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'
};
11 changes: 11 additions & 0 deletions tests/integration/testdata/buildcmd/npm_manifest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "npmdeps",
"version": "1.0.0",
"description": "",
"keywords": [],
"author": "",
"license": "APACHE2.0",
"dependencies": {
"minimal-request-promise": "*"
}
}