Compare commits

..

10 Commits

7 changed files with 32 additions and 32 deletions

View File

@ -24,5 +24,5 @@ test.end('verify', async (stats) => {
assert.equal(stats.testFail.length, 0) assert.equal(stats.testFail.length, 0)
}) })
import { runifmain, summaryreporter, errorreporter } from '../index.js' import { runifmain } from '../index.js'
await runifmain(import.meta, () => test.run(summaryreporter(), errorreporter())) await runifmain(import.meta, test)

View File

@ -6,9 +6,15 @@ const isMain = (meta) => {
return path.includes(process.argv[1]) return path.includes(process.argv[1])
} }
const runifmain = async (meta, fn) => { import { errorreporter, summaryreporter } from '../index.js'
if (isMain(meta)) { const runifmain = async (meta, fn, ...args) => {
await fn() if (!isMain(meta)) return
if (fn.name === 'runner' && fn.run) {
if (args.length == 0) args.push(summaryreporter(), errorreporter())
await fn.run(...args)
} else {
await fn(...args)
} }
} }

View File

@ -22,5 +22,5 @@ test('Diff', () => {
} }
}) })
import { runifmain, summaryreporter, errorreporter } from '../index.js' import { runifmain } from '../index.js'
await runifmain(import.meta, () => test.run(summaryreporter(), errorreporter())) await runifmain(import.meta, test)

View File

@ -1,11 +1,15 @@
import { readdir } from 'node:fs/promises' import { readdir } from 'node:fs/promises'
import { join } from 'node:path' import { join } from 'node:path'
const walkDir = async function* (dir) { const walkDir = async function* (dir = '.', exclude = []) {
const files = await readdir(dir, { withFileTypes: true }) const files = await readdir(dir, { withFileTypes: true })
for (const file of files) { for (const file of files) {
if (exclude.includes(file.name)) continue
if (file.isDirectory()) { if (file.isDirectory()) {
yield* walkDir(join(dir, file.name)) yield* walkDir(join(dir, file.name))
} else if (file.isSymbolicLink()) {
yield* walkDir(join(dir, file.name))
} else { } else {
yield join(dir, file.name) yield join(dir, file.name)
} }
@ -34,9 +38,7 @@ const suite = async (folder = '.') => {
const total = totalreporter() const total = totalreporter()
for await (const file of walkDir(folder)) { for await (const file of walkDir(folder, ['node_modules', '.git'])) {
if (file.includes('node_modules')) continue
if (file.startsWith('.git')) continue
if (!file.endsWith('.test.js')) continue if (!file.endsWith('.test.js')) continue
const module = join(absolutePath, file) const module = join(absolutePath, file)

21
package-lock.json generated
View File

@ -1,21 +1,21 @@
{ {
"name": "metaltest", "name": "metaltest",
"version": "1.0.0", "version": "1.4.0",
"lockfileVersion": 2, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "metaltest", "name": "metaltest",
"version": "1.0.0", "version": "1.4.0",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"chalk": "^5.1.2" "chalk": "^5.3.0"
} }
}, },
"node_modules/chalk": { "node_modules/chalk": {
"version": "5.1.2", "version": "5.3.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.1.2.tgz", "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz",
"integrity": "sha512-E5CkT4jWURs1Vy5qGJye+XwCkNj7Od3Af7CP6SujMetSMkLs8Do2RWJK5yx1wamHV/op8Rz+9rltjaTQWDnEFQ==", "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==",
"engines": { "engines": {
"node": "^12.17.0 || ^14.13 || >=16.0.0" "node": "^12.17.0 || ^14.13 || >=16.0.0"
}, },
@ -23,12 +23,5 @@
"url": "https://github.com/chalk/chalk?sponsor=1" "url": "https://github.com/chalk/chalk?sponsor=1"
} }
} }
},
"dependencies": {
"chalk": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.1.2.tgz",
"integrity": "sha512-E5CkT4jWURs1Vy5qGJye+XwCkNj7Od3Af7CP6SujMetSMkLs8Do2RWJK5yx1wamHV/op8Rz+9rltjaTQWDnEFQ=="
}
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "metaltest", "name": "metaltest",
"version": "1.3.0", "version": "1.4.0",
"description": "Clone of baretest with reporting", "description": "Clone of baretest with reporting",
"type": "module", "type": "module",
"exports": "./index.js", "exports": "./index.js",
@ -14,6 +14,6 @@
"author": "Frédéric Matte <fmatte@gmail.com>", "author": "Frédéric Matte <fmatte@gmail.com>",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"chalk": "^5.1.2" "chalk": "^5.3.0"
} }
} }

View File

@ -1,5 +1,7 @@
import chalk from 'chalk' import chalk from 'chalk'
const percentage = (dividend, divisor) => (dividend / divisor * 100).toFixed(0)
const totalreporter = () => { const totalreporter = () => {
let success = 0, fail = 0, skip = 0 let success = 0, fail = 0, skip = 0
@ -7,10 +9,7 @@ const totalreporter = () => {
success: (test) => { success++ }, success: (test) => { success++ },
fail: (test, e) => { fail++ }, fail: (test, e) => { fail++ },
skip: (test) => { skip++ }, skip: (test) => { skip++ },
msg: () => `${chalk.redBright(`Fail: ${fail}`)} msg: () => `${chalk.redBright(`Fail: ${fail}`)} - ${chalk.greenBright(`Sucess: ${success}`)} - ${chalk.blueBright(`Skip: ${skip}`)} - ${chalk.yellowBright(`Ratio: ${percentage(success, success + fail)}%`)}`
${chalk.greenBright(`Sucess: ${success}`)}
${chalk.blueBright(`Skip: ${skip}`)}
${chalk.yellowBright(`Ratio ${(success / (success + fail) * 100).toFixed(0)}%`)}`
} }
} }