Hi!
I love ts-node so far but I run into issues when I want to run multiple tests at once. You can check out a sample repository to reproduce the error.
I have three tests and two test scripts declared in package.json. When I run
npm run test-single
# test-single: mocha test/test.ts --require ts-node/register && mocha test/test3.ts --require ts-node/register && mocha test/newtest.ts --require ts-node/register
it will execute each test one by one and everything seems to work fine. However, if I run all tests within one mocha run, like
npm test
# test: mocha test/**/*.ts --require ts-node/register
I receive the following TypeScript compilation errors from ts-node:
> [email protected] test /usr/local/src/Misc/ts-node-mocha
> mocha test/**/*.ts --require ts-node/register
----------------------------------
⨯ Unable to compile TypeScript
test/newtest.ts (5,14): Property 'should' does not exist on type 'string'. (2339)
test/test.ts (5,14): Property 'should' does not exist on type 'string'. (2339)
typings/should/should.d.ts (125,12): Cannot find name 'should'. (2304)
----------------------------------
npm ERR! Test failed. See above for more details.
What am I doing wrong? I'd really like to test all files within a folder at once.
Just checking it out now, that's extremely weird and you're definitely not doing anything wrong that I can tell. If it's an issue, I'll make sure it's patched ASAP.
Run out of time for now, got caught up fixing perf. I'll review it over the weekend. It really doesn't make a lot of sense how this could be happening. It literally only occurs when there's more than one input file. I think it should be erroring on the one file, that's the bug. Not sure why it's not though.
Hi Blake,
did you find the root cause of this bug yet? My workaround is still working, but it would be nice to know what caused this :)
@peterjuras I have not yet, no. However, the error is correct (IIRC). The problem is that the error is not occurring with a single file, when it should have been. You should look at importing the definition to fix the error.
I am also seeing this issue. If I run mocha for one file it will run the test and pass:
NODE_ENV=test node_modules/.bin/mocha --require ts-node/register src/HelloWorld.spec.ts
If I run with all files, I get TypeScript errors:
NODE_ENV=test node_modules/.bin/mocha --require ts-node/register src/**/*.spec.ts
⨯ Unable to compile TypeScript
src/HelloWorld.spec.ts (70,9): Cannot find name 'should'. (2304)
src/HelloWorld.spec.ts (71,9): Cannot find name 'should'. (2304)
src/HelloWorld.spec.ts (74,13): Cannot find name 'should'. (2304)
.
.
.
../typings/should/should.d.ts (125,12): Cannot find name 'should'. (2304)
I can run tsc in the appropriate directory and there are no errors. Perhaps more strangely, the **/*.spec.ts will work if it finds exactly one test file.
This could be related to global augmentation not applied on any. e.g.:
https://github.com/typed-typings/npm-chai/blob/master/lib/Chai.d.ts#L27
Can only augment type Object, so:
let x: Object;
x.should // is an Assertion
let x = {};
x.should // is undefined.
Also getting this.
So, is it possible to run all tests in e.g. src directory ?
I am able to run multiple tests. See https://github.com/typed-typings/npm-chai as an example.
npm install && npm run build then
npm run source-test
There are multiple issues here. The first one by @peterjuras can be worked around by putting the ts-node stuff first:
Does not work
mocha test/**/*.ts --require ts-node/register
Works
mocha --require ts-node/register test/**/*.ts
@blakeembrey looks like this is working now? Closing time?
@ianbytchek Seems reasonable. A new issue can always be opened 😄
Most helpful comment
There are multiple issues here. The first one by @peterjuras can be worked around by putting the
ts-nodestuff first:Does not work
Works