denoland / std

The Deno Standard Library
https://jsr.io/@std
MIT License
3.23k stars 621 forks source link

The deno test --filter CLI option does not filter individual BDD tests #6063

Open dandv opened 2 months ago

dandv commented 2 months ago

Describe the bug During behavior-driven development it is useful to group tests into describes and also to be able to run tests individually. The test/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 of describe blocks, not test or it blocks.

Steps to Reproduce

  1. Create bdd.ts with the contents
    
    import { describe, test, it } from 'jsr:@std/testing/bdd';
    import { assertEquals } from '@std/assert';

describe('this is the describe', () => { test('test 1', () => { assertEquals(1, 1); }); it('test 2', () => { assertEquals(2, 2); }); });


2. Run `deno test --filter /2/ bdd.ts`
3. Run `deno test --filter "test 2" bdd.ts`

**Expected behavior**

`test 2` should execute.

**Environment**

- OS: Fedora Linux 39
- deno version: 1.46.3
- std version: 1.0.3
kt3k commented 1 week ago

This happens because we map each test/it case to test step (t.step) and test steps can't be filtered by deno test --filter option (This is by design in this way. See https://github.com/denoland/deno/issues/26997 ).

This probably can be fixed by changing the mapping of it/test case to Deno.test instead of mapping to t.step.