connor4312 / nodejs-testing

VS Code integration for node:test native tests
MIT License
48 stars 7 forks source link

Unable to run tests compiled with Babel #53

Open zeel01 opened 1 week ago

zeel01 commented 1 week ago

I'm trying to set up some tests for a package I'm compiling with Babel (in order to use Stage 3 decorators). Babel is compiling files from src into dist with sourcemaps.

image

This extension only sees the original decorators.test.js in the src directory. If I configure it to only look in dist with "nodejs-testing.include": ["./dist"] it won't see any tests.

I've tried a bunch of permutations trying to get it to see the compiled tests. The only thing that seems to make it run the compiled test, is to copy/paste the compiled version into the original file. Obviously that's not a solution and breaks imports and such, but it will see that file as a test file at least.

I've tried refreshing the test explorer, reloading the VS Code window, using inline sourcemaps, outputting the compiled code in the same directory as the source, etc. Nothing I do seems to convince it to see anything but the original copy of the test file.

I thought for a second that maybe it was being magical and smart, and listing the the source files but actually running the compiled versions via the source maps. But that's not the case, running the test immediately fails due to Invalid or unexpected token because of the decorators.

I also thought maybe it was trying to do something like that, so I tried removing the sourcemaps and comments from the output file but that doesn't change anything.

Babel is only transforming the decorators themselves, so all the important lines like import { test } from "node:test"; are still there for the extension to detect.

I even checked if the extension was respecting my .gitignore or something silly like that, but nope.

Finally, when I run the compiled file with node it runs correctly.

Minimal reproducible example: https://gist.github.com/zeel01/6c183f2ce1c62c4602208ca7ad618fe6

zeel01 commented 1 day ago

It looks like I'm getting this error in the Extension Host: [error] Error: Unknown node type StaticBlock.

It looks like Babel sometimes outputs static initializer blocks, and the test runner doesn't like them.

Workaround: Installing @babel/plugin-transform-class-static-block