Coverage for tests / integration / tools / vue_tsc / conftest.py: 50%

48 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-04-03 18:53 +0000

1"""Pytest configuration for vue-tsc integration tests.""" 

2 

3from __future__ import annotations 

4 

5import shutil 

6import subprocess 

7from pathlib import Path 

8 

9import pytest 

10 

11 

12def vue_tsc_is_available() -> bool: 

13 """Check if vue-tsc is installed and actually works. 

14 

15 This checks both that the command exists AND that it executes successfully, 

16 which handles cases where a wrapper script exists but the underlying 

17 tool isn't installed. Also checks bunx/npx fallbacks. 

18 

19 Returns: 

20 True if vue-tsc is installed and working, False otherwise. 

21 """ 

22 # Try direct vue-tsc command first 

23 if shutil.which("vue-tsc") is not None: 

24 try: 

25 result = subprocess.run( 

26 ["vue-tsc", "--version"], 

27 capture_output=True, 

28 timeout=10, 

29 check=False, 

30 ) 

31 if result.returncode == 0: 

32 return True 

33 except (subprocess.TimeoutExpired, OSError): 

34 pass 

35 

36 # Try bunx fallback 

37 if shutil.which("bunx") is not None: 

38 try: 

39 result = subprocess.run( 

40 ["bunx", "vue-tsc", "--version"], 

41 capture_output=True, 

42 timeout=30, 

43 check=False, 

44 ) 

45 if result.returncode == 0: 

46 return True 

47 except (subprocess.TimeoutExpired, OSError): 

48 pass 

49 

50 # Try npx fallback 

51 if shutil.which("npx") is not None: 

52 try: 

53 result = subprocess.run( 

54 ["npx", "vue-tsc", "--version"], 

55 capture_output=True, 

56 timeout=30, 

57 check=False, 

58 ) 

59 if result.returncode == 0: 

60 return True 

61 except (subprocess.TimeoutExpired, OSError): 

62 pass 

63 

64 return False 

65 

66 

67def _find_project_root() -> Path: 

68 """Find project root by looking for pyproject.toml. 

69 

70 Returns: 

71 Path to the project root directory. 

72 

73 Raises: 

74 RuntimeError: If pyproject.toml is not found in any parent directory. 

75 """ 

76 path = Path(__file__).resolve() 

77 for parent in path.parents: 

78 if (parent / "pyproject.toml").exists(): 

79 return parent 

80 raise RuntimeError("pyproject.toml not found in parent directories") 

81 

82 

83# Paths to test samples 

84SAMPLE_DIR = _find_project_root() / "test_samples" 

85VUE_TSC_SAMPLES = SAMPLE_DIR / "tools" / "web" / "vue_tsc" 

86CLEAN_SAMPLE = VUE_TSC_SAMPLES / "vue_tsc_clean.vue" 

87VIOLATION_SAMPLE = VUE_TSC_SAMPLES / "vue_tsc_violations.vue" 

88 

89 

90@pytest.fixture 

91def vue_tsc_violation_file(tmp_path: Path) -> str: 

92 """Copy the vue-tsc violation sample to a temp directory. 

93 

94 Args: 

95 tmp_path: Pytest fixture providing a temporary directory. 

96 

97 Returns: 

98 Path to the copied file as a string. 

99 """ 

100 dst = tmp_path / "vue_tsc_violations.vue" 

101 shutil.copy(VIOLATION_SAMPLE, dst) 

102 return str(dst) 

103 

104 

105@pytest.fixture 

106def vue_tsc_clean_file(tmp_path: Path) -> str: 

107 """Copy the vue-tsc clean sample to a temp directory. 

108 

109 Args: 

110 tmp_path: Pytest fixture providing a temporary directory. 

111 

112 Returns: 

113 Path to the copied file as a string. 

114 """ 

115 dst = tmp_path / "vue_tsc_clean.vue" 

116 shutil.copy(CLEAN_SAMPLE, dst) 

117 return str(dst)