I've been using ts-node with mocha for running test. It works fine in watch mode. I can change from failing test to success smoothly. But when code error it shown TSError: ⨯ Unable to compile TypeScript by removing imported dependency. and then I put that dependency back. It's not work as expect.
Here's an example
import {expect} from 'chai';
import fizzbuzz from '../src/fizzbuzz';
describe('fizzbuzz', () => {
it('input 1 return 1', () => {
expect(fizzbuzz(1)).to.equal('1');
});
});
output is (this failing test is OK)
2 passing (45ms)
1 failing
1) fizzbuzz input 1 return 1:
AssertionError: expected undefined to equal '1'
at Context.<anonymous> (../../test/test.ts:6:28)
and remove dependency and save file
import {expect} from 'chai';
describe('fizzbuzz', () => {
it('input 1 return 1', () => {
expect(fizzbuzz(1)).to.equal('1');
});
});
and it's ok to error
TSError: ⨯ Unable to compile TypeScript
test/test.ts (6,12): Cannot find name 'fizzbuzz'. (2304)
but when I put it back and save the file
import {expect} from 'chai';
import fizzbuzz from '../src/fizzbuzz';
describe('fizzbuzz', () => {
it('input 1 return 1', () => {
expect(fizzbuzz(1)).to.equal('1');
});
});
mocha's not comming back and the error show up again
TSError: ⨯ Unable to compile TypeScript
test/test.ts (6,12): Cannot find name 'fizzbuzz'. (2304)
This is my mocha opts
--require ts-node/register
--reporter nyan
--watch-extensions tsx,ts
test/**/*.tsx
test/**/*.ts
Please help me
Thanks
Can confirm this is happening on my setup as well. But when say, I purposely break a test (by making it fail), and then fix it, it does re-run tests. So only on compilation errors.
This is also happening in my set up. If you set the flags:
TS_NODE_IGNORE_WARNINGS=TRUE TS_NODE_DISABLE_WARNINGS=TRUE
then this doesn't happen, but it silently fails to compile so you don't get compilation errors.
mocha -w and ts-node don't work together in my project too
@EddyLane
I think you only need TS_NODE_IGNORE_WARNINGS=TRUE.
It makes it recompile on change even after compilation error and you still get errors when it fails to compile.
same here.. TS_NODE_IGNORE_WARNINGS just silent down errors... needs cmd+c and run again
Closing because the original issue does not happen on the latest ts-node and mocha.
https://github.com/TypeStrong/ts-node-repros/tree/issue-113
https://github.com/TypeStrong/ts-node-repros/runs/1029421954
Most helpful comment
mocha -wandts-nodedon't work together in my project too