connor4312 / nodejs-testing

VS Code integration for node:test native tests
MIT License
43 stars 6 forks source link

Support for .ts-files #4

Closed geirsagberg-hent closed 10 months ago

geirsagberg-hent commented 1 year ago

Just the plugin I was looking for! I wish it would support .ts-files though, they do not seem to show up in the test explorer.

connor4312 commented 1 year ago

Please see the "Having Problems? Read this!" section:

The Node.js test runner only supports running JavaScript files. If you have a compilation step, you'll need to make sure that runs with sourcemaps so we can figure out where tests appear in your source code. For example, for TypeScript, set "sourceMap": true in your tsconfig.json.

geirsagberg-hent commented 1 year ago

Actually, the test runner supports .ts-files if you pass in a loader and the files explicitly, it just doesn't discover them:

node --test --loader tsx src/foo.test.ts

The above works well. Could there be a setting in this plugin to configure node-args so we can pass in loaders, and also to make the include-option a glob instead of just directories?

connor4312 commented 1 year ago

It seems like the loader is still very experimental (stability 1), and comes with a caveat:

When loading ECMAScript module loader loads the program entry point, the node command will only accept as input only files with .js, .mjs, or .cjs extensions; and with .wasm extensions when --experimental-wasm-modules is enabled.

Though what you said seems to contract that, or maybe it's different when running with --test. Will need to play around with it, I haven't personally tried to use --loader/--experimental-loader before.

koshic commented 1 year ago

@connor4312 node test runner is experimental too, and still have a lot of bugs )

Seriously, ESM loaders are stable enough since 18.x (and much more usable after https://github.com/nodejs/node/pull/43772 in 19.6). A bit strange naming convention is not a problem due to '--test test/*/.spec.ts'.

Your extension looks very promising, so please - don't introduce additional restrictions to the workflow (as we can see in many other, much more mature and popular extensions). Even if those restrictions are implicit, like inability to pass glob-based file list or configure node argv / NODE_OPTIONS (yes, I have to create separate script which mimics node binary to use eslint extension with latest node & yarn features), etc.

Thx!

connor4312 commented 12 months ago

Published in 1.1.0

koshic commented 12 months ago

@connor4312 may be stupid question - we can specify custom loaders & other node options (which is really cool), but we can't use .ts files due to extension doesn't look for them, right?

connor4312 commented 12 months ago

ah, right!

connor4312 commented 10 months ago

You can now do this, example config here: https://github.com/connor4312/nodejs-testing/blob/main/testCases/tsx/workspace/.vscode/settings.json