@@ -119,8 +116,9 @@ def test_remove_unused_exports(tmpdir) -> None:
)
}
"""
+ adj_filename = "adjacent.tsx"
# language=typescript jsx
- ADJ_CONTENT = """
+ adj_content = """
import MainComponent from 'Component'
import { SharedComponent } from 'Component'
import { StateComponent } from 'utils'
@@ -129,79 +127,26 @@ def test_remove_unused_exports(tmpdir) -> None:
return (
)
}
"""
+ misc_filename = "misc.tsx"
# language=typescript jsx
- MISC_CONTENT = """
+ misc_content = """
export { UnusedComponent } from 'Component'
function Helper({ props }: HelperProps) {}
export { Helper }
"""
+ import_filename = "import.tsx"
# language=typescript jsx
- IMPORT_CONTENT = """
+ import_content = """
import { UnusedComponent } from 'misc'
"""
- # ========== [ AFTER ] ==========
- # language=typescript jsx
- EXPECTED_SRC_CONTENT = """
-import { SubComponent } from 'new';
-
-export default function MainComponent() {
- const [state, setState] = useState
()
- return ()
-}
-
-export function UnusedComponent({ props }: UnusedProps) {
- return (
- Unused
- )
-}
-"""
- # language=typescript jsx
- EXPECTED_NEW_CONTENT = """
-export function SubComponent({ props }: SubComponentProps) {
- return (
-
- )
-}
-
-function HelperComponent({ props }: HelperComponentProps) {
- return (
-
- )
-}
-
-export function SharedComponent({ props }: SharedComponentProps) {
- return (
-
- )
-}
-"""
- # language=typescript jsx
- EXPECTED_ADJ_CONTENT = """
-import MainComponent from 'Component'
-import { SharedComponent } from 'new'
-import { StateComponent } from 'utils'
-
-function Container(props: ContainerProps) {
- return ()
-}
-"""
- # language=typescript jsx
- EXPECTED_MISC_CONTENT = """
-function Helper({ props }: HelperProps) {}
-"""
-
- files = {"Component.tsx": SRC_CONTENT, "adjacent.tsx": ADJ_CONTENT, "misc.tsx": MISC_CONTENT, "import.tsx": IMPORT_CONTENT}
+ files = {src_filename: src_content, adj_filename: adj_content, misc_filename: misc_content, import_filename: import_content}
with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files=files) as codebase:
- src_file = codebase.get_file("Component.tsx")
- adj_file = codebase.get_file("adjacent.tsx")
- misc_file = codebase.get_file("misc.tsx")
+ src_file = codebase.get_file(src_filename)
+ adj_file = codebase.get_file(adj_filename)
+ misc_file = codebase.get_file(misc_filename)
new_file = codebase.create_file("new.tsx")
sub_component = src_file.get_symbol("SubComponent")
@@ -214,7 +159,20 @@ def test_remove_unused_exports(tmpdir) -> None:
src_file.remove_unused_exports()
misc_file.remove_unused_exports()
- assert src_file.content.strip() == EXPECTED_SRC_CONTENT.strip()
- assert new_file.content.strip() == EXPECTED_NEW_CONTENT.strip()
- assert adj_file.content.strip() == EXPECTED_ADJ_CONTENT.strip()
- assert misc_file.content.strip() == EXPECTED_MISC_CONTENT.strip()
+ # Verify exports in new file
+ assert "export function SubComponent" in new_file.content
+ assert "function HelperComponent" in new_file.content
+ assert "export function HelperComponent" not in new_file.content
+ assert "export function SharedComponent" in new_file.content
+
+ # Verify imports updated
+ assert "import { SharedComponent } from 'new'" in adj_file.content
+
+ # Verify original file exports
+ assert "export default function MainComponent()" in src_file.content
+ assert "function UnusedComponent" in src_file.content
+ assert "export function UnusedComponent" not in src_file.content
+
+ # Verify misc file exports cleaned up
+ assert "export { Helper }" not in misc_file.content
+ assert "export { UnusedComponent } from 'Component'" not in misc_file.content
diff --git a/tests/unit/codegen/sdk/typescript/tsx/test_tsx_edit.py b/tests/unit/codegen/sdk/typescript/tsx/test_tsx_edit.py
index a7147bf3a..6f21af839 100644
--- a/tests/unit/codegen/sdk/typescript/tsx/test_tsx_edit.py
+++ b/tests/unit/codegen/sdk/typescript/tsx/test_tsx_edit.py
@@ -333,7 +333,7 @@ def test_tsx_move_component(tmpdir) -> None:
ctx.commit_transactions()
assert "export function FooBar" in new_file.content
- assert "function MyFooBar" in new_file.content
+ assert "export function MyFooBar" in new_file.content
assert "import { FooBar } from 'new'" in original_file.content
assert "import { MyFooBar } from 'new'" not in original_file.content
diff --git a/tests/unit/codegen/sdk/typescript/tsx/test_tsx_parsing.py b/tests/unit/codegen/sdk/typescript/tsx/test_tsx_parsing.py
index 813102927..af2f32446 100644
--- a/tests/unit/codegen/sdk/typescript/tsx/test_tsx_parsing.py
+++ b/tests/unit/codegen/sdk/typescript/tsx/test_tsx_parsing.py
@@ -105,7 +105,7 @@ def test_tsx_file_type_validation(tmpdir) -> None:
test_component.move_to_file(tsx_file)
- assert "function TestComponent" in tsx_file.content
+ assert "export function TestComponent" in tsx_file.content
def test_jsx_element_attributes(tmpdir) -> None:
diff --git a/tests/unit/skills/implementations/guides/organize-your-codebase.py b/tests/unit/skills/implementations/guides/organize-your-codebase.py
index d2e914bd2..5827d2ca5 100644
--- a/tests/unit/skills/implementations/guides/organize-your-codebase.py
+++ b/tests/unit/skills/implementations/guides/organize-your-codebase.py
@@ -416,7 +416,7 @@ def my_symbol():
SkillTestCaseTSFile(
input="",
output="""
-function dependencyFunction() {
+export function dependencyFunction() {
console.log("I'm a dependency");
}