如果我使用编译模式运行yarn test
,我会得到一个像这样的堆栈跟踪:
-*- mode: compilation; default-directory: "~/code/MyProject" -*-
Compilation started at Tue Apr 24 09:54:23
yarn test
yarn run v1.6.0
$ jest 'src'
FAIL src/scenes/MainScene.test.ts
● Test suite failed to run
~/code/MyProject/node_modules/phaser/src/renderer/webgl/shaders/BitmapMask.frag:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){#define SHADER_NAME PHASER_BITMAP_MASK_FS
^
SyntaxError: Invalid or unexpected token
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)
at Object.<anonymous> (node_modules/phaser/src/renderer/webgl/pipelines/BitmapMaskPipeline.js:9:22)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.866s
Ran all test suites matching /src/i.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Compilation exited abnormally with code 1 at Tue Apr 24 09:54:26
Emacs自动检测到很酷的错误!所以我按<TAB>
它将光标移动到以下行:
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)
然后,我按<CR>
尝试导航到该文件,但我在屏幕底部问我问:
Find this error in (default node_modules/jest-runtime/build/script_transformer.js:316): ~/code/MyProject
由于某种原因,它似乎无法找到文件的路径,我想知道是否因为堆栈跟踪附加了行号。有没有办法配置compile-goto-error
函数来考虑这一点?
答案 0 :(得分:1)
您可以向compilation-error-regexp-alist-alist
添加条目以匹配编译缓冲区中的错误输出。您可以在文档中阅读有很多选项来匹配错误。对于你的例子,
(push 'my-error-1 compilation-error-regexp-alist)
(push '(my-error-1
"^[ ]*at .* (\\([^:]+\\):\\([0-9]+\\):\\([0-9]+\\))" 1 2)
compilation-error-regexp-alist-alist)
第一个捕获组指定文件,第二个是行号,如果需要,第三个也是列。