Skip to content

Implement static analysis of test files (Blocker for #78). #696

@jamestalmage

Description

@jamestalmage

Blocks #78.

We need a way to do static analysis of test files, specifically to discover if any use exclusive tests (i.e. test.only).

There are plenty of complications:

  1. Naming the AVA import something other than test:

    import ava from 'ava';
  2. Storing a reference to a test.only for reuse:

    const shortcut = test.serial.only;
    
    shortcut(t => t.is(...)); // will be an exclusive, serial test

    Similar can also be achieved with import statements:

    import test, {skip, todo, only} from 'ava';

    Or require statements:

    var skip = require('ava').skip;
  3. Dynamically generating tests (see [Idea]: test macros #695 possible solution).

    function testAddition(a, b, expected) {
     test(`${a} + ${b} === ${expected}`, t => t.is(a + b, expected));
    }
    
    testAddition(2, 2, 4);
    testAddition(3, 4, 7);
  4. Non-constant variables (variables that are reassigned after declaration, not referring to const here):

    var test;
    test = require('ava');

It seems possible to support 1 and 2 without a lot of pain. 3 quickly becomes impossible. I think #695 provides a solution that would allow us to cover most use cases for dynamically generating tests and still give us the ability to do the static analysis we need to. 4 just seems silly and probably not very likely in practice.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions