Closed unional closed 7 years ago
Actually, I still do not get what is the situation the current API can't cover:
import test from 'ava'
import fixture from './index'
import { resolve } from 'path'
import { readdirSync } from 'fs'
import { target } from './test-target'
const cwd = resolve(process.cwd(), 'fixtures/cases')
const ftest = fixture(test, 'fixtures/cases', 'fixtures/baselines', 'fixtures/results')
const dirs = readdirSync(cwd)
dirs.forEach(testcase => {
ftest(testcase, (t, d) => {
// target.run(..., from, to)
target.run(..., d.casePath, d.resultPath)
return d.match
})
})
Seems like I still can't see what exactly you need to do in beforeEach()
.
Can you provide a concrete example?
you’re right. maybe we should just wrap this in a convenience function similar to this one:
ftest.perCase([globPattern, ][titleTemplate, ]run)
i also propose to add d.caseName, i.e. just the file name part of d.casePath.
import fixture from 'ava-fixture'
const ftest = fixture(test, 'fixtures/cases', 'fixtures/baselines', 'fixtures/results')
ftest.perCase((t, d) => {
// uses d.caseName as test title and readdirSync('fixtures/cases') as cases
…
})
ftest.perCase('test-*', (t, d) => {
// uses glob(path.join('fixtures/cases', 'test-*')) as cases
…
})
ftest.perCase(d => toTitleCase(d.caseName), (t, d) => {
// calls the function to get the test title
…
})
ftest.perCase('*.test.js', 'transforms [caseName]', (t, d) => {
// replaces [caseName] with d.caseName to get the test tile
…
})
this signature is possible because globs must contain *
and webpack-like chunk templates must contain []
.
Like that idea!
perCase
is just ad-hoc, idk if it’s the best name
Among perCase
, forEach
, iterate
, filter
, each
, I think perCase
or each
stands out most.
Other suggestions?
no, i also like those two most. we could combine them into eachCase
, but idk
What do you think?
ftest.each((t, d) => {})
ftest.each(filter, (t,d) => {})
ftest.each.failing(filter, (t,d) => {})
filter: string /* glob */ | ((caseName: string) => boolean)
d: {
caseName: string,
casePath: string,
baselinePath: string,
resultPath: string,
// this change can be added later.
match('abs or relative glob to result', 'abs or relative glob to baseline'): Promise<void>
}
Released 0.8.0
.
It is also chainable. I didn't add all permutations. But it should be sufficient. 🌷
ftest.only.each.failling()
, ftest.skip.each.failing()
🌷
@flying-sheep , what you originally ask (per file) is actually supported too #19 🌷
Continue discussion of #9
@flying-sheep lets continue the discussion here, as it is not about beforeEach anymore.
I have added you as a collaborator. Feel free to give it a try on creating this function.
Current proposal (pesudo code):