tldr; I want to convert my JS project to TS one file at a time while being able to run Mocha tests without a build step.
I utilize a lot of Babel transforms (class props, jsx, ...) in my current javascript code, which Mocha handles at run-time by registering the babel loader (basically mocha --require @babel/register). This means running a single test is fast and requires no build step for the entire project.
I followed a guide on getting started with TypeScript using the (relatively) new babel plugin from Microsoft: @babel/preset-typescript. This worked fine for the basic case: converting app.js to app.ts.
What it didn't cover was how to do a step-wise transition. For me, fixing 3978 typescript errors (actual count after doing the <code>find</code> ...) is a bit overwhelming and would stall development for two weeks. Just getting my 200 LOC helpers lib to compile nicely with the definitions from react-redux took well over an hour.
While doing git mv app.{j,t}s worked fine, doing it to any other file was a disaster. Existing Mocha tests quickly crashed on being unable to find the right files, even when registering Babel and adding suitable extensions:
mocha --extension js,jsx,ts,tsx --require @babel/register
Typically if doing git mv Logger.{j,t}s I'd get Error: Cannot find module './lib/logging/Logger'.
Is there a way of getting Mocha's module loader to recognize typescript files and transparently run them through Babel?
mocha --extension js,jsxinstead of including and piping tsx to the babel register.buildfolder that copied all the js modules over and transpiled all the ts modules into something that would could be loaded by Mocha.