Is it possible to override which tsconfig.json ts-node uses when called from mocha?
My main tsconfig.json contains \"module\": \"es20
--compilerOptions wont' work.
What you need to do is customize how you register ts-node. My case was a little bit different from yours, I wanted it to use test/tsconfig.json, which contained settings needed by my test code. If I just used --require ts-node/register, it was using a default configuration that did not contain the settings needed to run my tests.
What I did was:
Create a file test/tshook.js. It contains:
require("ts-node").register({
project: "test/tsconfig.json",
});
I edited my test/mocha.opts to have:
--require test/tshook.js
test/**/*.ts
This should will pass the desired setting to ts-node:
require("ts-node").register({
compilerOptions: {
module: "commonjs",
},
});