-
Notifications
You must be signed in to change notification settings - Fork 24
Bugfix/handle running parameterized tests #106
Bugfix/handle running parameterized tests #106
Conversation
Wrap tests/describes with separator for cleaner matching. This prevents partial matches from falsely being included.
480dd02
to
0bc870d
Compare
Hey @TheSench, I quite like your code style, especially where you create an array to project the ID using a fluent syntax. I see what you are doing, adding a 'closing' tag to the end of the describe and test IDs. Which makes me consider something that I had been thinking about for a while and might alter your approach. the Test Explorer host expects an ID as a unique string but internally we can use anything we like for an identifier, including an object matching public run(tests: string[]): Promise<void> {
const ids: ID[] = []; // TODO convert the tests array into an array of ID objects
return runInternal(ids);
}
private async runInternal(testIds: ID[]): Promise<void> {
// actually run the requested tests.
} Then we could just stringify the IDs instead of all the code that is currently being used for separators etc. We probably just need something that is slightly more deterministic than Alternatively, you could tackle the above in a subsequent PR if you wanted. |
PS, if you wouldn't mind having a look at #107 too. I don't have anyone to peer-review at the moment. |
@rossknudsen thank you for the compliment. I hadn't thought of that, but now that you mention it, it might simplify things if we just used ID's to match them up - I'd have to think on it. As much as the string-matching presented some problems, the |
Sure. I don't have time this moment, but I'll carve out some time later this weekend to take a look. |
Sure, just let me know whether you want this merged as is. I'm happy for it to be merged like this and address the ID thing separately. Or if you would rather it be decided before merging this piece of work, let me know. I've reviewed it and am happy with it. Thanks also for adding all the extra tests. It will make me feel more comfortable about taking it out of preview in the marketplace. |
I'm fine with leaving this PR as-is and taking a look at the JSONified-IDs in a separate PR. With the amount of time I currently have available for this type of stuff, it will probably be a week or more before I'd have these changes ready. |
Hi guys, In case you haven't seen yet, there is a new version of Jest editor support, which improves handling of parametrised tests. |
@TheSench do you want to include the new version in this PR? |
Sure, I think that makes sense. |
When I go to update the dependency, a whole bunch of other stuff gets added to |
If it's a stable version of NPM then go for it. I'll update my local version. |
We'll see if the CI pipeline can handle it. |
I ended up just pointing |
@TheSench So if I'm running version 0.8.0 (which has this PR merged) should I not be seeing this anymore?
|
Unfortunately no - you'll still see the original entry that will run all of the variations, as that's what is discovered in the code. At the time that the extension identifies what tests exist, it doesn't know enough to populate the list of actual variations (it would have to execute the code in some cases). What this PR added is the fact that the actual results now show up when you run that parameterized test. Before this change, the tests would run, but the extension would not identify them as being part of the tests it asked Jest to run, and it would throw them away, leaving you with only the |
Too bad, i was always pleasantly surprised that the mocha test adapter did seem to dynamically evaluate these and accurately show all the iterations of the test in the sidebar. Which was really nice because vscode would then prompt you when you would click "Run" or "Debug" and ask you which values you wanted to use. |
I think that would require a large rewrite of this plugin, as it currently uses jest-editor-support to discover and run the tests, and that project does all its discovery via static analysis. There might be some ways we can improve the UI (such as possibly nesting parameterized tests underneath the generic version), although I haven't looked in a while to see how many hoops we'd have to jump through for that. |
😢 I guess that's the only thing better about Mocha... |
This PR allows some forms of parameterized tests to be run directly in the test explorer (rather than having to run their non-parameterized parent). Specifically, the parameterized tests that use the form
(it|describe).each(table)(name, fn)
and useprintf
patterns in their names can now be run and matched in the results.This is achieved by a two-fold change:
testNamePattern
,printf
placeholders will be replaced by regex expressions that will loosely match the range of possible values for that type ofprintf
pattern (or the original pattern). We err on the side of matching too many so that we can ensure we always run the test selected.Partially addresses #26.