Coverage for tests / unit / tools / vue_tsc / test_options.py: 100%
73 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Unit tests for vue-tsc plugin options and definition."""
3from __future__ import annotations
5import pytest
6from assertpy import assert_that
8from lintro.enums.tool_type import ToolType
9from lintro.tools.definitions.vue_tsc import (
10 VUE_TSC_DEFAULT_PRIORITY,
11 VUE_TSC_DEFAULT_TIMEOUT,
12 VUE_TSC_FILE_PATTERNS,
13 VueTscPlugin,
14)
16# Tests for tool definition attributes
19def test_definition_name(vue_tsc_plugin: VueTscPlugin) -> None:
20 """Verify tool name is 'vue-tsc'.
22 Args:
23 vue_tsc_plugin: The VueTscPlugin instance to test.
24 """
25 assert_that(vue_tsc_plugin.definition.name).is_equal_to("vue-tsc")
28def test_definition_description(vue_tsc_plugin: VueTscPlugin) -> None:
29 """Verify tool has a description.
31 Args:
32 vue_tsc_plugin: The VueTscPlugin instance to test.
33 """
34 assert_that(vue_tsc_plugin.definition.description).is_not_empty()
37def test_definition_can_fix_is_false(vue_tsc_plugin: VueTscPlugin) -> None:
38 """Verify vue-tsc cannot auto-fix issues.
40 Args:
41 vue_tsc_plugin: The VueTscPlugin instance to test.
42 """
43 assert_that(vue_tsc_plugin.definition.can_fix).is_false()
46def test_definition_tool_type(vue_tsc_plugin: VueTscPlugin) -> None:
47 """Verify tool type is LINTER | TYPE_CHECKER.
49 Args:
50 vue_tsc_plugin: The VueTscPlugin instance to test.
51 """
52 expected_type = ToolType.LINTER | ToolType.TYPE_CHECKER
53 assert_that(vue_tsc_plugin.definition.tool_type).is_equal_to(expected_type)
56def test_definition_file_patterns(vue_tsc_plugin: VueTscPlugin) -> None:
57 """Verify file patterns include .vue files.
59 Args:
60 vue_tsc_plugin: The VueTscPlugin instance to test.
61 """
62 assert_that(vue_tsc_plugin.definition.file_patterns).is_equal_to(
63 VUE_TSC_FILE_PATTERNS,
64 )
65 assert_that(vue_tsc_plugin.definition.file_patterns).contains("*.vue")
68def test_definition_priority(vue_tsc_plugin: VueTscPlugin) -> None:
69 """Verify tool priority is set correctly.
71 Args:
72 vue_tsc_plugin: The VueTscPlugin instance to test.
73 """
74 assert_that(vue_tsc_plugin.definition.priority).is_equal_to(
75 VUE_TSC_DEFAULT_PRIORITY,
76 )
79def test_definition_native_configs(vue_tsc_plugin: VueTscPlugin) -> None:
80 """Verify native configs include tsconfig files.
82 Args:
83 vue_tsc_plugin: The VueTscPlugin instance to test.
84 """
85 native_configs = vue_tsc_plugin.definition.native_configs
86 assert_that(native_configs).is_not_empty()
87 assert_that(native_configs).contains("tsconfig.json")
88 assert_that(native_configs).contains("tsconfig.app.json")
91# Tests for default options
94@pytest.mark.parametrize(
95 ("option_name", "expected_value"),
96 [
97 ("timeout", VUE_TSC_DEFAULT_TIMEOUT),
98 ("project", None),
99 ("strict", None),
100 ("skip_lib_check", True),
101 ("use_project_files", False),
102 ],
103 ids=[
104 "timeout_equals_default",
105 "project_is_none",
106 "strict_is_none",
107 "skip_lib_check_is_true",
108 "use_project_files_is_false",
109 ],
110)
111def test_default_options_values(
112 vue_tsc_plugin: VueTscPlugin,
113 option_name: str,
114 expected_value: object,
115) -> None:
116 """Default options have correct values.
118 Args:
119 vue_tsc_plugin: The VueTscPlugin instance to test.
120 option_name: The name of the option to check.
121 expected_value: The expected value for the option.
122 """
123 assert_that(
124 vue_tsc_plugin.definition.default_options[option_name],
125 ).is_equal_to(expected_value)
128# Tests for set_options method - valid options
131def test_set_options_project_valid(vue_tsc_plugin: VueTscPlugin) -> None:
132 """Set project option with valid string path.
134 Args:
135 vue_tsc_plugin: The VueTscPlugin instance to test.
136 """
137 vue_tsc_plugin.set_options(project="tsconfig.app.json")
138 assert_that(vue_tsc_plugin.options.get("project")).is_equal_to("tsconfig.app.json")
141def test_set_options_project_none(vue_tsc_plugin: VueTscPlugin) -> None:
142 """Set project option to None (default).
144 Args:
145 vue_tsc_plugin: The VueTscPlugin instance to test.
146 """
147 vue_tsc_plugin.set_options(project=None)
148 # None values are filtered out, so key won't exist
149 assert_that(vue_tsc_plugin.options.get("project")).is_none()
152def test_set_options_strict_true(vue_tsc_plugin: VueTscPlugin) -> None:
153 """Set strict option to True.
155 Args:
156 vue_tsc_plugin: The VueTscPlugin instance to test.
157 """
158 vue_tsc_plugin.set_options(strict=True)
159 assert_that(vue_tsc_plugin.options.get("strict")).is_true()
162def test_set_options_skip_lib_check_false(vue_tsc_plugin: VueTscPlugin) -> None:
163 """Set skip_lib_check option to False.
165 Args:
166 vue_tsc_plugin: The VueTscPlugin instance to test.
167 """
168 vue_tsc_plugin.set_options(skip_lib_check=False)
169 assert_that(vue_tsc_plugin.options.get("skip_lib_check")).is_false()
172# Tests for set_options method - invalid types
175def test_set_options_project_invalid_type(vue_tsc_plugin: VueTscPlugin) -> None:
176 """Raise ValueError for invalid project type.
178 Args:
179 vue_tsc_plugin: The VueTscPlugin instance to test.
180 """
181 with pytest.raises(ValueError, match="project must be a string path"):
182 vue_tsc_plugin.set_options(project=123) # type: ignore[arg-type]
185def test_set_options_strict_invalid_type(vue_tsc_plugin: VueTscPlugin) -> None:
186 """Raise ValueError for invalid strict type.
188 Args:
189 vue_tsc_plugin: The VueTscPlugin instance to test.
190 """
191 with pytest.raises(ValueError, match="strict must be a boolean"):
192 vue_tsc_plugin.set_options(strict="yes") # type: ignore[arg-type]
195def test_set_options_skip_lib_check_invalid_type(
196 vue_tsc_plugin: VueTscPlugin,
197) -> None:
198 """Raise ValueError for invalid skip_lib_check type.
200 Args:
201 vue_tsc_plugin: The VueTscPlugin instance to test.
202 """
203 with pytest.raises(ValueError, match="skip_lib_check must be a boolean"):
204 vue_tsc_plugin.set_options(skip_lib_check="no") # type: ignore[arg-type]
207def test_set_options_use_project_files_invalid_type(
208 vue_tsc_plugin: VueTscPlugin,
209) -> None:
210 """Raise ValueError for invalid use_project_files type.
212 Args:
213 vue_tsc_plugin: The VueTscPlugin instance to test.
214 """
215 with pytest.raises(ValueError, match="use_project_files must be a boolean"):
216 vue_tsc_plugin.set_options(use_project_files="yes") # type: ignore[arg-type]
219# Tests for _build_command method
222def test_build_command_basic(vue_tsc_plugin: VueTscPlugin) -> None:
223 """Build basic command with default options.
225 Args:
226 vue_tsc_plugin: The VueTscPlugin instance to test.
227 """
228 cmd = vue_tsc_plugin._build_command(files=[])
230 # Should contain --noEmit and --pretty false
231 assert_that(cmd).contains("--noEmit")
232 assert_that(cmd).contains("--pretty")
233 assert_that(cmd).contains("false")
234 # First element should be vue-tsc command (or bunx/npx wrapper)
235 assert_that(cmd[0]).is_in("vue-tsc", "bunx", "npx")
238def test_build_command_with_project(vue_tsc_plugin: VueTscPlugin) -> None:
239 """Build command with project option.
241 Args:
242 vue_tsc_plugin: The VueTscPlugin instance to test.
243 """
244 cmd = vue_tsc_plugin._build_command(
245 files=[],
246 project_path="/path/to/tsconfig.json",
247 )
249 assert_that(cmd).contains("--project")
250 project_idx = cmd.index("--project")
251 assert_that(cmd[project_idx + 1]).is_equal_to("/path/to/tsconfig.json")
254def test_build_command_with_strict(vue_tsc_plugin: VueTscPlugin) -> None:
255 """Build command with strict option enabled.
257 Args:
258 vue_tsc_plugin: The VueTscPlugin instance to test.
259 """
260 vue_tsc_plugin.set_options(strict=True)
261 cmd = vue_tsc_plugin._build_command(files=[])
263 assert_that(cmd).contains("--strict")
266def test_build_command_with_skip_lib_check(vue_tsc_plugin: VueTscPlugin) -> None:
267 """Build command includes --skipLibCheck by default.
269 Args:
270 vue_tsc_plugin: The VueTscPlugin instance to test.
271 """
272 cmd = vue_tsc_plugin._build_command(files=[])
274 assert_that(cmd).contains("--skipLibCheck")
277def test_build_command_without_skip_lib_check(vue_tsc_plugin: VueTscPlugin) -> None:
278 """Build command without --skipLibCheck when disabled.
280 Args:
281 vue_tsc_plugin: The VueTscPlugin instance to test.
282 """
283 vue_tsc_plugin.set_options(skip_lib_check=False)
284 cmd = vue_tsc_plugin._build_command(files=[])
286 assert_that(cmd).does_not_contain("--skipLibCheck")