如何在launch.json中的Visual Studio Code中在$ {relativeFile}中反斜杠? [英] How to reverse backslashes in ${relativeFile} in Visual Studio Code in launch.json?
问题描述
我正在尝试配置(Windows)Visual Studio代码launch.json
以启动当前文件的jest
测试.为了获得路径,我使用了${relativeFile}
变量,该变量给出了一个带有反斜杠的字符串,例如"src\services\some-service.spec.ts"
,尽管在
I'm trying to configure (Windows) Visual Studio Code launch.json
to launch jest
tests for the current file. To get the path I use ${relativeFile}
variable which gives a string with backslashes like this "src\services\some-service.spec.ts"
, although in the documentation slashes look just normal.
由于反斜杠,似乎jest
不接受这种路径.当我用正常的斜杠手动传递相同的路径时,效果很好.
It seems that jest
doesn't accept this kind of path because of reversed slashed. When I manually pass the same path with normal slashes it works just fine.
问题是,有什么方法可以在VSCode路径预定义变量(例如${relativeFile}
)中反斜杠,或者有一些解决方法?
The question is is there any way to reverse backslashes in VSCode path predefined variables like ${relativeFile}
or maybe some workarounds?
推荐答案
此问题与我向其他地方给出答案的问题非常相似.在此处总结说明:
This problem is very similar to one I gave an answer to elsewhere. To summarize the explanation there:
- 运行
bash -c node ...
而不是直接运行node ...
,因此您可以在命令行中使用shell命令替换. - 通过
cygpath -m
程序传递路径以获得正斜杠,例如$(cygpath -m ${relativeFile})
.
- Instead of directly running
node ...
, runbash -c node ...
so you can use shell command substitution in the command line. - Pass the path through the
cygpath -m
program to get forward slashes, something like$(cygpath -m ${relativeFile})
.
有关更多详细信息和示例,请参见链接的答案.
See the linked answer for more details and examples.
这篇关于如何在launch.json中的Visual Studio Code中在$ {relativeFile}中反斜杠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!