Skip to content

Commit

Permalink
fix: update test case for overriding Filename
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsobanjaved committed May 3, 2024
1 parent 22ea9c4 commit 269acf7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
21 changes: 12 additions & 9 deletions tubular/scripts/frontend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,19 @@ def create_version_file(self):
def copy_js_config_file_to_app_root(self, app_config, app_name):
""" Creates a copy of env.config.js(x) file to the app root """
source = app_config.get('JS_CONFIG_FILEPATH')
filename = app_config.get('LOCAL_CONFIG_FILENAME', "env.config.js")

# Skip if JS_CONFIG_FILEPATH not defined
if source:
destination = f"{app_name}/{filename}"
try:
shutil.copyfile(source, destination)
except FileNotFoundError:
self.FAIL(1, f"Could not find '{source}' for copying for app {app_name}.")
except OSError:
self.FAIL(1, f"Could not copy '{source}' to '{destination}', due to destination not writable.")
if not source:
return

filename = app_config.get('LOCAL_JS_CONFIG_FILENAME', "env.config.js")
destination = f"{app_name}/{filename}"
try:
shutil.copyfile(source, destination)
except FileNotFoundError:
self.FAIL(1, f"Could not find '{source}' for copying for app {app_name}.")
except OSError:
self.FAIL(1, f"Could not copy '{source}' to '{destination}', due to destination not writable.")


class FrontendDeployer:
Expand Down
5 changes: 4 additions & 1 deletion tubular/tests/example-frontend-config/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ APP_CONFIG:
NONE: !!null
NONE_WITH_QUOTES: 'None' # `None` instead of `null` because Python loads this file.

JS_CONFIG_FILEPATH: "dummy/file/path/env.stage.config.js"
# This can be overridden for any MFE
LOCAL_JS_CONFIG_FILENAME: "env.config.jsx"

JS_CONFIG_FILEPATH: "dummy/file/path/env.stage.config.jsx"
2 changes: 1 addition & 1 deletion tubular/tests/example-frontend-config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ APP_CONFIG:
COMMON_OVERRIDE_ME: initial_value

# Local Config File Name
LOCAL_CONFIG_FILENAME: "env.config.js"
LOCAL_JS_CONFIG_FILENAME: "env.config.js"
6 changes: 3 additions & 3 deletions tubular/tests/test_frontend_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_frontend_build_config_handling(
assert mock_build.call_args[0][0] == [
"COMMON_VAR='common_value'",
"COMMON_OVERRIDE_ME='overriden_value'",
"LOCAL_CONFIG_FILENAME='env.config.js'",
"LOCAL_JS_CONFIG_FILENAME='env.config.jsx'",
"VAR_WITH_SINGLE_QUOTES='The // value!'",
"VAR_WITH_DOUBLE_QUOTES='The // value!'",
"VAR_WITH_SINGLE_THEN_DOUBLE_QUOTES='The // value!'",
Expand All @@ -64,9 +64,9 @@ def test_frontend_build_config_handling(
"BOOL_FALSE_WITH_QUOTES='False'",
"NONE='None'",
"NONE_WITH_QUOTES='None'",
"JS_CONFIG_FILEPATH='dummy/file/path/env.stage.config.js'",
"JS_CONFIG_FILEPATH='dummy/file/path/env.stage.config.jsx'",
]
assert mock_create_version.call_count == 1
assert mock_shutil_copyfile.call_count == 1
# Verify that source is correct and destination is rightly formatted
mock_shutil_copyfile.assert_called_with('dummy/file/path/env.stage.config.js', 'coolfrontend/env.config.js')
mock_shutil_copyfile.assert_called_with('dummy/file/path/env.stage.config.jsx', 'coolfrontend/env.config.jsx')

0 comments on commit 269acf7

Please sign in to comment.