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)
|
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)
|
||||||
|
|
|
@ -6,10 +6,16 @@ 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { runifmain }
|
export { runifmain }
|
||||||
|
|
|
@ -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)
|
||||||
|
|
10
lib/suite.js
10
lib/suite.js
|
@ -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)
|
||||||
|
|
|
@ -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=="
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)}%`)}`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue