Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions aws_lambda_builders/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
SUPPORTED_RUNTIMES = {
"nodejs12.x": [ARM64, X86_64],
"nodejs14.x": [ARM64, X86_64],
"nodejs16.x": [ARM64, X86_64],
"python3.6": [X86_64],
"python3.7": [X86_64],
"python3.8": [ARM64, X86_64],
Expand Down
72 changes: 47 additions & 25 deletions tests/integration/workflows/nodejs_npm/test_nodejs_npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,30 @@ def setUp(self):
self.no_deps = os.path.join(self.TEST_DATA_FOLDER, "no-deps")

self.builder = LambdaBuilder(language="nodejs", dependency_manager="npm", application_framework=None)
self.runtime = "nodejs12.x"

def tearDown(self):
shutil.rmtree(self.artifacts_dir)
shutil.rmtree(self.scratch_dir)
shutil.rmtree(self.dependencies_dir)

def test_builds_project_without_dependencies(self):
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)])
def test_builds_project_without_dependencies(self, runtime):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "no-deps")

self.builder.build(
source_dir,
self.artifacts_dir,
self.scratch_dir,
os.path.join(source_dir, "package.json"),
runtime=self.runtime,
runtime=runtime,
)

expected_files = {"package.json", "included.js"}
output_files = set(os.listdir(self.artifacts_dir))
self.assertEqual(expected_files, output_files)

def test_builds_project_without_manifest(self):
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)])
def test_builds_project_without_manifest(self, runtime):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "no-manifest")

with mock.patch.object(logger, "warning") as mock_warning:
Expand All @@ -60,38 +61,40 @@ def test_builds_project_without_manifest(self):
self.artifacts_dir,
self.scratch_dir,
os.path.join(source_dir, "package.json"),
runtime=self.runtime,
runtime=runtime,
)

expected_files = {"app.js"}
output_files = set(os.listdir(self.artifacts_dir))
mock_warning.assert_called_once_with("package.json file not found. Continuing the build without dependencies.")
self.assertEqual(expected_files, output_files)

def test_builds_project_and_excludes_hidden_aws_sam(self):
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)])
def test_builds_project_and_excludes_hidden_aws_sam(self, runtime):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "excluded-files")

self.builder.build(
source_dir,
self.artifacts_dir,
self.scratch_dir,
os.path.join(source_dir, "package.json"),
runtime=self.runtime,
runtime=runtime,
)

expected_files = {"package.json", "included.js"}
output_files = set(os.listdir(self.artifacts_dir))
self.assertEqual(expected_files, output_files)

def test_builds_project_with_remote_dependencies(self):
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)])
def test_builds_project_with_remote_dependencies(self, runtime):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "npm-deps")

self.builder.build(
source_dir,
self.artifacts_dir,
self.scratch_dir,
os.path.join(source_dir, "package.json"),
runtime=self.runtime,
runtime=runtime,
)

expected_files = {"package.json", "included.js", "node_modules"}
Expand All @@ -102,15 +105,16 @@ def test_builds_project_with_remote_dependencies(self):
output_modules = set(os.listdir(os.path.join(self.artifacts_dir, "node_modules")))
self.assertEqual(expected_modules, output_modules)

def test_builds_project_with_npmrc(self):
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)])
def test_builds_project_with_npmrc(self, runtime):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "npmrc")

self.builder.build(
source_dir,
self.artifacts_dir,
self.scratch_dir,
os.path.join(source_dir, "package.json"),
runtime=self.runtime,
runtime=runtime,
)

expected_files = {"package.json", "included.js", "node_modules"}
Expand All @@ -122,8 +126,20 @@ def test_builds_project_with_npmrc(self):
output_modules = set(os.listdir(os.path.join(self.artifacts_dir, "node_modules")))
self.assertEqual(expected_modules, output_modules)

