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
4 changes: 2 additions & 2 deletions aws_lambda_builders/workflows/nodejs_npm/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class NodejsNpmrcAndLockfileCopyAction(BaseAction):
"""

NAME = "CopyNpmrcAndLockfile"
DESCRIPTION = "Copying configuration from .npmrc and dependencies from lockfile"
DESCRIPTION = "Copying configuration from .npmrc and dependencies from lockfile/shrinkwrap"
PURPOSE = Purpose.COPY_SOURCE

def __init__(self, artifacts_dir, source_dir, osutils):
Expand Down Expand Up @@ -194,7 +194,7 @@ def execute(self):
"""

try:
for filename in [".npmrc", "package-lock.json"]:
for filename in [".npmrc", "package-lock.json", "npm-shrinkwrap.json"]:
file_path = self.osutils.joinpath(self.source_dir, filename)
if self.osutils.file_exists(file_path):
LOG.debug("%s copying in: %s", filename, self.artifacts_dir)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import shutil
import tempfile
from pathlib import Path
from unittest import TestCase
from unittest.mock import patch

Expand Down Expand Up @@ -32,7 +33,8 @@ def _set_esbuild_binary_path(self):
npm = SubprocessNpm(self.osutils)
esbuild_dir = os.path.join(self.TEST_DATA_FOLDER, "esbuild-binary")
npm.run(["ci"], cwd=esbuild_dir)
self.binpath = npm.run(["bin"], cwd=esbuild_dir)
self.root_path = npm.run(["root"], cwd=esbuild_dir)
self.binpath = Path(self.root_path, ".bin")

def tearDown(self):
shutil.rmtree(self.artifacts_dir)
Expand Down Expand Up @@ -168,7 +170,7 @@ def test_bundles_project_without_dependencies(self, runtime):
npm = SubprocessNpm(osutils)
esbuild_dir = os.path.join(self.TEST_DATA_FOLDER, "esbuild-binary")
npm.run(["ci"], cwd=esbuild_dir)
binpath = npm.run(["bin"], cwd=esbuild_dir)
binpath = Path(npm.run(["root"], cwd=esbuild_dir), ".bin")

self.builder.build(
source_dir,
Expand All @@ -194,7 +196,7 @@ def test_builds_project_with_remote_dependencies_without_download_dependencies_w
npm = SubprocessNpm(osutils)
esbuild_dir = os.path.join(self.TEST_DATA_FOLDER, "esbuild-binary")
npm.run(["ci"], cwd=esbuild_dir)
binpath = npm.run(["bin"], cwd=esbuild_dir)
binpath = Path(npm.run(["root"], cwd=esbuild_dir), ".bin")

self.builder.build(
source_dir,
Expand Down
17 changes: 7 additions & 10 deletions tests/unit/workflows/nodejs_npm/test_actions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import itertools
from unittest import TestCase
from mock import patch, call
from parameterized import parameterized
Expand Down Expand Up @@ -111,26 +112,22 @@ def test_raises_action_failed_when_npm_fails(self, SubprocessNpmMock):


class TestNodejsNpmrcAndLockfileCopyAction(TestCase):
@parameterized.expand(
[
[False, False],
[True, False],
[False, True],
[True, True],
]
)
@parameterized.expand(itertools.product([True, False], [True, False], [True, False]))
@patch("aws_lambda_builders.workflows.nodejs_npm.utils.OSUtils")
def test_copies_into_a_project_if_file_exists(self, npmrc_exists, package_lock_exists, OSUtilMock):
def test_copies_into_a_project_if_file_exists(
self, npmrc_exists, package_lock_exists, shrinkwrap_exists, OSUtilMock
):
osutils = OSUtilMock.return_value
osutils.joinpath.side_effect = lambda a, b: "{}/{}".format(a, b)

action = NodejsNpmrcAndLockfileCopyAction("artifacts", "source", osutils=osutils)
osutils.file_exists.side_effect = [npmrc_exists, package_lock_exists]
osutils.file_exists.side_effect = [npmrc_exists, package_lock_exists, shrinkwrap_exists]
action.execute()

filename_exists = {
".npmrc": npmrc_exists,
"package-lock.json": package_lock_exists,
"npm-shrinkwrap.json": shrinkwrap_exists,
}
file_exists_calls = [call("source/{}".format(filename)) for filename in filename_exists]
copy_file_calls = [
Expand Down