-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working with mocha and nyc #41
Comments
@reekoheek Did you find a solution to use |
I'd suggest just switching to |
No solution yet. For now I use
Didn't success using
|
I think I got it working. It is because it tries to bundle everything including the tests and then things go wrong, if you pass node a custom --require (aka -r) field to a file that uses esbuild-runner that just transpiles and not bundle, then it works. These two commands do the same, just wanted to show that the --require flag is not even needed, you can just specify the file to be used.
./cli/tests/compile.js require('esbuild-runner').install({
type: "transform", //toalso preserve debug points, else it bundles everything.
// debug: true,
esbuild: {
//TODO can extend esbuild here with the same config as used by the actual build process
}
}); In addition to that, the .mocharc file also uses that same require. .mocharc.json {
"extension": ["spec.ts"],
"spec": "tests/unit/*.spec.ts",
"require": "./tests/compile.js"
} |
As @rehanvdm stated, using different transform options is necessary unless you pre-instrument the sources. An esbuild option that is necessary to output coverage is Per the README here, create esbuild-runner.config.js in your package root, and configure your esbuild options including esbuild-runner.config.js module.exports = {
type: 'transform',
esbuild: {
sourcemap: 'inline'
}
} Otherwise, you can create a custom "register" file for your tests, and reference it from your scripts. package.json "test": "mocha -r custom-register.js \"test/**/*.spec.ts\"",
"coverage": "nyc npm run mocha", custom-register.js require('esbuild-runner').install({
type: 'transform',
esbuild: {
sourcemap: 'inline'
}
}); |
If anybody bumps into this and is having issues using
This seems to be working with simply invoking nyc + mocha |
Hi,
I love
esbuild-runner
, however I tried to replace my toolchain for testing withesbuild-runner
but I can't get the same result asts-node
did.I ran
nyc
withmocha
like this,nyc mocha -r ts-node/register './src/**/*.test.ts' --extension ts
and replace with
nyc mocha -r esbuild-runner/register './src/**/*.test.ts' --extension ts
But it seemed I didn't get the same result as
ts-node
versionThanks
The text was updated successfully, but these errors were encountered: