2022-12-04 16:30:05 -05:00
|
|
|
import { readdir } from 'node:fs/promises'
|
|
|
|
import { join } from 'node:path'
|
2023-01-03 23:58:50 -05:00
|
|
|
const walkDir = async function* (dir = '.', ignores = []) {
|
2022-12-04 16:30:05 -05:00
|
|
|
const files = await readdir(dir, { withFileTypes: true })
|
|
|
|
|
|
|
|
for (const file of files) {
|
2023-01-03 23:58:50 -05:00
|
|
|
if (ignores.includes(file.name)) continue
|
|
|
|
|
2022-12-04 16:30:05 -05:00
|
|
|
if (file.isDirectory()) {
|
|
|
|
yield* walkDir(join(dir, file.name))
|
|
|
|
} else {
|
|
|
|
yield join(dir, file.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
import { dirname } from 'node:path'
|
|
|
|
const getStackAbsolutePaths = () => {
|
|
|
|
const old = Error.prepareStackTrace
|
|
|
|
Error.prepareStackTrace = (_, stack) => stack
|
|
|
|
const stack = new Error().stack
|
|
|
|
Error.prepareStackTrace = old
|
|
|
|
|
|
|
|
return stack
|
|
|
|
.map(cs => cs.getFileName())
|
|
|
|
.filter(filename => filename?.startsWith('file://'))
|
|
|
|
.map(filename => dirname(fileURLToPath(filename)))
|
|
|
|
}
|
|
|
|
|
2022-12-06 20:46:14 -05:00
|
|
|
import { summaryreporter, errorreporter, totalreporter } from 'metaltest'
|
2022-12-04 16:30:05 -05:00
|
|
|
const suite = async (folder = '.') => {
|
|
|
|
const absolutePaths = getStackAbsolutePaths()
|
|
|
|
const absolutePath = absolutePaths[2]
|
2022-12-04 16:45:57 -05:00
|
|
|
const fileIgnored = []
|
2022-12-04 16:30:05 -05:00
|
|
|
|
|
|
|
const total = totalreporter()
|
|
|
|
|
2023-01-03 23:58:50 -05:00
|
|
|
for await (const file of walkDir(folder, ['node_modules', '.git'])) {
|
2022-12-05 17:08:02 -05:00
|
|
|
if (!file.endsWith('.test.js')) continue
|
2022-12-04 16:30:05 -05:00
|
|
|
|
|
|
|
const module = join(absolutePath, file)
|
|
|
|
const { test } = await import(module)
|
2022-12-04 16:45:57 -05:00
|
|
|
|
|
|
|
if (test === undefined) {
|
|
|
|
fileIgnored.push(file)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-12-06 20:46:14 -05:00
|
|
|
await test.run(summaryreporter(), errorreporter(), total)
|
2022-12-04 16:30:05 -05:00
|
|
|
}
|
|
|
|
|
2022-12-04 16:45:57 -05:00
|
|
|
for (const file of fileIgnored) {
|
|
|
|
console.log(`The file ${file} doesn't export the metaltest object`)
|
|
|
|
}
|
|
|
|
|
2022-12-04 16:30:05 -05:00
|
|
|
console.log(total.msg())
|
|
|
|
}
|
|
|
|
|
|
|
|
export { suite }
|