Skip to content

Add test utilities (skip, only, retries) to itParam #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

HoldYourWaffle
Copy link
Contributor

Title says it all, fixes #6.

This branch is based on #13, meaning it shouldn't be merged until that one's merged. I did this to avoid regressing the this-context shenanigans.

Defining these utility functions can be done manually (3f9f25c) or automatically (6521e2e), since Object.keys(it) (currently) returns just these three utility functions. This has the benefit of not having to update when mocha adds another utility function, but could potentially lead to undefined behavior if mocha adds something that is not a utility function.
The branch is currently contains the 'automatic' version, if you prefer the manual one I can revert it.

I opened this PR as a draft because I'm still working on the type definitions, unfortunately they're not as straightforward anymore.

@HoldYourWaffle
Copy link
Contributor Author

I finally managed to get the type definitions right, again with a manual and automatic variant.

@HoldYourWaffle
Copy link
Contributor Author

I just noticed that everything (defintions & code) concerning retries is probably wrong. I have never actually used that functionality before, and it looks like there's a mistake in the typescript definitions (which I based my code around). I'll investigate further...

@HoldYourWaffle
Copy link
Contributor Author

After some investigation I can only conclude that a couple of things just don't seem to add up.

  1. it.retries(x) (and thus itParam.retries) is valid, but errors at runtime

    • mocha allows it.retries, thus my automatic version allows itParam.retries.
      I'd see this as expected behavior (even though it leads to weird results here): everything you can call on it you can call on itParam.
    • I've created an issue for this over at the mocha typings to see what's going on here.
  2. Using this.retries(x) either "next to" itParam or inside the callback works as I'd expect: all tests (each value) is repeated x times (except when used inside an 'if' inside the callback).

  3. The return values of it are not accessible to the user because we're running a loop.
    This means that the user can't use the properties/functions defined here and here (including retries).
    I think it'd make sense to return an array of the return types of the it calls (by changing forEach to map). We could even add some additional functions to this array to allow for things like itParam(...).retries(x) executing retries on every element of the array.


In case you're unfamiliar with TypeScript, here's a quick (but pretty complete) overview of the language. A summary for the code I linked:

  • An interface can be seen as a 'description' of the types of properties in an object.
  • Properties marked with '?' are optional.
  • foo(bar: Baz): Qux describes a function foo with a parameter bar of type Baz and a return type of Qux.
  • (parameters): Foo in an interface without property name means that the object itself is callable (a function).
  • The type 'a' | 'b' means that the property can only be "a" or "b".

@HoldYourWaffle
Copy link
Contributor Author

Unfortunately it looks like this means that the automatic system won't work, because (as far as I know) there's no way in JS to determine if a function should be wrapped (only and skip) or simply passed through (retries).

What are your thoughts on this matter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't use mocha functions like skip() in itParam()
1 participant