[BUG] - timeout annotation is causing a compiler error
Testdeck Version
freshly installed 0.2.0
Testdeck Package
- [x]
@testdeck/mocha
NodeJS Version
- [ ] 11
- [ ] 10
- [ ] 9
- [ ] 8
- [ ] all
- [x] other: 16.14.2
Mocha / Jasmine / Jest Version
- Mocha: 9.2.2
-
@types/mocha: 9.1.0 - Jasmine: ---
-
@types/jasmine: --- - Jest: ---
-
@types/jest: ---
Operating System
- [x] Linux
- [x] Mac OS X
- [ ] Windows 7
- [ ] Windows 10
- [ ] Other:
Actual Behaviour
I use a base class with following setup
export class BaseTest {
@timeout(5000)
static async before(): Promise<void> {
// some code that takes longer
}
After an update from 0.1.2 to 0.2.0 I get the following issue: the timeout is marked in WebStorm and the typescript compiler says
TS2345: Argument of type 'typeof BaseTest' is not assignable to parameter of type 'Object'. Types of property '[context]' are incompatible. Type 'Suite' is missing the following properties from type 'Context': _runnable, runnable, skip.
If I remove the timeout it works fine.
This works however with version 0.1.2.
Expected Behaviour
It should not error as it was in Version 0.1.2
Additional Information
Typescript version is 4.4.4 and I tried with latest 4.6.3, same errors
Quick-fix: downgrade to 0.1.2
@sittingbool I think I found the source of the problem
https://github.com/testdeck/testdeck/blob/1cd8cf742a170f47b5704585f9dbaec40a031338/packages/mocha/index.ts#L89
interface Object {
[mochaDecorators.context]: Mocha.Context
}
However, @pana-cc, I do not know what you want to express or achieve with this augmentation of the Object interface.
Commenting out this part seems to have no adverse effect on the existing tests, and the example code provided by the OP will work just fine.
@pana-cc how can we fix this? or do we even need to fix this?
I am sorry for the delay, but this issue has somehow slipped my attention. I probably should add some tests for the augmentation, what it does is basically provide typing for the mocha context:
import { suite, test, context } from "@testdeck/mocha";
@suite class Hello {
@test world() {
this[context]; // <-- the type of this property is Mocha.Context
}
}
I also wonder if the TypeScript compiler may have become more strict. I think it should be possible to extend the type of the timeout function to work.
I have troubles publishing it, but this PR should've fixed it: https://github.com/testdeck/testdeck/pull/294
Got my Authenticator in order, there is now v0.2.1 that has the typings in order.