| | 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() && |
| | (file.endsWith('.js') || |
| | file.endsWith('.tsx') || |
| | file.endsWith('.ts')) && |
| | !file.endsWith('custom-types.ts') && |
| | !file.endsWith('type-guards.ts') && |
| | !file.startsWith('.') && |
| | |
| | |
| | file !== 'index.js' |
| | ) { |
| | const name = basename(file, extname(file)) |
| |
|
| | |
| | it(`${name} `, function () { |
| | const module = require(p) |
| |
|
| | if (module.skip) { |
| | this.skip() |
| | return |
| | } |
| |
|
| | fn({ name, path, module }) |
| | }) |
| | } |
| | } |
| | }) |
| | } |
| |
|
| | fixtures.skip = (...args) => { |
| | fixtures(...args, { skip: true }) |
| | } |
| |
|