Comparing version 3.0.0-rc.1 to 3.0.0
@@ -15,5 +15,1 @@ export type Configs = { | ||
}; | ||
export type FileResults = { | ||
success: Map<string, string>; | ||
fail: Map<string, string>; | ||
}; |
@@ -0,2 +1,7 @@ | ||
import type { AssertionError } from "assert"; | ||
import type { results } from '../configs/poku.js'; | ||
import type { Configs as ListFilesConfigs } from './list-files.js'; | ||
import type { ProcessAssertionOptions } from './assert.js'; | ||
import type { DescribeOptions } from './describe.js'; | ||
type CustomString = string & NonNullable<unknown>; | ||
export type DenoOptions = { | ||
@@ -8,2 +13,3 @@ allow?: string[]; | ||
export type Runtime = 'node' | 'bun' | 'deno'; | ||
export type Reporter = 'poku' | 'focus' | 'dot' | 'verbose' | 'compact' | 'classic' | CustomString; | ||
export type Configs = { | ||
@@ -49,2 +55,6 @@ /** | ||
/** | ||
* @default "poku" | ||
*/ | ||
reporter?: Reporter; | ||
/** | ||
* You can use this option to run a **callback** or a **file** before each test file on your suite. | ||
@@ -79,5 +89,7 @@ * | ||
} & ListFilesConfigs; | ||
export type FinalResults = { | ||
time: string; | ||
export type Timespan = { | ||
started: Date; | ||
finished: Date; | ||
/** Calculation from `process.hrtime()`. */ | ||
duration: number; | ||
}; | ||
@@ -107,2 +119,57 @@ export type States = { | ||
export type ConfigFile = Omit<Configs, 'noExit'> & cliConfigs; | ||
type Results = { | ||
code: number; | ||
timespan: Timespan; | ||
results: typeof results; | ||
}; | ||
type Path = { | ||
absolute: string; | ||
relative: string; | ||
}; | ||
export type ReporterPlugin = (configs?: Configs) => { | ||
onRunStart: () => void; | ||
onDescribeAsTitle: (title: string, options: DescribeOptions) => void; | ||
onDescribeStart: (options: { | ||
title?: string; | ||
}) => void; | ||
onDescribeEnd: (options: { | ||
title?: string; | ||
duration: number; | ||
}) => void; | ||
onItStart: (options: { | ||
title?: string; | ||
}) => void; | ||
onItEnd: (options: { | ||
title?: string; | ||
duration: number; | ||
}) => void; | ||
onAssertionSuccess: (options: { | ||
message: string; | ||
}) => void; | ||
onAssertionFailure: (options: { | ||
assertOptions: ProcessAssertionOptions; | ||
error: AssertionError; | ||
}) => void; | ||
onSkipFile: (options: { | ||
message: string; | ||
}) => void; | ||
onSkipModifier: (options: { | ||
message: string; | ||
}) => void; | ||
onTodoModifier: (options: { | ||
message: string; | ||
}) => void; | ||
onFileStart: (options: { | ||
path: Path; | ||
}) => void; | ||
onFileResult: (options: { | ||
status: boolean; | ||
path: Path; | ||
duration: number; | ||
output?: string; | ||
}) => void; | ||
onRunResult: (options: Results) => void; | ||
onExit: (options: Results) => void; | ||
}; | ||
export type ReporterEvents = Partial<ReturnType<ReporterPlugin>>; | ||
export {}; |
@@ -30,2 +30,6 @@ "use strict"; | ||
['--listFiles', 'Display all the files returned in the terminal.'], | ||
[ | ||
'--reporter, -r', | ||
'Specify the reporter: poku, dot, compact, focus, verbose, classic.', | ||
], | ||
['--only', 'Enable selective execution of tests.'], | ||
@@ -72,3 +76,3 @@ ['--quiet, -q', 'Run tests with no logs.'], | ||
const footer = ` | ||
${b('Documentation:')} ${u('https://poku.io')} | ||
${b('Documentation:')} ${u('https://poku.io/docs')} | ||
@@ -75,0 +79,0 @@ ${bullet} ${b('Poku')} is made with ${b('love')} and ${b('care')} in every detail. |
@@ -6,13 +6,14 @@ #! /usr/bin/env node | ||
const get_arg_js_1 = require("../parsers/get-arg.js"); | ||
const files_js_1 = require("../configs/files.js"); | ||
const poku_js_1 = require("../configs/poku.js"); | ||
const format_js_1 = require("../services/format.js"); | ||
const kill_js_1 = require("../modules/helpers/kill.js"); | ||
const env_js_1 = require("../modules/helpers/env.js"); | ||
const poku_js_1 = require("../modules/essentials/poku.js"); | ||
const poku_js_2 = require("../modules/essentials/poku.js"); | ||
const write_js_1 = require("../services/write.js"); | ||
const options_js_1 = require("../parsers/options.js"); | ||
const poku_js_2 = require("../configs/poku.js"); | ||
const poku_js_3 = require("../configs/poku.js"); | ||
(async () => { | ||
if ((0, get_arg_js_1.hasArg)('version') || (0, get_arg_js_1.hasArg)('v', '-')) { | ||
(0, write_js_1.log)(poku_js_2.VERSION); | ||
(0, write_js_1.log)(poku_js_3.VERSION); | ||
return; | ||
@@ -26,4 +27,4 @@ } | ||
const configFile = (0, get_arg_js_1.getArg)('config') || (0, get_arg_js_1.getArg)('c', '-'); | ||
poku_js_2.GLOBAL.configsFromFile = await (0, options_js_1.getConfigs)(configFile); | ||
const { configsFromFile } = poku_js_2.GLOBAL; | ||
poku_js_3.GLOBAL.configsFromFile = await (0, options_js_1.getConfigs)(configFile); | ||
const { configsFromFile } = poku_js_3.GLOBAL; | ||
const dirs = (0, get_arg_js_1.getPaths)('-') ?? | ||
@@ -38,2 +39,6 @@ (configsFromFile?.include | ||
const killPID = (0, get_arg_js_1.getArg)('killPid'); | ||
const reporter = (0, get_arg_js_1.getArg)('reporter') ?? | ||
(0, get_arg_js_1.getArg)('r', '-') ?? | ||
poku_js_3.GLOBAL.configsFromFile.reporter ?? | ||
'poku'; | ||
@@ -60,3 +65,3 @@ const denoAllow = (0, get_arg_js_1.argToArray)('denoAllow') ?? configsFromFile?.deno?.allow; | ||
if (dirs.length === 1) | ||
files_js_1.states.isSinglePath = true; | ||
poku_js_1.states.isSinglePath = true; | ||
if ((0, get_arg_js_1.hasArg)('listFiles')) { | ||
@@ -84,4 +89,4 @@ const { listFiles } = require('../modules/helpers/list-files.js'); | ||
} | ||
poku_js_2.GLOBAL.configFile = configFile; | ||
poku_js_2.GLOBAL.configs = { | ||
poku_js_3.GLOBAL.configFile = configFile; | ||
poku_js_3.GLOBAL.configs = { | ||
filter: typeof filter === 'string' ? new RegExp((0, list_files_js_1.escapeRegExp)(filter)) : filter, | ||
@@ -100,2 +105,3 @@ exclude: typeof exclude === 'string' ? new RegExp((0, list_files_js_1.escapeRegExp)(exclude)) : exclude, | ||
noExit: watchMode, | ||
reporter, | ||
beforeEach: 'beforeEach' in configsFromFile ? configsFromFile.beforeEach : undefined, | ||
@@ -106,3 +112,3 @@ afterEach: 'afterEach' in configsFromFile ? configsFromFile.afterEach : undefined, | ||
if (hasEnvFile || configsFromFile?.envFile) { | ||
poku_js_2.GLOBAL.envFile = (0, get_arg_js_1.getArg)('envFile') ?? configsFromFile?.envFile ?? '.env'; | ||
poku_js_3.GLOBAL.envFile = (0, get_arg_js_1.getArg)('envFile') ?? configsFromFile?.envFile ?? '.env'; | ||
} | ||
@@ -132,16 +138,18 @@ if (enforce) | ||
poku_js_2.GLOBAL.envFile && tasks.push((0, env_js_1.envFile)(poku_js_2.GLOBAL.envFile)); | ||
poku_js_3.GLOBAL.envFile && tasks.push((0, env_js_1.envFile)(poku_js_3.GLOBAL.envFile)); | ||
if (debug || configsFromFile?.debug) { | ||
(0, write_js_1.hr)(); | ||
(0, write_js_1.log)(`${(0, format_js_1.format)(' Debug Enabled ').bg('brightBlue')}\n`); | ||
(0, write_js_1.log)(`${(0, format_js_1.format)('β¦').info().italic()} ${(0, format_js_1.format)('Paths').bold()}`); | ||
console.table(dirs); | ||
(0, write_js_1.log)('\n'); | ||
(0, write_js_1.log)(`${(0, format_js_1.format)('β¦').info().italic()} ${(0, format_js_1.format)('Options').bold()}`); | ||
console.dir(poku_js_2.GLOBAL.configs, { depth: null, colors: true }); | ||
console.dir(poku_js_3.GLOBAL.configs, { | ||
depth: Number.POSITIVE_INFINITY, | ||
colors: true, | ||
}); | ||
(0, write_js_1.log)(`\n${(0, format_js_1.format)('π‘')} To list all test files, run: ${(0, format_js_1.format)('poku --listFiles').bold()}`); | ||
} | ||
await Promise.all(tasks); | ||
await (0, poku_js_1.poku)(dirs); | ||
await (0, poku_js_2.poku)(dirs); | ||
if (watchMode) | ||
await require('./watch.js').startWatch(dirs); | ||
})(); |
@@ -14,7 +14,8 @@ "use strict"; | ||
const get_arg_js_1 = require("../parsers/get-arg.js"); | ||
const files_js_1 = require("../configs/files.js"); | ||
const os_js_1 = require("../polyfills/os.js"); | ||
const poku_js_2 = require("../configs/poku.js"); | ||
const poku_js_3 = require("../services/reporters/poku.js"); | ||
const startWatch = async (dirs) => { | ||
let isRunning = false; | ||
const { configs } = poku_js_2.GLOBAL; | ||
const watchers = new Set(); | ||
@@ -27,4 +28,3 @@ const executing = new Set(); | ||
const resultsClear = () => { | ||
files_js_1.fileResults.success.clear(); | ||
files_js_1.fileResults.fail.clear(); | ||
poku_js_3.errors.length = 0; | ||
}; | ||
@@ -45,3 +45,3 @@ const listenStdin = async (input) => { | ||
resultsClear(); | ||
const mappedTests = await (0, map_tests_js_1.mapTests)('.', dirs, poku_js_2.GLOBAL.configs.filter, poku_js_2.GLOBAL.configs.exclude); | ||
const mappedTests = await (0, map_tests_js_1.mapTests)('.', dirs, configs.filter, configs.exclude); | ||
for (const mappedTest of Array.from(mappedTests.keys())) { | ||
@@ -60,4 +60,4 @@ const currentWatcher = (0, watch_js_1.watch)(mappedTest, async (file, event) => { | ||
await (0, poku_js_1.poku)(Array.from(tests), { | ||
...poku_js_2.GLOBAL.configs, | ||
concurrency: poku_js_2.GLOBAL.configs.concurrency ?? | ||
...configs, | ||
concurrency: configs.concurrency ?? | ||
Math.max(Math.floor((0, os_js_1.availableParallelism)() / 2), 1), | ||
@@ -64,0 +64,0 @@ }); |
@@ -1,6 +0,9 @@ | ||
import type { ConfigFile, ConfigJSONFile, Configs } from '../@types/poku.js'; | ||
import type { Timespan, States } from '../@types/poku.js'; | ||
import type { ConfigFile, ConfigJSONFile, Configs, Runtime } from '../@types/poku.js'; | ||
export declare const states: States; | ||
export declare const timespan: Timespan; | ||
export declare const results: { | ||
success: number; | ||
fail: number; | ||
skip: number; | ||
passed: number; | ||
failed: number; | ||
skipped: number; | ||
todo: number; | ||
@@ -15,6 +18,66 @@ }; | ||
configsFromFile: ConfigFile | ConfigJSONFile; | ||
reporter: { | ||
onRunStart: () => void; | ||
onDescribeAsTitle: (title: string, options: import("../@types/describe.js").DescribeOptions) => void; | ||
onDescribeStart: (options: { | ||
title?: string; | ||
}) => void; | ||
onDescribeEnd: (options: { | ||
title?: string; | ||
duration: number; | ||
}) => void; | ||
onItStart: (options: { | ||
title?: string; | ||
}) => void; | ||
onItEnd: (options: { | ||
title?: string; | ||
duration: number; | ||
}) => void; | ||
onAssertionSuccess: (options: { | ||
message: string; | ||
}) => void; | ||
onAssertionFailure: (options: { | ||
assertOptions: import("../@types/assert.js").ProcessAssertionOptions; | ||
error: import("assert").AssertionError; | ||
}) => void; | ||
onSkipFile: (options: { | ||
message: string; | ||
}) => void; | ||
onSkipModifier: (options: { | ||
message: string; | ||
}) => void; | ||
onTodoModifier: (options: { | ||
message: string; | ||
}) => void; | ||
onFileStart: (options: { | ||
path: { | ||
absolute: string; | ||
relative: string; | ||
}; | ||
}) => void; | ||
onFileResult: (options: { | ||
status: boolean; | ||
path: { | ||
absolute: string; | ||
relative: string; | ||
}; | ||
duration: number; | ||
output?: string; | ||
}) => void; | ||
onRunResult: (options: { | ||
code: number; | ||
timespan: Timespan; | ||
results: typeof results; | ||
}) => void; | ||
onExit: (options: { | ||
code: number; | ||
timespan: Timespan; | ||
results: typeof results; | ||
}) => void; | ||
}; | ||
isPoku: boolean; | ||
FILE: string | undefined; | ||
envFile: string | undefined; | ||
runtime: Runtime; | ||
runAsOnly: boolean; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GLOBAL = exports.deepOptions = exports.VERSION = exports.results = void 0; | ||
exports.GLOBAL = exports.deepOptions = exports.VERSION = exports.results = exports.timespan = exports.states = void 0; | ||
const node_process_1 = require("process"); | ||
const reporter_js_1 = require("../services/reporter.js"); | ||
const get_runtime_js_1 = require("../parsers/get-runtime.js"); | ||
exports.states = Object.create(null); | ||
exports.timespan = Object.create(null); | ||
exports.results = { | ||
success: 0, | ||
fail: 0, | ||
skip: 0, | ||
passed: 0, | ||
failed: 0, | ||
skipped: 0, | ||
todo: 0, | ||
}; | ||
exports.VERSION = '3.0.0-rc.1'; | ||
exports.VERSION = '3.0.0'; | ||
exports.deepOptions = []; | ||
@@ -18,6 +22,8 @@ exports.GLOBAL = { | ||
configsFromFile: Object.create(null), | ||
isPoku: typeof node_process_1.env?.POKU_FILE === 'string' && node_process_1.env?.POKU_FILE.length > 0, | ||
reporter: reporter_js_1.reporter[node_process_1.env.POKU_REPORTER || 'poku'](), | ||
isPoku: typeof node_process_1.env.POKU_FILE === 'string' && node_process_1.env.POKU_FILE.length > 0, | ||
FILE: node_process_1.env.POKU_FILE, | ||
envFile: undefined, | ||
runtime: (node_process_1.env.POKU_RUNTIME || (0, get_runtime_js_1.getRuntime)()), | ||
runAsOnly: false, | ||
}; |
@@ -9,8 +9,7 @@ "use strict"; | ||
const node_process_1 = __importDefault(require("process")); | ||
const write_js_1 = require("../../services/write.js"); | ||
const exit_js_1 = require("../helpers/exit.js"); | ||
const format_js_1 = require("../../services/format.js"); | ||
const files_js_1 = require("../../configs/files.js"); | ||
const poku_js_1 = require("../../configs/poku.js"); | ||
const run_tests_js_1 = require("../../services/run-tests.js"); | ||
const poku_js_1 = require("../../configs/poku.js"); | ||
const poku_js_2 = require("../../configs/poku.js"); | ||
const reporter_js_1 = require("../../services/reporter.js"); | ||
@@ -23,13 +22,14 @@ const onSigint = () => node_process_1.default.stdout.write('\u001B[?25h'); | ||
if (configs) | ||
poku_js_1.GLOBAL.configs = { ...poku_js_1.GLOBAL.configs, ...configs }; | ||
files_js_1.finalResults.started = new Date(); | ||
poku_js_2.GLOBAL.configs = { ...poku_js_2.GLOBAL.configs, ...configs }; | ||
poku_js_1.timespan.started = new Date(); | ||
const start = node_process_1.default.hrtime(); | ||
const dirs = Array.prototype.concat(targetPaths); | ||
const showLogs = !poku_js_1.GLOBAL.configs.quiet; | ||
if (showLogs) { | ||
(0, write_js_1.hr)(); | ||
(0, write_js_1.log)(`${(0, format_js_1.format)('Running Tests').bold()}\n`); | ||
} | ||
const paths = Array.prototype.concat(targetPaths); | ||
const showLogs = !poku_js_2.GLOBAL.configs.quiet; | ||
const { reporter: plugin } = poku_js_2.GLOBAL.configs; | ||
if (typeof plugin === 'string' && plugin !== 'poku') | ||
poku_js_2.GLOBAL.reporter = reporter_js_1.reporter[plugin](); | ||
if (showLogs) | ||
poku_js_2.GLOBAL.reporter.onRunStart(); | ||
try { | ||
const promises = dirs.map(async (dir) => await (0, run_tests_js_1.runTests)(dir)); | ||
const promises = paths.map(async (dir) => await (0, run_tests_js_1.runTests)(dir)); | ||
const concurrency = await Promise.all(promises); | ||
@@ -41,9 +41,11 @@ if (concurrency.some((result) => !result)) | ||
const end = node_process_1.default.hrtime(start); | ||
const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6); | ||
files_js_1.finalResults.time = total; | ||
const total = end[0] * 1e3 + end[1] / 1e6; | ||
poku_js_1.timespan.duration = total; | ||
poku_js_1.timespan.finished = new Date(); | ||
} | ||
showLogs && (0, format_js_1.showTestResults)(); | ||
if (poku_js_1.GLOBAL.configs.noExit) | ||
if (showLogs) | ||
poku_js_2.GLOBAL.reporter.onRunResult({ code, timespan: poku_js_1.timespan, results: poku_js_1.results }); | ||
if (poku_js_2.GLOBAL.configs.noExit) | ||
return code; | ||
(0, exit_js_1.exit)(code, poku_js_1.GLOBAL.configs.quiet); | ||
(0, exit_js_1.exit)(code, poku_js_2.GLOBAL.configs.quiet); | ||
} |
@@ -5,7 +5,8 @@ "use strict"; | ||
const assert_js_1 = require("../../builders/assert.js"); | ||
const get_runtime_js_1 = require("../../parsers/get-runtime.js"); | ||
const poku_js_1 = require("../../configs/poku.js"); | ||
const runtime_version_js_1 = require("../../parsers/runtime-version.js"); | ||
const nodeAssert = !get_runtime_js_1.nodeVersion || get_runtime_js_1.nodeVersion >= 16 | ||
const nodeAssert = poku_js_1.GLOBAL.runtime !== 'node' || runtime_version_js_1.runtimeVersion >= 16 | ||
? require("assert/strict") | ||
: require("assert"); | ||
exports.strict = (0, assert_js_1.createAssert)(nodeAssert); |
@@ -14,2 +14,3 @@ "use strict"; | ||
const write_js_1 = require("../../services/write.js"); | ||
const os_js_1 = require("../../parsers/os.js"); | ||
const runningProcesses = new Map(); | ||
@@ -24,5 +25,5 @@ const backgroundProcess = (runtime, args, file, options) => new Promise((resolve, reject) => { | ||
cwd: options?.cwd ? (0, list_files_js_1.sanitizePath)((0, node_path_1.normalize)(options.cwd)) : undefined, | ||
shell: get_runner_js_1.isWindows, | ||
detached: !get_runner_js_1.isWindows, | ||
windowsHide: get_runner_js_1.isWindows, | ||
shell: os_js_1.isWindows, | ||
detached: !os_js_1.isWindows, | ||
windowsHide: os_js_1.isWindows, | ||
}); | ||
@@ -36,3 +37,3 @@ const PID = service.pid; | ||
runningProcesses.delete(PID); | ||
if (get_runner_js_1.isWindows) { | ||
if (os_js_1.isWindows) { | ||
kill_js_1.kill.pid(PID); | ||
@@ -39,0 +40,0 @@ return; |
@@ -6,5 +6,2 @@ "use strict"; | ||
const node_process_1 = require("process"); | ||
const format_js_1 = require("../../services/format.js"); | ||
const write_js_1 = require("../../services/write.js"); | ||
const indentation_js_1 = require("../../configs/indentation.js"); | ||
const modifiers_js_1 = require("./modifiers.js"); | ||
@@ -18,2 +15,3 @@ const get_arg_js_1 = require("../../parsers/get-arg.js"); | ||
let options; | ||
const { reporter } = poku_js_1.GLOBAL; | ||
if (typeof arg1 === 'string') { | ||
@@ -30,13 +28,10 @@ title = arg1; | ||
} | ||
const hasCB = typeof cb === 'function'; | ||
if (title) { | ||
indentation_js_1.indentation.hasDescribe = true; | ||
const { background, icon } = options ?? Object.create(null); | ||
const message = `${cb ? (0, format_js_1.format)('β').dim() : (icon ?? 'β°')} ${cb ? (0, format_js_1.format)(title).dim() : (0, format_js_1.format)(title).bold()}`; | ||
const noBackground = !background; | ||
if (noBackground) | ||
(0, write_js_1.log)((0, format_js_1.format)(message).bold()); | ||
if (hasCB) | ||
reporter.onDescribeStart({ title }); | ||
else | ||
(0, write_js_1.log)((0, format_js_1.format)(` ${message} `).bg(typeof background === 'string' ? background : 'grey')); | ||
reporter.onDescribeAsTitle(title, options); | ||
} | ||
if (typeof cb !== 'function') | ||
if (!hasCB) | ||
return; | ||
@@ -50,6 +45,5 @@ const start = (0, node_process_1.hrtime)(); | ||
return; | ||
const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6); | ||
const duration = end[0] * 1e3 + end[1] / 1e6; | ||
reporter.onDescribeEnd({ title, duration }); | ||
poku_js_1.GLOBAL.runAsOnly = false; | ||
indentation_js_1.indentation.hasDescribe = false; | ||
(0, write_js_1.log)(`${(0, format_js_1.format)(`β ${title}`).success().bold()} ${(0, format_js_1.format)(`βΊ ${total}ms`).success().dim()}`); | ||
} | ||
@@ -56,0 +50,0 @@ async function describeCore(messageOrCb, cbOrOptions) { |
@@ -9,43 +9,11 @@ "use strict"; | ||
const poku_js_1 = require("../../configs/poku.js"); | ||
const format_js_1 = require("../../services/format.js"); | ||
const write_js_1 = require("../../services/write.js"); | ||
const files_js_1 = require("../../configs/files.js"); | ||
const time_js_1 = require("../../parsers/time.js"); | ||
const poku_js_2 = require("../../configs/poku.js"); | ||
const node_assert_1 = require("assert"); | ||
const exit = (code, quiet) => { | ||
const isPoku = poku_js_1.results.success > 0 || poku_js_1.results.fail > 0; | ||
const success = ` PASS βΊ ${poku_js_1.results.success} `; | ||
const failure = ` FAIL βΊ ${poku_js_1.results.fail} `; | ||
const skips = ` SKIP βΊ ${poku_js_1.results.skip} `; | ||
const plans = ` TODO βΊ ${poku_js_1.results.todo} `; | ||
const inline = poku_js_1.results.skip === 0 || poku_js_1.results.todo === 0; | ||
let message = ''; | ||
if (inline) { | ||
message += `${(0, format_js_1.format)(success).bg('green')} ${(0, format_js_1.format)(failure).bg(poku_js_1.results.fail === 0 ? 'grey' : 'brightRed')}`; | ||
if (poku_js_1.results.skip) | ||
message += ` ${(0, format_js_1.format)(skips).bg('brightBlue')}`; | ||
if (poku_js_1.results.todo) | ||
message += ` ${(0, format_js_1.format)(plans).bg('brightBlue')}`; | ||
} | ||
else { | ||
message += `${(0, format_js_1.format)(success).success().bold()}\n`; | ||
message += | ||
poku_js_1.results.fail === 0 | ||
? (0, format_js_1.format)(`${failure}\n`).bold() | ||
: `${(0, format_js_1.format)(failure).fail().bold()}\n`; | ||
message += `${(0, format_js_1.format)(skips).info().bold()}\n`; | ||
message += `${(0, format_js_1.format)(plans).info().bold()}`; | ||
} | ||
!quiet && | ||
node_process_1.default.on('exit', (code) => { | ||
if (isPoku) { | ||
(0, write_js_1.hr)(); | ||
(0, write_js_1.log)(` ${(0, format_js_1.format)(`Start at βΊ ${(0, format_js_1.format)(`${(0, time_js_1.parseTime)(files_js_1.finalResults.started)}`).bold()}`).dim()}`); | ||
(0, write_js_1.log)(` ${(0, format_js_1.format)('Duration βΊ').dim()} ${(0, format_js_1.format)(`${files_js_1.finalResults.time}ms`).bold().dim()} ${(0, format_js_1.format)(`(Β±${(0, time_js_1.parseTimeToSecs)(files_js_1.finalResults.time)} seconds)`).dim()}`); | ||
(0, write_js_1.log)(` ${(0, format_js_1.format)(`Test Files βΊ ${(0, format_js_1.format)(String(files_js_1.fileResults.success.size + files_js_1.fileResults.fail.size)).bold()}`).dim()}`); | ||
(0, write_js_1.hr)(); | ||
(0, write_js_1.log)(message); | ||
(0, write_js_1.hr)(); | ||
} | ||
(0, write_js_1.log)(`${(0, format_js_1.format)('Exited with code').dim()} ${(0, format_js_1.format)(String(code)).bold()[code === 0 ? 'success' : 'fail']()}\n`); | ||
const isPoku = poku_js_1.results.passed > 0 || poku_js_1.results.failed > 0; | ||
if (!quiet && isPoku) | ||
poku_js_1.GLOBAL.reporter.onExit({ | ||
code, | ||
timespan: poku_js_2.timespan, | ||
results: poku_js_1.results, | ||
}); | ||
@@ -55,3 +23,2 @@ node_process_1.default.exitCode = code === 0 ? 0 : 1; | ||
exports.exit = exit; | ||
node_process_1.default.on('unhandledRejection', (err) => { | ||
@@ -62,2 +29,3 @@ if (!(err instanceof node_assert_1.AssertionError)) | ||
}); | ||
node_process_1.default.on('uncaughtException', (err) => { | ||
@@ -68,2 +36,1 @@ if (!(err instanceof node_assert_1.AssertionError)) | ||
}); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getPIDs = void 0; | ||
const get_runner_js_1 = require("../../parsers/get-runner.js"); | ||
const os_js_1 = require("../../parsers/os.js"); | ||
const pid_js_1 = require("../../services/pid.js"); | ||
@@ -10,3 +10,3 @@ const getPIDsByPorts = async (port) => { | ||
await Promise.all(ports.map(async (p) => { | ||
PIDs.push(...(await (get_runner_js_1.isWindows | ||
PIDs.push(...(await (os_js_1.isWindows | ||
? pid_js_1.getPIDs.windows(p) | ||
@@ -13,0 +13,0 @@ : pid_js_1.getPIDs.unix(p)))); |
@@ -6,4 +6,4 @@ import { todo, skip, onlyIt } from '../modifiers.js'; | ||
]): Promise<void>; | ||
declare function itCore(message: string, cb: () => Promise<unknown>): Promise<void>; | ||
declare function itCore(message: string, cb: () => unknown): void; | ||
declare function itCore(title: string, cb: () => Promise<unknown>): Promise<void>; | ||
declare function itCore(title: string, cb: () => unknown): void; | ||
declare function itCore(cb: () => Promise<unknown>): Promise<void>; | ||
@@ -10,0 +10,0 @@ declare function itCore(cb: () => unknown): void; |
@@ -8,4 +8,2 @@ "use strict"; | ||
const indentation_js_1 = require("../../../configs/indentation.js"); | ||
const format_js_1 = require("../../../services/format.js"); | ||
const write_js_1 = require("../../../services/write.js"); | ||
const modifiers_js_1 = require("../modifiers.js"); | ||
@@ -16,6 +14,6 @@ const get_arg_js_1 = require("../../../parsers/get-arg.js"); | ||
try { | ||
let message; | ||
let title; | ||
let cb; | ||
if (typeof args[0] === 'string') { | ||
message = args[0]; | ||
title = args[0]; | ||
cb = args[1]; | ||
@@ -25,6 +23,3 @@ } | ||
cb = args[0]; | ||
if (message) { | ||
indentation_js_1.indentation.hasItOrTest = true; | ||
(0, write_js_1.log)(`${indentation_js_1.indentation.hasDescribe ? ' ' : ''}${(0, format_js_1.format)(`β ${message}`).dim()}`); | ||
} | ||
poku_js_1.GLOBAL.reporter.onItStart({ title }); | ||
if (typeof each_js_1.each.before.cb === 'function') { | ||
@@ -45,7 +40,6 @@ const beforeResult = each_js_1.each.before.cb(); | ||
} | ||
if (!message) | ||
if (!title) | ||
return; | ||
const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6); | ||
indentation_js_1.indentation.hasItOrTest = false; | ||
(0, write_js_1.log)(`${indentation_js_1.indentation.hasDescribe ? ' ' : ''}${(0, format_js_1.format)(`β ${message}`).success().bold()} ${(0, format_js_1.format)(`βΊ ${total}ms`).success().dim()}`); | ||
const duration = end[0] * 1e3 + end[1] / 1e6; | ||
poku_js_1.GLOBAL.reporter.onItEnd({ title, duration }); | ||
} | ||
@@ -62,15 +56,15 @@ catch (error) { | ||
} | ||
async function itCore(messageOrCb, cb) { | ||
async function itCore(titleOrCb, cb) { | ||
if (get_arg_js_1.hasOnly) { | ||
if (!poku_js_1.GLOBAL.runAsOnly) | ||
return; | ||
if (typeof messageOrCb === 'string' && typeof cb === 'function') | ||
return itBase(messageOrCb, cb); | ||
if (typeof messageOrCb === 'function') | ||
return itBase(messageOrCb); | ||
if (typeof titleOrCb === 'string' && typeof cb === 'function') | ||
return itBase(titleOrCb, cb); | ||
if (typeof titleOrCb === 'function') | ||
return itBase(titleOrCb); | ||
} | ||
if (typeof messageOrCb === 'string' && cb) | ||
return itBase(messageOrCb, cb); | ||
if (typeof messageOrCb === 'function') | ||
return itBase(messageOrCb); | ||
if (typeof titleOrCb === 'string' && cb) | ||
return itBase(titleOrCb, cb); | ||
if (typeof titleOrCb === 'function') | ||
return itBase(titleOrCb); | ||
} | ||
@@ -77,0 +71,0 @@ exports.it = Object.assign(itCore, { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.kill = void 0; | ||
const get_runner_js_1 = require("../../parsers/get-runner.js"); | ||
const os_js_1 = require("../../parsers/os.js"); | ||
const pid_js_1 = require("../../services/pid.js"); | ||
@@ -10,3 +10,3 @@ const get_pids_js_1 = require("./get-pids.js"); | ||
await Promise.all(PIDs.map(async (p) => { | ||
get_runner_js_1.isWindows | ||
os_js_1.isWindows | ||
? await pid_js_1.killPID.windows(p) | ||
@@ -13,0 +13,0 @@ : await pid_js_1.killPID.unix(p); |
@@ -7,3 +7,3 @@ "use strict"; | ||
const promises_1 = require("fs/promises"); | ||
const files_js_1 = require("../../configs/files.js"); | ||
const poku_js_1 = require("../../configs/poku.js"); | ||
const regex = { | ||
@@ -69,3 +69,3 @@ sep: /[/\\]+/g, | ||
return; | ||
if (isFullPath && files_js_1.states?.isSinglePath) | ||
if (isFullPath && poku_js_1.states?.isSinglePath) | ||
return files.add(fullPath); | ||
@@ -72,0 +72,0 @@ if (exclude) |
@@ -9,3 +9,2 @@ "use strict"; | ||
const write_js_1 = require("../../services/write.js"); | ||
const indentation_js_1 = require("../../configs/indentation.js"); | ||
const format_js_1 = require("../../services/format.js"); | ||
@@ -17,8 +16,9 @@ const core_js_1 = require("./it/core.js"); | ||
const poku_js_1 = require("../../configs/poku.js"); | ||
async function todo(message, _cb) { | ||
(0, write_js_1.log)(`${indentation_js_1.indentation.hasDescribe ? ' ' : ''}${(0, format_js_1.format)(`β ${message}`).cyan().bold()}`); | ||
async function todo(messageOrCb, _cb) { | ||
const message = typeof messageOrCb === 'string' ? messageOrCb : 'Planning'; | ||
poku_js_1.GLOBAL.reporter.onTodoModifier({ message }); | ||
} | ||
async function skip(messageOrCb, _cb) { | ||
const message = typeof messageOrCb === 'string' ? messageOrCb : 'Skipping'; | ||
(0, write_js_1.log)(`${indentation_js_1.indentation.hasDescribe ? ' ' : ''}${(0, format_js_1.format)(`β― ${message}`).info().bold()}`); | ||
poku_js_1.GLOBAL.reporter.onSkipModifier({ message }); | ||
} | ||
@@ -25,0 +25,0 @@ async function onlyDescribe(messageOrCb, cb) { |
@@ -5,15 +5,8 @@ "use strict"; | ||
const node_process_1 = require("process"); | ||
const write_js_1 = require("../../services/write.js"); | ||
const format_js_1 = require("../../services/format.js"); | ||
const poku_js_1 = require("../../configs/poku.js"); | ||
const skip = (message = 'Skipping') => { | ||
const { isPoku, FILE } = poku_js_1.GLOBAL; | ||
if (message) | ||
(0, write_js_1.log)((0, format_js_1.format)(isPoku | ||
? `β― ${message} ${(0, format_js_1.format)('βΊ').dim()} ${(0, format_js_1.format)(`${FILE}`).italic().gray().dim()}` | ||
: `β― ${message}`) | ||
.info() | ||
.bold()); | ||
poku_js_1.GLOBAL.reporter.onSkipFile({ message }); | ||
(0, node_process_1.exit)(0); | ||
}; | ||
exports.skip = skip; |
export declare const test: { | ||
(message: string, cb: () => Promise<unknown>): Promise<void>; | ||
(message: string, cb: () => unknown): void; | ||
(title: string, cb: () => Promise<unknown>): Promise<void>; | ||
(title: string, cb: () => unknown): void; | ||
(cb: () => Promise<unknown>): Promise<void>; | ||
@@ -5,0 +5,0 @@ (cb: () => unknown): void; |
import type { Runner } from '../@types/runner.js'; | ||
export declare const isWindows: boolean; | ||
export declare const runner: (filename: string) => string[]; | ||
export declare const scriptRunner: (runner: Runner) => string[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.scriptRunner = exports.runner = exports.isWindows = void 0; | ||
const node_process_1 = require("process"); | ||
exports.scriptRunner = exports.runner = void 0; | ||
const node_path_1 = require("path"); | ||
const get_runtime_js_1 = require("./get-runtime.js"); | ||
const poku_js_1 = require("../configs/poku.js"); | ||
exports.isWindows = node_process_1.platform === 'win32'; | ||
const os_js_1 = require("./os.js"); | ||
const runner = (filename) => { | ||
const runtime = (0, get_runtime_js_1.getRuntime)(); | ||
const { configs, runtime } = poku_js_1.GLOBAL; | ||
if (runtime === 'bun') | ||
return ['bun']; | ||
if (runtime === 'deno') { | ||
const denoAllow = poku_js_1.GLOBAL.configs.deno?.allow | ||
? poku_js_1.GLOBAL.configs.deno.allow | ||
const denoAllow = configs.deno?.allow | ||
? configs.deno.allow | ||
.map((allow) => (allow ? `--allow-${allow}` : '')) | ||
.filter((allow) => allow) | ||
: ['--allow-read', '--allow-env', '--allow-run', '--allow-net']; | ||
const denoDeny = poku_js_1.GLOBAL.configs.deno?.deny | ||
? poku_js_1.GLOBAL.configs.deno.deny | ||
const denoDeny = configs.deno?.deny | ||
? configs.deno.deny | ||
.map((deny) => (deny ? `--deny-${deny}` : '')) | ||
@@ -28,3 +26,3 @@ .filter((deny) => deny) | ||
return ['.ts', '.mts', '.cts'].includes((0, node_path_1.extname)(filename)) | ||
? [exports.isWindows ? 'npx.cmd' : 'npx', 'tsx'] | ||
? [os_js_1.isWindows ? 'npx.cmd' : 'npx', 'tsx'] | ||
: ['node']; | ||
@@ -35,3 +33,3 @@ }; | ||
const commands = { | ||
npm: [exports.isWindows ? 'npm.cmd' : 'npm', 'run'], | ||
npm: [os_js_1.isWindows ? 'npm.cmd' : 'npm', 'run'], | ||
bun: ['bun', 'run'], | ||
@@ -38,0 +36,0 @@ deno: ['deno', 'task'], |
import type { Runtime } from '../@types/poku.js'; | ||
export declare const getRuntime: () => Runtime; | ||
export declare const nodeVersion: number | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.nodeVersion = exports.getRuntime = void 0; | ||
exports.getRuntime = void 0; | ||
const node_process_1 = require("process"); | ||
const regex = /v(\d+)\./; | ||
const node_path_1 = require("path"); | ||
const getRuntime = () => { | ||
if (node_process_1.env.POKU_RUNTIME) | ||
return node_process_1.env.POKU_RUNTIME; | ||
const { _, POKU_RUNTIME } = node_process_1.env; | ||
if (POKU_RUNTIME) | ||
return POKU_RUNTIME; | ||
if (typeof _ === 'string') { | ||
const bin = (0, node_path_1.basename)(_); | ||
if (bin.indexOf('bun') !== -1) | ||
return 'bun'; | ||
if (bin.indexOf('deno') !== -1) | ||
return 'deno'; | ||
if (bin.indexOf('node') !== -1 || bin.indexOf('tsx') !== -1) | ||
return 'node'; | ||
} | ||
if (typeof Deno !== 'undefined') | ||
@@ -16,2 +28,1 @@ return 'deno'; | ||
exports.getRuntime = getRuntime; | ||
exports.nodeVersion = (0, exports.getRuntime)() === 'node' ? Number(node_process_1.version.match(regex)?.[1]) : undefined; |
@@ -8,3 +8,3 @@ "use strict"; | ||
const poku_js_1 = require("../configs/poku.js"); | ||
const get_runner_js_1 = require("./get-runner.js"); | ||
const os_js_1 = require("./os.js"); | ||
const getConfigs = async (customPath) => { | ||
@@ -22,3 +22,3 @@ const expectedFiles = customPath | ||
let path = ''; | ||
if (get_runner_js_1.isWindows) | ||
if (os_js_1.isWindows) | ||
path += 'file://'; | ||
@@ -25,0 +25,0 @@ path += (0, node_path_1.normalize)(filePath); |
@@ -15,3 +15,3 @@ "use strict"; | ||
if (hasSkip) | ||
poku_js_1.results.skip += hasSkip.length; | ||
poku_js_1.results.skipped += hasSkip.length; | ||
const hasTodo = normalizedOutput.match(regex.todo); | ||
@@ -18,0 +18,0 @@ if (hasTodo) |
export declare const parseTime: (date: Date) => string; | ||
export declare const parseTimeToSecs: (milliseconds: string) => string; | ||
export declare const parseTimeToSecs: (milliseconds: number) => string; |
@@ -12,6 +12,3 @@ "use strict"; | ||
exports.parseTime = parseTime; | ||
const parseTimeToSecs = (milliseconds) => { | ||
const ms = Number(milliseconds); | ||
return (ms / 1000).toFixed(2); | ||
}; | ||
const parseTimeToSecs = (milliseconds) => (milliseconds / 1000).toFixed(2); | ||
exports.parseTimeToSecs = parseTimeToSecs; |
@@ -10,73 +10,15 @@ "use strict"; | ||
const node_process_1 = __importDefault(require("process")); | ||
const node_path_1 = __importDefault(require("path")); | ||
const find_file_from_stack_js_1 = require("../parsers/find-file-from-stack.js"); | ||
const assert_js_1 = require("../parsers/assert.js"); | ||
const indentation_js_1 = require("../configs/indentation.js"); | ||
const format_js_1 = require("./format.js"); | ||
const write_js_1 = require("./write.js"); | ||
const poku_js_1 = require("../configs/poku.js"); | ||
const { cwd } = poku_js_1.GLOBAL; | ||
const regexFile = /file:(\/\/)?/; | ||
const assertProcessor = () => { | ||
const { isPoku, FILE } = poku_js_1.GLOBAL; | ||
let preIdentation = ''; | ||
const handleSuccess = (options) => { | ||
if (typeof options.message === 'string') { | ||
if (indentation_js_1.indentation.hasDescribe) | ||
preIdentation += ' '; | ||
if (indentation_js_1.indentation.hasItOrTest) | ||
preIdentation += ' '; | ||
const message = isPoku && !indentation_js_1.indentation.hasDescribe && !indentation_js_1.indentation.hasItOrTest | ||
? `${preIdentation}${(0, format_js_1.format)(`${(0, format_js_1.format)(`β ${options.message}`).bold()} ${(0, format_js_1.format)(`βΊ ${FILE}`).success().dim()}`).success()}` | ||
: `${preIdentation}${(0, format_js_1.format)(`β ${options.message}`).success().bold()}`; | ||
(0, write_js_1.log)(message); | ||
} | ||
preIdentation = ''; | ||
const { isPoku, reporter } = poku_js_1.GLOBAL; | ||
const handleSuccess = ({ message }) => { | ||
if (typeof message === 'string') | ||
reporter.onAssertionSuccess({ message }); | ||
}; | ||
const handleError = (error, options) => { | ||
node_process_1.default.exitCode = 1; | ||
if (error instanceof node_assert_1.AssertionError) { | ||
const { code, actual, expected, operator } = error; | ||
const absolutePath = (0, find_file_from_stack_js_1.findFile)(error).replace(regexFile, ''); | ||
const file = node_path_1.default.relative(node_path_1.default.resolve(cwd), absolutePath); | ||
if (indentation_js_1.indentation.hasDescribe) | ||
preIdentation += ' '; | ||
if (indentation_js_1.indentation.hasItOrTest) | ||
preIdentation += ' '; | ||
let message = ''; | ||
if (typeof options.message === 'string') | ||
message = options.message; | ||
else if (options.message instanceof Error) | ||
message = options.message.message; | ||
else if (typeof options.defaultMessage === 'string') | ||
message = options.defaultMessage; | ||
const finalMessage = message?.trim().length > 0 | ||
? (0, format_js_1.format)(`β ${message}`).fail().bold() | ||
: (0, format_js_1.format)('β Assertion Error').fail().bold(); | ||
(0, write_js_1.log)(isPoku | ||
? `${preIdentation}${finalMessage} ${(0, format_js_1.format)(`βΊ ${FILE}`).fail().dim()}` | ||
: `${preIdentation}${finalMessage}`); | ||
file && (0, write_js_1.log)(`${(0, format_js_1.format)(`${preIdentation} File`).dim()} ${file}`); | ||
(0, write_js_1.log)(`${(0, format_js_1.format)(`${preIdentation} Code`).dim()} ${code}`); | ||
(0, write_js_1.log)(`${(0, format_js_1.format)(`${preIdentation} Operator`).dim()} ${operator}\n`); | ||
if (!options?.hideDiff) { | ||
const splitActual = (0, assert_js_1.parseResultType)(actual).split('\n'); | ||
const splitExpected = (0, assert_js_1.parseResultType)(expected).split('\n'); | ||
(0, write_js_1.log)((0, format_js_1.format)(`${preIdentation} ${options?.actual ?? 'Actual'}:`).dim()); | ||
for (const line of splitActual) | ||
(0, write_js_1.log)(`${preIdentation} ${(0, format_js_1.format)(line).fail().bold()}`); | ||
(0, write_js_1.log)(`\n${preIdentation} ${(0, format_js_1.format)(`${options?.expected ?? 'Expected'}:`).dim()}`); | ||
for (const line of splitExpected) | ||
(0, write_js_1.log)(`${preIdentation} ${(0, format_js_1.format)(line).success().bold()}`); | ||
preIdentation = ''; | ||
} | ||
if (options.throw) { | ||
console.error(error); | ||
(0, write_js_1.hr)(); | ||
} | ||
if (isPoku) | ||
throw error; | ||
} | ||
throw error; | ||
if (error instanceof node_assert_1.AssertionError) | ||
reporter.onAssertionFailure({ assertOptions: options, error }); | ||
if (isPoku) | ||
throw error; | ||
}; | ||
@@ -83,0 +25,0 @@ const processAssert = (cb, options) => { |
@@ -6,20 +6,18 @@ "use strict"; | ||
const write_js_1 = require("../services/write.js"); | ||
const get_runner_js_1 = require("../parsers/get-runner.js"); | ||
const os_js_1 = require("../parsers/os.js"); | ||
const list_files_js_1 = require("../modules/helpers/list-files.js"); | ||
const runDockerCommand = (command, args, options, verbose) => { | ||
return new Promise((resolve) => { | ||
const dockerProcess = (0, node_child_process_1.spawn)(command, args, { | ||
...options, | ||
shell: get_runner_js_1.isWindows, | ||
}); | ||
if (verbose) { | ||
dockerProcess.stdout.setEncoding('utf8'); | ||
dockerProcess.stderr.setEncoding('utf8'); | ||
dockerProcess.stdout.on('data', write_js_1.log); | ||
dockerProcess.stderr.on('data', write_js_1.log); | ||
} | ||
dockerProcess.on('close', (code) => resolve(code === 0)); | ||
dockerProcess.on('error', () => resolve(false)); | ||
const runDockerCommand = (command, args, options, verbose) => new Promise((resolve) => { | ||
const dockerProcess = (0, node_child_process_1.spawn)(command, args, { | ||
...options, | ||
shell: os_js_1.isWindows, | ||
}); | ||
}; | ||
if (verbose) { | ||
dockerProcess.stdout.setEncoding('utf8'); | ||
dockerProcess.stderr.setEncoding('utf8'); | ||
dockerProcess.stdout.on('data', write_js_1.log); | ||
dockerProcess.stderr.on('data', write_js_1.log); | ||
} | ||
dockerProcess.on('close', (code) => resolve(code === 0)); | ||
dockerProcess.on('error', () => resolve(false)); | ||
}); | ||
class DockerContainer { | ||
@@ -26,0 +24,0 @@ constructor(configs) { |
@@ -8,6 +8,7 @@ "use strict"; | ||
const eachCore = async (type, fileRelative) => { | ||
if (typeof poku_js_1.GLOBAL.configs?.[type] !== 'function') | ||
const { configs } = poku_js_1.GLOBAL; | ||
if (typeof configs?.[type] !== 'function') | ||
return true; | ||
const cb = poku_js_1.GLOBAL.configs[type]; | ||
const showLogs = !poku_js_1.GLOBAL.configs.quiet; | ||
const cb = configs[type]; | ||
const showLogs = !configs.quiet; | ||
const cbName = cb.name !== type ? cb.name : 'anonymous function'; | ||
@@ -14,0 +15,0 @@ showLogs && |
@@ -22,3 +22,3 @@ export declare const backgroundColor: { | ||
constructor(text: string); | ||
private code; | ||
code(code: string): this; | ||
static create(text: string): Formatter; | ||
@@ -40,2 +40,1 @@ counter(current: number, total: number, pad?: string): this; | ||
export declare const getLargestStringLength: (arr: string[]) => number; | ||
export declare const showTestResults: () => void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.showTestResults = exports.getLargestStringLength = exports.format = exports.Formatter = exports.backgroundColor = void 0; | ||
const files_js_1 = require("../configs/files.js"); | ||
const indentation_js_1 = require("../configs/indentation.js"); | ||
const write_js_1 = require("../services/write.js"); | ||
exports.getLargestStringLength = exports.format = exports.Formatter = exports.backgroundColor = void 0; | ||
exports.backgroundColor = { | ||
@@ -81,16 +78,1 @@ white: 7, | ||
exports.getLargestStringLength = getLargestStringLength; | ||
const showTestResults = () => { | ||
(0, write_js_1.hr)(); | ||
if (files_js_1.fileResults.success.size > 0 && files_js_1.fileResults.fail.size === 0) { | ||
(0, write_js_1.log)(Array.from(files_js_1.fileResults.success) | ||
.map(([file, time]) => `${indentation_js_1.indentation.test}${(0, exports.format)('β').success()} ${(0, exports.format)(`${file} ${(0, exports.format)(`βΊ ${time}ms`).success()}`).dim()}`) | ||
.join('\n')); | ||
return; | ||
} | ||
if (files_js_1.fileResults.fail.size > 0) { | ||
(0, write_js_1.log)(Array.from(files_js_1.fileResults.fail) | ||
.map(([file, time]) => `${indentation_js_1.indentation.test}${(0, exports.format)('β').fail()} ${(0, exports.format)(`${file} ${(0, exports.format)(`βΊ ${time}ms`).fail()}`).dim()}`) | ||
.join('\n')); | ||
} | ||
}; | ||
exports.showTestResults = showTestResults; |
@@ -1,1 +0,1 @@ | ||
export declare const runTestFile: (filePath: string) => Promise<boolean>; | ||
export declare const runTestFile: (path: string) => Promise<boolean>; |
@@ -7,11 +7,10 @@ "use strict"; | ||
const node_child_process_1 = require("child_process"); | ||
const files_js_1 = require("../configs/files.js"); | ||
const get_runner_js_1 = require("../parsers/get-runner.js"); | ||
const output_js_1 = require("../parsers/output.js"); | ||
const each_js_1 = require("./each.js"); | ||
const write_js_1 = require("./write.js"); | ||
const poku_js_1 = require("../configs/poku.js"); | ||
const { cwd } = poku_js_1.GLOBAL; | ||
const runTestFile = async (filePath) => { | ||
const runtimeOptions = (0, get_runner_js_1.runner)(filePath); | ||
const os_js_1 = require("../parsers/os.js"); | ||
const runTestFile = async (path) => { | ||
const { cwd, configs, reporter } = poku_js_1.GLOBAL; | ||
const runtimeOptions = (0, get_runner_js_1.runner)(path); | ||
const runtime = runtimeOptions.shift(); | ||
@@ -21,10 +20,10 @@ const runtimeArguments = [ | ||
poku_js_1.GLOBAL.configs.deno?.cjs === true || | ||
(Array.isArray(poku_js_1.GLOBAL.configs.deno?.cjs) && | ||
poku_js_1.GLOBAL.configs.deno.cjs.some((ext) => filePath.includes(ext))) | ||
configs.deno?.cjs === true || | ||
(Array.isArray(configs.deno?.cjs) && | ||
configs.deno.cjs.some((ext) => path.includes(ext))) | ||
? `https://cdn.jsdelivr.net/npm/poku${poku_js_1.VERSION ? `@${poku_js_1.VERSION}` : ''}/lib/polyfills/deno.mjs` | ||
: filePath, | ||
: path, | ||
]; | ||
const fileRelative = (0, node_path_1.relative)(cwd, filePath); | ||
const showLogs = !poku_js_1.GLOBAL.configs.quiet; | ||
const file = (0, node_path_1.relative)(cwd, path); | ||
const showLogs = !configs.quiet; | ||
let output = ''; | ||
@@ -36,12 +35,19 @@ const stdOut = (data) => { | ||
let end; | ||
if (!(await (0, each_js_1.beforeEach)(fileRelative))) | ||
if (!(await (0, each_js_1.beforeEach)(file))) | ||
return false; | ||
reporter.onFileStart({ | ||
path: { | ||
relative: file, | ||
absolute: path, | ||
}, | ||
}); | ||
return new Promise((resolve) => { | ||
const child = (0, node_child_process_1.spawn)(runtime, [...runtimeArguments, ...poku_js_1.deepOptions], { | ||
stdio: ['inherit', 'pipe', 'pipe'], | ||
shell: get_runner_js_1.isWindows, | ||
shell: os_js_1.isWindows, | ||
env: { | ||
...node_process_1.env, | ||
POKU_FILE: fileRelative, | ||
POKU_FILE: file, | ||
POKU_RUNTIME: node_process_1.env.POKU_RUNTIME, | ||
POKU_REPORTER: configs.reporter, | ||
}, | ||
@@ -57,17 +63,21 @@ }); | ||
if (showLogs) { | ||
const mappedOutputs = (0, output_js_1.parserOutput)({ | ||
const parsedOutputs = (0, output_js_1.parserOutput)({ | ||
output, | ||
result, | ||
})?.join('\n'); | ||
const total = end[0] * 1e3 + end[1] / 1e6; | ||
reporter.onFileResult({ | ||
status: result, | ||
path: { | ||
relative: file, | ||
absolute: path, | ||
}, | ||
duration: total, | ||
output: parsedOutputs, | ||
}); | ||
mappedOutputs && (0, write_js_1.log)(mappedOutputs.join('\n')); | ||
} | ||
if (!(await (0, each_js_1.afterEach)(fileRelative))) { | ||
if (!(await (0, each_js_1.afterEach)(file))) { | ||
resolve(false); | ||
return; | ||
} | ||
const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6); | ||
if (result) | ||
files_js_1.fileResults.success.set(fileRelative, total); | ||
else | ||
files_js_1.fileResults.fail.set(fileRelative, total); | ||
resolve(result); | ||
@@ -78,9 +88,18 @@ }); | ||
end = (0, node_process_1.hrtime)(start); | ||
const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6); | ||
console.error(`Failed to start test: ${filePath}`, err); | ||
files_js_1.fileResults.fail.set(fileRelative, total); | ||
const total = end[0] * 1e3 + end[1] / 1e6; | ||
if (showLogs) | ||
console.error(`Failed to start test: ${path}`, err); | ||
reporter.onFileResult({ | ||
status: false, | ||
path: { | ||
relative: file, | ||
absolute: path, | ||
}, | ||
duration: total, | ||
}); | ||
resolve(false); | ||
}); | ||
}); | ||
}; | ||
exports.runTestFile = runTestFile; |
@@ -17,3 +17,2 @@ "use strict"; | ||
const { cwd } = poku_js_1.GLOBAL; | ||
const failFastError = ` ${(0, format_js_1.format)('βΉ').fail()} ${(0, format_js_1.format)('failFast').bold()} is enabled`; | ||
if (get_arg_js_1.hasOnly) | ||
@@ -26,9 +25,11 @@ poku_js_1.deepOptions.push('--only'); | ||
let rejectDone; | ||
const { configs } = poku_js_1.GLOBAL; | ||
const testDir = (0, node_path_1.join)(cwd, dir); | ||
const files = await (0, list_files_js_1.listFiles)(testDir, poku_js_1.GLOBAL.configs); | ||
const showLogs = !poku_js_1.GLOBAL.configs.quiet; | ||
const files = await (0, list_files_js_1.listFiles)(testDir, configs); | ||
const showLogs = !configs.quiet; | ||
const failFastError = ` ${(0, format_js_1.format)('βΉ').fail()} ${(0, format_js_1.format)('failFast').bold()} is enabled`; | ||
const concurrency = (() => { | ||
if (poku_js_1.GLOBAL.configs.sequential) | ||
if (configs.sequential) | ||
return 1; | ||
const limit = poku_js_1.GLOBAL.configs.concurrency ?? Math.max((0, os_js_1.availableParallelism)() - 1, 1); | ||
const limit = configs.concurrency ?? Math.max((0, os_js_1.availableParallelism)() - 1, 1); | ||
return limit <= 0 ? files.length || 1 : limit; | ||
@@ -52,7 +53,7 @@ })(); | ||
if (testPassed) | ||
++poku_js_1.results.success; | ||
++poku_js_1.results.passed; | ||
else { | ||
++poku_js_1.results.fail; | ||
++poku_js_1.results.failed; | ||
allPassed = false; | ||
if (poku_js_1.GLOBAL.configs.failFast) { | ||
if (configs.failFast) { | ||
if (showLogs) { | ||
@@ -59,0 +60,0 @@ (0, write_js_1.hr)(); |
{ | ||
"name": "poku", | ||
"version": "3.0.0-rc.1", | ||
"version": "3.0.0", | ||
"description": "π· Poku makes testing easy for Node.js, Bun, Deno, and you at the same time.", | ||
"main": "./lib/modules/index.js", | ||
"license": "MIT", | ||
"type": "commonjs", | ||
"bin": { | ||
@@ -55,10 +54,10 @@ "poku": "./lib/bin/index.js" | ||
"@biomejs/biome": "1.9.4", | ||
"@types/node": "^22.10.2", | ||
"@types/node": "^22.10.10", | ||
"c8": "^10.1.3", | ||
"jsonc.min": "^1.1.0", | ||
"monocart-coverage-reports": "^2.11.5", | ||
"monocart-coverage-reports": "^2.12.0", | ||
"packages-update": "^2.0.0", | ||
"prettier": "^3.4.2", | ||
"tsx": "4.19.2", | ||
"typescript": "^5.7.2" | ||
"typescript": "^5.7.3" | ||
}, | ||
@@ -65,0 +64,0 @@ "keywords": [ |
@@ -8,4 +8,4 @@ <div align="center"> | ||
[![NPM Version](https://img.shields.io/npm/v/poku/rc.svg?label=&color=70a1ff&logo=npm&logoColor=white)](https://www.npmjs.com/package/poku/v/3.0.0-rc.0) | ||
[![NPM Downloads](https://img.shields.io/npm/dm/poku.svg?label=&logo=npm&logoColor=white&color=45aaf2)](https://www.npmjs.com/package/poku/v/3.0.0-rc.0) | ||
[![NPM Version](https://img.shields.io/npm/v/poku.svg?label=&color=70a1ff&logo=npm&logoColor=white)](https://www.npmjs.com/package/poku) | ||
[![NPM Downloads](https://img.shields.io/npm/dm/poku.svg?label=&logo=npm&logoColor=white&color=45aaf2)](https://www.npmjs.com/package/poku) | ||
[![Coverage](https://img.shields.io/codecov/c/github/wellwelwel/poku?label=&logo=codecov&logoColor=white&color=98cc00)](https://github.com/wellwelwel/poku/tree/main/.nycrc)<br /> | ||
@@ -24,6 +24,6 @@ [![GitHub Workflow Status (Linux)](https://img.shields.io/github/actions/workflow/status/wellwelwel/poku/ci_coverage-linux.yml?event=push&label=&branch=main&logo=ubuntu&logoColor=8897a9&color=dfe4ea)](https://github.com/wellwelwel/poku/actions/workflows/ci_coverage-linux.yml?query=branch%3Amain) | ||
> | ||
> **Poku** is growing and <strong>version 3</strong> is on its way! You can already try it by installing the Release Candidate with `poku@rc`. | ||
> **Poku `v3`** is here! π | ||
> | ||
> - To check out what's coming, follow the [**Issue #801**](https://github.com/wellwelwel/poku/issues/801). | ||
> - For `v2` documentation, see the [**legacy version documentation**](https://poku.io/docs/2.x.x) and [**README**](https://github.com/wellwelwel/poku/tree/2.x.x?tab=readme-ov-file#readme).<br /> | ||
> - To check out what's changed, follow the [**Issue #801**](https://github.com/wellwelwel/poku/issues/801). | ||
> - For `v2` documentation, see the [**previous version's documentation**](https://poku.io/docs/2.x.x) and [**README**](https://github.com/wellwelwel/poku/tree/2.x.x?tab=readme-ov-file#readme).<br /> | ||
@@ -54,3 +54,3 @@ --- | ||
# Node.js | ||
npm i -D poku@rc | ||
npm i -D poku | ||
``` | ||
@@ -63,3 +63,3 @@ | ||
# TypeScript (Node.js) | ||
npm i -D poku@rc tsx | ||
npm i -D poku tsx | ||
``` | ||
@@ -72,3 +72,3 @@ | ||
# Bun | ||
bun add -d poku@rc | ||
bun add -d poku | ||
``` | ||
@@ -81,3 +81,3 @@ | ||
# Deno (optional) | ||
deno add npm:poku@rc | ||
deno add npm:poku | ||
``` | ||
@@ -140,3 +140,3 @@ | ||
```bash | ||
deno run npm:poku@rc | ||
deno run npm:poku | ||
``` | ||
@@ -143,0 +143,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
174211
131
3936
0