Skip to content

Commit 941da6c

Browse files
committed
fix: update tests to expect build output dirs to be skipped
Tests now correctly expect '.' when package.json exports points to build output directories (dist/, build/, etc.) without a src/ directory.
1 parent 17806b8 commit 941da6c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

tests/code_utils/test_config_js.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,14 @@ def test_detects_from_exports_string(self, tmp_path: Path) -> None:
127127
assert result == "lib"
128128

129129
def test_detects_from_exports_object_dot(self, tmp_path: Path) -> None:
130-
"""Should detect module root from exports object with '.' key."""
130+
"""Should skip build output dirs and return '.' when no src dir exists."""
131131
(tmp_path / "dist").mkdir()
132132
package_data = {"exports": {".": "./dist/index.js"}}
133133

134134
result = detect_module_root(tmp_path, package_data)
135135

136-
assert result == "dist"
136+
# dist is a build output directory, so it's skipped
137+
assert result == "."
137138

138139
def test_detects_from_exports_object_nested(self, tmp_path: Path) -> None:
139140
"""Should detect module root from nested exports object."""
@@ -227,13 +228,14 @@ def test_ignores_root_level_main(self, tmp_path: Path) -> None:
227228
assert result == "src"
228229

229230
def test_handles_deeply_nested_exports(self, tmp_path: Path) -> None:
230-
"""Should handle deeply nested export paths."""
231+
"""Should handle deeply nested export paths but skip build output dirs."""
231232
(tmp_path / "packages" / "core" / "dist").mkdir(parents=True)
232233
package_data = {"exports": {".": {"import": "./packages/core/dist/index.mjs"}}}
233234

234235
result = detect_module_root(tmp_path, package_data)
235236

236-
assert result == "packages/core/dist"
237+
# dist is a build output directory, so it's skipped even when nested
238+
assert result == "."
237239

238240
def test_handles_empty_exports(self, tmp_path: Path) -> None:
239241
"""Should handle empty exports gracefully."""
@@ -756,7 +758,7 @@ def test_vite_react_project(self, tmp_path: Path) -> None:
756758
assert config["formatter_cmds"] == ["npx eslint --fix $file"]
757759

758760
def test_library_with_exports(self, tmp_path: Path) -> None:
759-
"""Should handle library with modern exports field."""
761+
"""Should handle library with modern exports field, skipping build output dirs."""
760762
(tmp_path / "dist").mkdir()
761763
package_json = tmp_path / "package.json"
762764
package_json.write_text(
@@ -773,7 +775,8 @@ def test_library_with_exports(self, tmp_path: Path) -> None:
773775

774776
assert result is not None
775777
config, _ = result
776-
assert config["module_root"] == str((tmp_path / "dist").resolve())
778+
# dist is a build output directory, so it's skipped and falls back to project root
779+
assert config["module_root"] == str(tmp_path.resolve())
777780

778781
def test_monorepo_package(self, tmp_path: Path) -> None:
779782
"""Should handle monorepo package configuration."""

0 commit comments

Comments
 (0)