Skip to content

Commit ce00e1d

Browse files
committed
feat(javascript): add logging to JSWriteTestService
Add logging statements to JSWriteTestService to provide more information during debugging. This includes logging warnings when test file paths or element to test are not found. The logging statements help identify potential issues and improve error handling.
1 parent 45f21b2 commit ce00e1d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

javascript/src/main/kotlin/cc/unitmesh/ide/javascript/provider/testing/JSWriteTestService.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.intellij.lang.javascript.psi.util.JSStubBasedPsiTreeUtil
1919
import com.intellij.openapi.application.ReadAction
2020
import com.intellij.openapi.application.runReadAction
2121
import com.intellij.openapi.command.WriteCommandAction
22+
import com.intellij.openapi.diagnostic.logger
2223
import com.intellij.openapi.project.Project
2324
import com.intellij.openapi.roots.ProjectFileIndex
2425
import com.intellij.openapi.vfs.LocalFileSystem
@@ -31,6 +32,7 @@ import java.nio.file.Path
3132
import kotlin.io.path.Path
3233

3334
class JSWriteTestService : WriteTestService() {
35+
val log = logger<JSWriteTestService>()
3436
override fun runConfigurationClass(project: Project): Class<out RunProfile> = NpmRunConfiguration::class.java
3537

3638
override fun isApplicable(element: PsiElement): Boolean {
@@ -40,10 +42,23 @@ class JSWriteTestService : WriteTestService() {
4042

4143
override fun findOrCreateTestFile(sourceFile: PsiFile, project: Project, element: PsiElement): TestFileContext? {
4244
val language = sourceFile.language
43-
val testFilePath = Util.getTestFilePath(element)?.toString() ?: return null
45+
val testFilePath = Util.getTestFilePath(element)?.toString()
46+
if (testFilePath == null) {
47+
log.warn("Failed to find test file path for: $element")
48+
return null
49+
}
50+
51+
val elementToTest = runReadAction { Util.getElementToTest(element) }
52+
if (elementToTest == null) {
53+
log.warn("Failed to find element to test for: ${element}, check your function is exported.")
54+
return null
55+
}
4456

45-
val elementToTest = runReadAction { Util.getElementToTest(element) } ?: return null
46-
val elementName = JSPsiUtil.elementName(elementToTest) ?: return null
57+
val elementName = JSPsiUtil.elementName(elementToTest)
58+
if (elementName == null) {
59+
log.warn("Failed to find element name for: $element")
60+
return null
61+
}
4762

4863
var testFile = LocalFileSystem.getInstance().findFileByPath(testFilePath)
4964
if (testFile != null) {

0 commit comments

Comments
 (0)