Skip to content

Commit 4383d60

Browse files
committed
fix(paths/names): use relative paths, and fix test name
- try to use the relative path to the file being tested rather then the file name - improve test name matching to allow running single test in file
1 parent 3db215e commit 4383d60

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/main/kotlin/no/eirikb/avatest/actions/AvaJavaScriptTestRunnerRunConfigurationGenerator.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.intellij.execution.configurations.ConfigurationFactory
66
import com.intellij.execution.executors.DefaultRunExecutor
77
import com.intellij.execution.runners.ExecutionUtil
88
import com.intellij.lang.javascript.psi.JSCallExpression
9+
import com.intellij.lang.javascript.psi.JSElement
910
import com.intellij.lang.javascript.psi.JSExpression
1011
import com.intellij.lang.javascript.psi.JSLiteralExpression
1112
import com.intellij.notification.Notification
@@ -35,12 +36,15 @@ class AvaJavaScriptTestRunnerRunConfigurationGenerator : AnAction() {
3536
}
3637

3738
private fun getTestName(element: PsiElement?): String? {
38-
if (element == null || element !is JSCallExpression) {
39+
if (element == null || element.parent== null) {
3940
return null
4041
}
4142

42-
val jsCallExpression: JSCallExpression = element
43+
if( element !is JSCallExpression ){
44+
return getTestName(element.parent)
45+
}
4346

47+
val jsCallExpression: JSCallExpression = element
4448
if (jsCallExpression.isTest()) {
4549
val arguments: Array<JSExpression> = jsCallExpression.arguments
4650
if (arguments.isNotEmpty()) {
@@ -74,6 +78,8 @@ class AvaJavaScriptTestRunnerRunConfigurationGenerator : AnAction() {
7478
}
7579
val filePath = currentFile.path
7680
val fileName = Paths.get(filePath).fileName.toString()
81+
val basePath = project.basePath
82+
val relPath = if (basePath == null) fileName else currentFile.path.substring(basePath.length +1)
7783
val node: NodeJsRunConfiguration? =
7884
NodeJsRunConfiguration.getDefaultRunConfiguration(project)?.clone() as NodeJsRunConfiguration?
7985
if (node == null) {
@@ -85,14 +91,14 @@ class AvaJavaScriptTestRunnerRunConfigurationGenerator : AnAction() {
8591
writeError("Factory not found")
8692
return
8793
}
88-
node.workingDirectory = project.basePath
94+
node.workingDirectory = basePath
8995
node.inputPath = "node_modules/ava/cli.js"
9096
if (testName != null) {
9197
node.name = "ava $fileName $testName"
92-
node.applicationParameters = "-m \"$testName\" -v $fileName"
98+
node.applicationParameters = "-m \"$testName\" -v $relPath"
9399
} else {
94100
node.name = "ava $fileName"
95-
node.applicationParameters = "-v $fileName"
101+
node.applicationParameters = "-v $relPath"
96102
}
97103
val runManager = RunManager.getInstance(project)
98104
val configuration: RunnerAndConfigurationSettings = runManager.createConfiguration(node, factory)

0 commit comments

Comments
 (0)