Skip to content

Commit

Permalink
Merge branch 'master' into feature/robot_cross-project-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boakley authored Nov 25, 2020
2 parents 465133a + ac78480 commit a6a4bf0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 54 deletions.
11 changes: 5 additions & 6 deletions cumulusci/salesforce_api/package_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,18 @@ def _include_directory(self, root_parts):
if len(root_parts) == 0:
return True

# include top level only within lwc
if root_parts[0] == "lwc" and len(root_parts) != 2:
# don't include lwc tests
if root_parts[0] == "lwc" and any(part.startswith("__") for part in root_parts):
return False

# include everything else
return True

def _include_file(self, root_parts, f):
"""Return boolean for whether this file should be included in the package."""
if len(root_parts) == 2 and root_parts[0] == "lwc":
# is file of lwc component directory
lower_f = f.lower()
return lower_f.endswith((".js", ".js-meta.xml", ".html", ".css", ".svg"))
if len(root_parts) and root_parts[0] == "lwc":
# only include expected file extensions within lwc components
return f.lower().endswith((".js", ".js-meta.xml", ".html", ".css", ".svg"))
return True

def _process(self):
Expand Down
65 changes: 17 additions & 48 deletions cumulusci/salesforce_api/tests/test_package_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,31 +263,19 @@ def test_include_directory(self):
assert builder._include_directory([]) is True

# not include lwc directory
assert builder._include_directory(["lwc"]) is False
assert builder._include_directory(["lwc"]) is True

# include any lwc sub-directory (i.e. lwc component directory)
assert builder._include_directory(["lwc", "myComponent"]) is True
assert builder._include_directory(["lwc", "lwc"]) is True

# not include any sub-*-directory of a lwc sub-directory
assert builder._include_directory(["lwc", "myComponent", "__tests__"]) is False
assert (
builder._include_directory(["lwc", "myComponent", "sub-1", "sub-2"])
is False
)
assert (
builder._include_directory(
["lwc", "myComponent", "sub-1", "sub-2", "sub-3"]
)
is False
)
assert (
builder._include_directory(
["lwc", "myComponent", "sub-1", "sub-2", "sub-3", "sub-4"]
)
is False
builder._include_directory(["lwc", "myComponent", "sub-1", "sub-2"]) is True
)

# don't include __tests__ within lwc components
assert not builder._include_directory(["lwc", "myComponent", "__tests__"])
assert not builder._include_directory(["lwc", "myComponent", "__mocks__"])

# include any non-lwc directory
assert builder._include_directory(["not-lwc"]) is True
assert builder._include_directory(["classes"]) is True
Expand All @@ -296,55 +284,36 @@ def test_include_directory(self):
# include any sub_* directory of a non-lwc directory
assert builder._include_directory(["not-lwc", "sub-1"]) is True
assert builder._include_directory(["not-lwc", "sub-1", "sub-2"]) is True
assert (
builder._include_directory(["not-lwc", "sub-1", "sub-2", "sub-3"]) is True
)
assert (
builder._include_directory(["not-lwc", "sub-1", "sub-2", "sub-3", "sub-4"])
is True
)

def test_include_file(self):
builder = MetadataPackageZipBuilder()

lwc_component_directory = ["lwc", "myComponent"]
non_lwc_component_directories = [
[],
lwc_component_directories = [
["lwc"],
["lwc", "myComponent"],
["lwc", "myComponent", "sub-1"],
["lwc", "myComponent", "sub-2"],
]
non_lwc_component_directories = [
[],
["classes"],
["objects", "sub-1"],
["objects", "sub-1", "sub-2"],
]

# file endings in lwc component whitelist
for file_ending in [".js", ".js-meta.xml", ".html", ".css", ".svg"]:
# lwc_component_directory
assert (
builder._include_file(
lwc_component_directory, "file_name" + file_ending
)
is True
)

# non_lwc_component_directories
for d in lwc_component_directories:
assert builder._include_file(d, "file_name" + file_ending)
for d in non_lwc_component_directories:
assert builder._include_file(d, "file_name" + file_ending) is True
assert builder._include_file(d, "file_name" + file_ending)

# file endings not in lwc component whitelist
for file_ending in ["", ".json", ".xml", ".cls", ".cls-meta.xml", ".object"]:
# lwc_component_directory
assert (
builder._include_file(
lwc_component_directory, "file_name" + file_ending
)
is False
)

# non_lwc_component_directories
for d in lwc_component_directories:
assert not builder._include_file(d, "file_name" + file_ending)
for d in non_lwc_component_directories:
assert builder._include_file(d, "file_name" + file_ending) is True
assert builder._include_file(d, "file_name" + file_ending)

def test_convert_sfdx(self):
with temporary_dir() as path:
Expand Down

0 comments on commit a6a4bf0

Please sign in to comment.