Incorrect type for attach argument
FrancisTaylor opened this issue · 15 comments
Environment (please complete the following information):
- Node.js version: v14.19.1.
- NPM version: 6.14.16
- webdriver.io version: 7.19.7
- @wdio/cucumber-framework version: 7.19.7
- wdio-cucumberjs-json-reporter version: 4.4.1
Config of webdriver.io and the reporter
Describe the bug
excerpt from reporter.ts:
export class CucumberJsJsonReporter extends WDIOReporter {
...
public static attach ( data: string, type = TEXT_PLAIN ): void {
...
excerpt from README.md:
...
cucumberJson.attach({"json-string": true}, 'application/json');
...
To Reproduce
Attempt to use the example code yields an error:
Argument of type '{ hello: string; }' is not assignable to parameter of type 'string'.
Expected behavior
example code should work
Snapshots
Additional context
Add any other context about the problem here.
Thanks for reporting!
Any contributions that resolves the bug are highly appreciated. Let us know if you have any questions. Cheers!
This fix is crude but it works for me:
*** wdio-cucumberjs-json-reporter-orig/lib/models.ts Wed Jul 6 07:02:18 2022
--- wdio-cucumberjs-json-reporter-main/lib/models.ts Tue Aug 2 13:38:51 2022
*** 96,107 ****
}
export interface CucumberJsAttachment {
! data: string;
type: string;
}
export interface Embedding {
! data: string;
mime_type: string;
}
--- 96,107 ----
}
export interface CucumberJsAttachment {
! data;
type: string;
}
export interface Embedding {
! data;
mime_type: string;
}
diff -r -C 3 wdio-cucumberjs-json-reporter-orig/lib/reporter.ts wdio-cucumberjs-json-reporter-main/lib/reporter.ts
*** wdio-cucumberjs-json-reporter-orig/lib/reporter.ts Wed Jul 6 07:02:18 2022
--- wdio-cucumberjs-json-reporter-main/lib/reporter.ts Tue Aug 2 13:34:52 2022
*** 56,62 ****
/**
* Attach data to the report
/
! public static attach ( data: string, type = TEXT_PLAIN ): void {
// eslint-disable-next-line @typescript-eslint/ban-types
( process.emit as Function )( 'wdioCucumberJsReporter:attachment', { data, type } );
}
--- 56,62 ----
/*
* Attach data to the report
*/
! public static attach ( data, type = TEXT_PLAIN ): void {
// eslint-disable-next-line @typescript-eslint/ban-types
( process.emit as Function )( 'wdioCucumberJsReporter:attachment', { data, type } );
}
@wswebcreation what do you think?
I can take a look at it today and fix it
Created a PR for it, see #100. Feedback is appreciated.
Closing this for now
This is not fixed in 4.4.2
The method signature for the attach method still has the data parameter as type string, so the example code still fails to compile.
Perhaps it is prudent to have test cases for documented examples...
@FrancisTaylor mind raising a PR with the missing fixes?
Can you please fix this ASAP. This is now blocking my whole team.
As a fellow open source developer I would say, get involved into the project rather than demanding to fix things ASAP. A quick internet tutorial will help and we are here if you have questions. The world as you describe it is lovely but we only have so much free time to work on these projects for free so you don't have to pay a dime to use them.
I suggest the following change:
- public static attach ( data: string, type = TEXT_PLAIN ): void {
+ public static attach ( data: any, type = TEXT_PLAIN ): void {
as I can not really tell the restrictions to the data type upstream the code.
Ahh, crap, I changed the models, but not this code.
will see if I can squeeze it in tomorrow, will go on vacation 😅
I've released a new version, see https://github.com/webdriverio-community/wdio-cucumberjs-json-reporter/releases/tag/v4.4.3. This should now properly fix it.
I totally understand the sentiment behind this, but a team is never blocked by a type that is not correct. A temporary workaround is to use the beloved/behated //@ts-ignore
in your code.
As @christian-bromann mentioned, we all do this in our spare time, trying to help the testing community. If you love to learn more about this or want to contribute then please let us know. We're not only here to provide you with code, but also with some time to help you and your team fix this yourselves 😄.
Regarding your request, this is not something that would fit in the scope of this project, but....., WebdriverIO wouldn't be as awesome if it didn't had a solution for this.
You can create a filter in the onComplete
-hook where you would read the dir you use to write the JSON files to, and parse every file (not as a JSON but text file), replace all backslashes with slashes and write the data again.
Hope this helps