Skip to content

Commit a58da38

Browse files
authored
Merge pull request #4 from Umaaz/main
Fix issue with using file name
2 parents 3db215e + 3e1c793 commit a58da38

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ class AvaJavaScriptTestRunnerRunConfigurationGenerator : AnAction() {
3535
}
3636

3737
private fun getTestName(element: PsiElement?): String? {
38-
if (element == null || element !is JSCallExpression) {
38+
if (element == null || element.parent == null) {
3939
return null
4040
}
4141

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

46+
val jsCallExpression: JSCallExpression = element
4447
if (jsCallExpression.isTest()) {
4548
val arguments: Array<JSExpression> = jsCallExpression.arguments
4649
if (arguments.isNotEmpty()) {
@@ -74,6 +77,8 @@ class AvaJavaScriptTestRunnerRunConfigurationGenerator : AnAction() {
7477
}
7578
val filePath = currentFile.path
7679
val fileName = Paths.get(filePath).fileName.toString()
80+
val basePath = project.basePath
81+
val relPath = if (basePath == null) fileName else currentFile.path.substring(basePath.length + 1)
7782
val node: NodeJsRunConfiguration? =
7883
NodeJsRunConfiguration.getDefaultRunConfiguration(project)?.clone() as NodeJsRunConfiguration?
7984
if (node == null) {
@@ -85,14 +90,14 @@ class AvaJavaScriptTestRunnerRunConfigurationGenerator : AnAction() {
8590
writeError("Factory not found")
8691
return
8792
}
88-
node.workingDirectory = project.basePath
93+
node.workingDirectory = basePath
8994
node.inputPath = "node_modules/ava/cli.js"
9095
if (testName != null) {
9196
node.name = "ava $fileName $testName"
92-
node.applicationParameters = "-m \"$testName\" -v $fileName"
97+
node.applicationParameters = "-m \"$testName\" -v $relPath"
9398
} else {
9499
node.name = "ava $fileName"
95-
node.applicationParameters = "-v $fileName"
100+
node.applicationParameters = "-v $relPath"
96101
}
97102
val runManager = RunManager.getInstance(project)
98103
val configuration: RunnerAndConfigurationSettings = runManager.createConfiguration(node, factory)

0 commit comments

Comments
 (0)