@parameterized.expand(["package-lock", "shrinkwrap", "package-lock-and-shrinkwrap"])
def test_builds_project_with_lockfile(self, dir_name):
@parameterized.expand(
[
("nodejs12.x", "package-lock"),
("nodejs14.x", "package-lock"),
("nodejs16.x", "package-lock"),
("nodejs12.x", "shrinkwrap"),
("nodejs14.x", "shrinkwrap"),
("nodejs16.x", "shrinkwrap"),
("nodejs12.x", "package-lock-and-shrinkwrap"),
("nodejs14.x", "package-lock-and-shrinkwrap"),
("nodejs16.x", "package-lock-and-shrinkwrap"),
]
)
def test_builds_project_with_lockfile(self, runtime, dir_name):
expected_files_common = {"package.json", "included.js", "node_modules"}
expected_files_by_dir_name = {
"package-lock": {"package-lock.json"},
Expand All @@ -138,7 +154,7 @@ def test_builds_project_with_lockfile(self, dir_name):
self.artifacts_dir,
self.scratch_dir,
os.path.join(source_dir, "package.json"),
runtime=self.runtime,
runtime=runtime,
)

expected_files = expected_files_common.union(expected_files_by_dir_name[dir_name])
Expand All @@ -147,8 +163,8 @@ def test_builds_project_with_lockfile(self, dir_name):

self.assertEqual(expected_files, output_files)

def test_fails_if_npm_cannot_resolve_dependencies(self):

@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)])
def test_fails_if_npm_cannot_resolve_dependencies(self, runtime):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "broken-deps")

with self.assertRaises(WorkflowFailedError) as ctx:
Expand All @@ -157,20 +173,21 @@ def test_fails_if_npm_cannot_resolve_dependencies(self):
self.artifacts_dir,
self.scratch_dir,
os.path.join(source_dir, "package.json"),
runtime=self.runtime,
runtime=runtime,
)

self.assertIn("No matching version found for aws-sdk@2.997.999", str(ctx.exception))

def test_builds_project_with_remote_dependencies_without_download_dependencies_with_dependencies_dir(self):
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)])
def test_builds_project_with_remote_dependencies_without_download_dependencies_with_dependencies_dir(self, runtime):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "npm-deps")

self.builder.build(
source_dir,
self.artifacts_dir,
self.scratch_dir,
os.path.join(source_dir, "package.json"),
runtime=self.runtime,
runtime=runtime,
dependencies_dir=self.dependencies_dir,
download_dependencies=False,
)
Expand All @@ -179,15 +196,16 @@ def test_builds_project_with_remote_dependencies_without_download_dependencies_w
output_files = set(os.listdir(self.artifacts_dir))
self.assertEqual(expected_files, output_files)

def test_builds_project_with_remote_dependencies_with_download_dependencies_and_dependencies_dir(self):
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)])
def test_builds_project_with_remote_dependencies_with_download_dependencies_and_dependencies_dir(self, runtime):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "npm-deps")

self.builder.build(
source_dir,
self.artifacts_dir,
self.scratch_dir,
os.path.join(source_dir, "package.json"),
runtime=self.runtime,
runtime=runtime,
dependencies_dir=self.dependencies_dir,
download_dependencies=True,
)
Expand All @@ -208,7 +226,10 @@ def test_builds_project_with_remote_dependencies_with_download_dependencies_and_
output_dependencies_files = set(os.listdir(os.path.join(self.dependencies_dir)))
self.assertNotIn(expected_dependencies_files, output_dependencies_files)

def test_builds_project_with_remote_dependencies_without_download_dependencies_without_dependencies_dir(self):
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)])
def test_builds_project_with_remote_dependencies_without_download_dependencies_without_dependencies_dir(
self, runtime
):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "npm-deps")

with mock.patch.object(logger, "info") as mock_info:
Expand All @@ -217,7 +238,7 @@ def test_builds_project_with_remote_dependencies_without_download_dependencies_w
self.artifacts_dir,
self.scratch_dir,
os.path.join(source_dir, "package.json"),
runtime=self.runtime,
runtime=runtime,
dependencies_dir=None,
download_dependencies=False,
)
Expand All @@ -231,15 +252,16 @@ def test_builds_project_with_remote_dependencies_without_download_dependencies_w
"artifacts directory. "
)

def test_builds_project_without_combine_dependencies(self):
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)])
def test_builds_project_without_combine_dependencies(self, runtime):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "npm-deps")

self.builder.build(
source_dir,
self.artifacts_dir,
self.scratch_dir,
os.path.join(source_dir, "package.json"),
runtime=self.runtime,
runtime=runtime,
dependencies_dir=self.dependencies_dir,
download_dependencies=True,
combine_dependencies=False,
Expand Down
Loading