Open ehmicky opened 5 years ago
If they wrapped instance might provide other arguments, there are lots of rule assumptions that go out the window.
I feel like instead of wrapping AVA, AVA should provide hooks that enable new functionality. Can you describe the problems you’re trying to solve by wrapping AVA?
I tend to iterate tests over different inputs. I love Ava but I personally find the syntax for macros not very intuitive and would prefer a syntax closer to Jest's test.each()
and Array#forEach()
.
Besides this difference of syntax, there are additional features I would like:
Array#forEach()
but it's a little verbose.Object.create(null)
should be serialized differently from {}
I have created a library test-each
that does just that:
const test = require('ava')
const { each } = require('test-each')
// The code we are testing
const multiply = require('./multiply.js')
// Run this test 4 times using every possible combination of inputs
each([0.5, 10], [2.5, 5], ({ title }, first, second) => {
test(`should mix integers and floats | ${title}`, t => {
t.is(typeof multiply(first, second), 'number')
})
})
The library is designed to work with any test runner. However I want to create an adapter for Ava to make the syntax even simpler:
const ava = require('ava')
const avaTestEach = require('ava-test-each')
const test = avaTestEach(ava)
test([0.5, 10], [2.5, 5], 'should mix integers and floats', (t, first, second) => {
t.is(typeof multiply(first, second), 'number')
})
My two concerns are:
1) Losing linting with eslint-plugin-ava
2) Monkey patching or wrapping test()
(and related test.skip()
, etc.) might be brittle. Also test()
is quite polymorphic (title can be omitted for macros, callback must be omitted with test.todo()
, extra arguments might be passed with macros) which makes wrapping harder.
Some libraries might be wrapping Ava, for example:
or:
Also the
test()
function (and its variants.skip(...)
, etc.) might be wrapped as well and provide slightly different arguments:I think this does not work with
eslint-plugin-ava
because this plugin might rely on (correct me if I'm wrong):test()
being called"ava"
test()
signature not being modifiedtest()
(that one should not be an issue though)I am considering developing a small wrapper around Ava but I am realizing using that wrapper might not be compatible with
eslint-plugin-ava
. Would it be possible to add support for such wrappers?I understand that might add lots of complexity, so feel free to close this issue if you don't think it's a good idea :)