-
Notifications
You must be signed in to change notification settings - Fork 640
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
The deno test --filter CLI option does not filter individual BDD tests #6063
Comments
This happens because we map each This probably can be fixed by changing the mapping of |
@KyleJune I'm wondering if we can switch to map everything to |
I don't think that should be done. That would break a few things listed below:
I have an idea for how we could support filtering by nested individual test cases or describe block names that would be similar to how we support only in nested test cases. However, it might require having a way for bdd to bypass the filter flag so that it can look at the flag and apply the filtering itself. In TestSuiteInternal.run, it looks at 2 flags, The change in bdd would be pretty straight forward since the existing code already checks if any steps have only set to true and will run the parent test if any of it's children have the only flag. All you would have to do is update This idea depends on how filtering is implemented. If you use the filter flag, do tests registered with the only property set to true still run? If so, I think my proposed change would work, since the callback for describe is called immediately and bdd would handle adding only flag to any tests that need it. If filter applies first and tests focused using only are ignored, this would require a change so that bdd can handle how --filter applies to the test cases it registers. I just tested this by creating the following test file and running Deno.test({ name: "my-test", fn: () => {} });
Deno.test({ name: "test-1", fn: () => {} });
Deno.test({ name: "test-2", only: true, fn: () => {} }); It ended up only running "test-1" as shown in the following output.
So to actually get this to work, we are going to need a way for bdd to signal that --filter shouldn't apply to the tests it registers, that way it can apply the filtering itself via setting the only flag based on the filter flag. One workaround that wouldn't require changing the test runner would be adding a separate flag for filtering bdd. For example, the change I suggested to bdd.ts could instead check for the flag |
With my proposal, I think the only difference between if a test is focused via the only property on the test definition vs the filter flag is that if you use the filter flag, is that it will count as a failure due to how tests are being focused. The screenshot shows the difference between test-2 being focused using the only property on the test definition vs test-1 being focused via a flag. |
Does this mean we need to have Deno API for disabling native filtering behavior and also API for getting filtering string? I think that could be an option (At least we can start discussing that change in CLI repo), but I think that would take a bit of time..
This workaround also sounds fine to me. |
Yea, for Deno to hand over filtering control to std/bdd, we would need something like that. It wouldn't have to be completely disabling native filtering behavior, it could also be exposing a way to bypass the filter on an individual test bases. For example, if a new property was added to Deno.TestDefinition called ignoreFilterFlag, we would be able to update bdd to always set that to true on tests it registers so that it can control the filtering itself.
I assumed accessing the flag is already possible via Deno.args. If the filter flag cannot be accessed, we would need a way to access it so that bdd can test each test name against the filter pattern to determine if only should be set to true. If a code change is required to expose it, my recommendation would be to expose the filter pattern so that bdd can just use it directly instead of having to parse the text to determine if it is just a string or a regexp pattern (see https://docs.deno.com/runtime/fundamentals/testing/#filtering-by-string).
Yea, I thought it would be fine to do this workaround for now if someone wants to implement this feature, although it would be a bit hidden since the CLI wouldn't show that as a flag that could be used. However, I just did a quick test by logging Deno.args and it looks like we would actually need to do |
Thanks everyone for taking a look at this. I've just noticed that only the outermost |
Describe the bug
During behavior-driven development it is useful to group
test
s intodescribe
s and also to be able to run tests individually. Thetest
/t.step
structure does not allow filtering for individual steps (and is not intended to). Therefore I resorted to the standard BDD library, but it turns our that filtering also only applies to the names ofdescribe
blocks, nottest
orit
blocks.Steps to Reproduce
bdd.ts
with the contentsdeno test --filter /2/ bdd.ts
deno test --filter "test 2" bdd.ts
Expected behavior
test 2
should execute.Environment
The text was updated successfully, but these errors were encountered: