Compare commits
10 Commits
90b20029c9
...
ac5c61b9f5
Author | SHA1 | Date |
---|---|---|
Frédéric Matte | ac5c61b9f5 | |
Frédéric Matte | 315fc7281c | |
Frédéric Matte | b9a8b2c30c | |
Frédéric Matte | e3c8fceb42 | |
Frédéric Matte | 4f096bd848 | |
Frédéric Matte | 73b1b24e71 | |
Frédéric Matte | eade7e15b3 | |
Frédéric Matte | 07f0e2a084 | |
Frédéric Matte | c91f4a466b | |
Frédéric Matte | 9f2890ce32 |
|
@ -24,5 +24,5 @@ test.end('verify', async (stats) => {
|
|||
assert.equal(stats.testFail.length, 0)
|
||||
})
|
||||
|
||||
import { runifmain, summaryreporter, errorreporter } from '../index.js'
|
||||
await runifmain(import.meta, () => test.run(summaryreporter(), errorreporter()))
|
||||
import { runifmain } from '../index.js'
|
||||
await runifmain(import.meta, test)
|
||||
|
|
|
@ -6,9 +6,15 @@ const isMain = (meta) => {
|
|||
return path.includes(process.argv[1])
|
||||
}
|
||||
|
||||
const runifmain = async (meta, fn) => {
|
||||
if (isMain(meta)) {
|
||||
await fn()
|
||||
import { errorreporter, summaryreporter } from '../index.js'
|
||||
const runifmain = async (meta, fn, ...args) => {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,5 +22,5 @@ test('Diff', () => {
|
|||
}
|
||||
})
|
||||
|
||||
import { runifmain, summaryreporter, errorreporter } from '../index.js'
|
||||
await runifmain(import.meta, () => test.run(summaryreporter(), errorreporter()))
|
||||
import { runifmain } from '../index.js'
|
||||
await runifmain(import.meta, test)
|
||||
|
|
10
lib/suite.js
10
lib/suite.js
|
@ -1,11 +1,15 @@
|
|||
import { readdir } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
const walkDir = async function* (dir) {
|
||||
const walkDir = async function* (dir = '.', exclude = []) {
|
||||
const files = await readdir(dir, { withFileTypes: true })
|
||||
|
||||
for (const file of files) {
|
||||
if (exclude.includes(file.name)) continue
|
||||
|
||||
if (file.isDirectory()) {
|
||||
yield* walkDir(join(dir, file.name))
|
||||
} else if (file.isSymbolicLink()) {
|
||||
yield* walkDir(join(dir, file.name))
|
||||
} else {
|
||||
yield join(dir, file.name)
|
||||
}
|
||||
|
@ -34,9 +38,7 @@ const suite = async (folder = '.') => {
|
|||
|
||||
const total = totalreporter()
|
||||
|
||||
for await (const file of walkDir(folder)) {
|
||||
if (file.includes('node_modules')) continue
|
||||
if (file.startsWith('.git')) continue
|
||||
for await (const file of walkDir(folder, ['node_modules', '.git'])) {
|
||||
if (!file.endsWith('.test.js')) continue
|
||||
|
||||
const module = join(absolutePath, file)
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
{
|
||||
"name": "metaltest",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"version": "1.4.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "metaltest",
|
||||
"version": "1.0.0",
|
||||
"version": "1.4.0",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"chalk": "^5.1.2"
|
||||
"chalk": "^5.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/chalk": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.1.2.tgz",
|
||||
"integrity": "sha512-E5CkT4jWURs1Vy5qGJye+XwCkNj7Od3Af7CP6SujMetSMkLs8Do2RWJK5yx1wamHV/op8Rz+9rltjaTQWDnEFQ==",
|
||||
"version": "5.3.0",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz",
|
||||
"integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==",
|
||||
"engines": {
|
||||
"node": "^12.17.0 || ^14.13 || >=16.0.0"
|
||||
},
|
||||
|
@ -23,12 +23,5 @@
|
|||
"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=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "metaltest",
|
||||
"version": "1.3.0",
|
||||
"version": "1.4.0",
|
||||
"description": "Clone of baretest with reporting",
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
|
@ -14,6 +14,6 @@
|
|||
"author": "Frédéric Matte <fmatte@gmail.com>",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"chalk": "^5.1.2"
|
||||
"chalk": "^5.3.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import chalk from 'chalk'
|
||||
|
||||
const percentage = (dividend, divisor) => (dividend / divisor * 100).toFixed(0)
|
||||
|
||||
const totalreporter = () => {
|
||||
let success = 0, fail = 0, skip = 0
|
||||
|
||||
|
@ -7,10 +9,7 @@ const totalreporter = () => {
|
|||
success: (test) => { success++ },
|
||||
fail: (test, e) => { fail++ },
|
||||
skip: (test) => { skip++ },
|
||||
msg: () => `${chalk.redBright(`Fail: ${fail}`)}
|
||||
${chalk.greenBright(`Sucess: ${success}`)}
|
||||
${chalk.blueBright(`Skip: ${skip}`)}
|
||||
${chalk.yellowBright(`Ratio ${(success / (success + fail) * 100).toFixed(0)}%`)}`
|
||||
msg: () => `${chalk.redBright(`Fail: ${fail}`)} - ${chalk.greenBright(`Sucess: ${success}`)} - ${chalk.blueBright(`Skip: ${skip}`)} - ${chalk.yellowBright(`Ratio: ${percentage(success, success + fail)}%`)}`
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue