firsttris / vscode-jest-runner

Simple way to run or debug one or more tests from context menu, codelens or command plalette
https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner
MIT License
265 stars 124 forks source link

(typescript) Decorated parameters result in jest-runner erroring #260

Closed jbjhjm closed 1 year ago

jbjhjm commented 2 years ago

As soon as a test file contains a param decorator like e.g.

class SimpleTestController {
    handlerMethod(@Body() xxx) {
        return;
    }
}

jest-runner will fail. There already was a issue report some time ago: https://github.com/firsttris/vscode-jest-runner/issues/225

Unfortunately the issue remains. Console reported the following error:

jest-editor-support parser returned error SyntaxError: Decorators cannot be used to decorate parameters. (18:15)
    at mt._raise (c:\Users\Jannik\.vscode\extensions\firsttris.vscode-jest-runner-0.4.48\node_modules\@babel\parser\lib\index.js:479:22)

In the log paths one can see babel parser is generating this error. It seems some of the used dependencies try to transpile typescript based on babel.

I think this is whats happening:

So if jest-editor-support is not going to implement full typescript / tsc support, typescript files should be compiled to ECMAscript before being passed to the babel-based transpiler.

firsttris commented 2 years ago

thx for your report.

my understanding is babel 7 parser fully supports typescript syntax. We even migrated from typescript to babel parser in jest-editor-support. for whatever reasons. but decorators are experimental (even in typescript compiler). jest-editor-support would need to add the corresponding plugin to make decorators work. probably the plugin is missing.

since you already figured out the issue originates in jest-editor-support, we need to create the issue there to get it fixed: https://github.com/jest-community/jest-editor-support/issues

best regards Tristan

jbjhjm commented 2 years ago

Thx for blazingly fast reply @firsttris !

Who knows if typescript decorators will ever be marked stable 🤷‍♂️ The babel documentation on decorators mentions only class and method level decorators: https://babeljs.io/docs/en/babel-plugin-proposal-decorators And there is a 3rd party babel 7 plugin stating to add parameter-level decorators: https://github.com/WarnerHooh/babel-plugin-parameter-decorator Combining those two infos I'm kinda sure there's no official support for param decorators in Babel 7.

jest-editor-support documentation seems pretty sparse so I cannot see if there is any way to load the plugin without changing the library source code. I'll open a issue over on their repo.

firsttris commented 2 years ago

i think its just a matter of adding the plugin here. https://github.com/jest-community/jest-editor-support/blob/master/src/parsers/helper.ts#L11

i refactored this from typerscript to bable_parser at some point

and of course, they need to release a new version, we need to increase the dependency version...