I follow the instruction on this page:
Running Mocha tests in Webstorm
to run Mocha tests in WebStorm, but my tests are written in TypeScript (saved in .ts), I was wondering how do I run these? Here is an example:
describe("My Tests", () => {
it("Test #1", () => {
let nluConfig: any = {
"Provider" : "LUIS",
"Model" : {
"ID" : "aaa",
"Secret" : "bbb"
}
};
debugger;
let result:any = CNluFactory.getNluProvider(nluConfig);
expect(result).to.be.an.instanceof(CLuis);
});
});
Here is how I currently configured WebStorm to run my tests:
This is the error I get when I try to run:
"C:\Program Files\nodejs\node.exe" C:\Repository\Main\node_modules\nyc\bin\nyc.js --reporter=lcovonly --report-dir=C:\Users\User\AppData\Local\Temp\mocha-intellij-coverage- C:\Repository\Main\node_modules\mocha\bin\_mocha --ui bdd --reporter "C:\Program Files\JetBrains\WebStorm 2017.2.1\plugins\NodeJS\js\mocha-intellij\lib\mochaIntellijReporter.js" --recursive C:\Repository\Main\src\test
No test files found
I assume it couldn't recognize the TS file in my test directory?
Mocha can't run typescript files natively; you need to either pre-compile them and pass the generated .js
files to test runner, or compile them on-the-fly using ts-node, for example (--require ts-node/register/transpile-only
or the now deprecated --compilers ts:ts-node/register/transpile-only
):
Of course, you need to make sure to install typescript
and ts-node
modules next to mocha
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