2018-08-01 09:16:02 -07:00
|
|
|
import fs from 'fs'
|
|
|
|
import { basename, extname, resolve } from 'path'
|
|
|
|
|
|
|
|
export const fixtures = (...args) => {
|
|
|
|
let fn = args.pop()
|
|
|
|
let options = { skip: false }
|
|
|
|
|
|
|
|
if (typeof fn !== 'function') {
|
|
|
|
options = fn
|
|
|
|
fn = args.pop()
|
|
|
|
}
|
|
|
|
|
|
|
|
const path = resolve(...args)
|
|
|
|
const files = fs.readdirSync(path)
|
|
|
|
const dir = basename(path)
|
|
|
|
const d = options.skip ? describe.skip : describe
|
|
|
|
|
|
|
|
d(dir, () => {
|
|
|
|
for (const file of files) {
|
|
|
|
const p = resolve(path, file)
|
|
|
|
const stat = fs.statSync(p)
|
|
|
|
|
|
|
|
if (stat.isDirectory()) {
|
|
|
|
fixtures(path, file, fn)
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
stat.isFile() &&
|
2020-11-24 12:30:06 -08:00
|
|
|
(file.endsWith('.js') ||
|
|
|
|
file.endsWith('.tsx') ||
|
|
|
|
file.endsWith('.ts')) &&
|
|
|
|
!file.endsWith('custom-types.ts') &&
|
|
|
|
!file.endsWith('type-guards.ts') &&
|
2018-08-01 09:16:02 -07:00
|
|
|
!file.startsWith('.') &&
|
|
|
|
// Ignoring `index.js` files allows us to use the fixtures directly
|
|
|
|
// from the top-level directory itself, instead of only children.
|
|
|
|
file !== 'index.js'
|
|
|
|
) {
|
|
|
|
const name = basename(file, extname(file))
|
|
|
|
|
|
|
|
// This needs to be a non-arrow function to use `this.skip()`.
|
2020-11-24 12:30:06 -08:00
|
|
|
it(`${name} `, function() {
|
2018-08-01 09:16:02 -07:00
|
|
|
const module = require(p)
|
|
|
|
|
|
|
|
if (module.skip) {
|
|
|
|
this.skip()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fn({ name, path, module })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fixtures.skip = (...args) => {
|
|
|
|
fixtures(...args, { skip: true })
|
|
|
|
}
|