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
3 changes: 2 additions & 1 deletion samcli/lib/build/bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def _get_path_and_filename_from_handler(handler: str) -> Optional[str]:
:return: string path to built handler file
"""
try:
path = str(Path(handler).parent / Path(handler).stem) + ".js"
path = (Path(handler).parent / Path(handler).stem).as_posix()
path = path + ".js"
except (AttributeError, TypeError):
return None
return path
Expand Down
24 changes: 22 additions & 2 deletions tests/unit/lib/build_module/test_bundler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from pathlib import Path
from unittest import TestCase
from unittest import TestCase, skipIf
from unittest.mock import patch, Mock

from parameterized import parameterized

from samcli.lib.build.bundler import EsbuildBundlerManager
from tests.testing_utils import IS_WINDOWS
from tests.unit.commands.buildcmd.test_build_context import DummyStack


Expand Down Expand Up @@ -178,7 +179,7 @@ class PostProcessHandler(TestCase):
def test_get_path_and_filename_from_handler(self):
handler = "src/functions/FunctionName/app.Handler"
file = EsbuildBundlerManager._get_path_and_filename_from_handler(handler)
expected_path = str(Path("src") / "functions" / "FunctionName" / "app.js")
expected_path = (Path("src") / "functions" / "FunctionName" / "app.js").as_posix()
self.assertEqual(file, expected_path)

@patch("samcli.lib.build.bundler.Path.__init__")
Expand Down Expand Up @@ -240,3 +241,22 @@ def test_update_function_handler(self):
self.assertEqual(updated_handler_a, "app.handler")
self.assertEqual(updated_handler_b, "app.handler")
self.assertEqual(updated_handler_c, "functions/source/update/app.handler")

@parameterized.expand(
[("/opt/my/path/handler.handler", "/opt/my/path/handler.js"), ("handler.handler", "handler.js")]
)
def test_get_handler_path_unix(self, input_path, expected_path):
result_path = EsbuildBundlerManager(Mock())._get_path_and_filename_from_handler(input_path)

self.assertEqual(result_path, expected_path)

@parameterized.expand(
[
("\\opt\\my\\path\\handler.handler", "/opt/my/path/handler.js"),
]
)
@skipIf(not IS_WINDOWS, "Skipping POSIX converting logic since WindowsPath is not available on unix systems")
def test_get_handler_windows_returns_posix(self, input_path, expected_path):
result_path = EsbuildBundlerManager(Mock())._get_path_and_filename_from_handler(input_path)

self.assertEqual(result_path, expected_path)