I am trying to setup ts-node with mocha however the test script always fails.
I have tried
mocha --require ts-node/register --extensions ts,tsx --watch --watch-files src 'src/**/*.spec.{ts,tsx}'
and
mocha --require ts-node/register src/**/*.spec.ts
Also I tried installing ts-node locally and globally but always this is the output
> [email protected] test /home/moamen/foo/baz
> mocha --require ts-node/register src/**/*.spec.ts
(node:48106) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Object.help (/home/moamen/foo/baz/node_modules/yargs/lib/usage.js:240:22)
at Object.self.showHelp (/home/moamen/foo/baz/node_modules/yargs/lib/usage.js:432:15)
at Array.<anonymous> (/home/moamen/foo/baz/node_modules/mocha/lib/cli/cli.js:53:13)
at Object.fail (/home/moamen/foo/baz/node_modules/yargs/lib/usage.js:41:17)
at /home/moamen/foo/baz/node_modules/yargs/lib/command.js:246:36
(Use `node --trace-warnings ...` to show where the warning was created)
(node:48106) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:48106) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
and this is my tsconfig.json
{
"compilerOptions": {
"target": "es6" ,
"module": "commonjs",
"sourceMap": true ,
"outDir": "dist" ,
"strict": true ,
"moduleResolution": "node" ,
"esModuleInterop": true
},
"lib": ["es2015"]
}
After seeing this example https://github.com/mochajs/mocha-examples/tree/master/packages/typescript. The problem was that I had typescript installed globally. This shouldn't have been a problem but it was.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With