ava/lib/parse-test-args.js
Sindre Sorhus cf0fa4ce5a
Update dependencies, rely on Node.js 18, other small changes
* Update dependencies
* Rely on Node.js 18 language features
* Other small changes
* Upgrade to tap@18
* Develop and test with typescript@5.2
* Rebuild lockfile

---------

Co-authored-by: Mark Wubben <mark@novemberborn.net>
2023-11-06 21:46:04 +01:00

26 lines
629 B
JavaScript

const buildTitle = (raw, implementation, args) => {
let value = implementation?.title?.(raw, ...args) ?? raw;
const isValid = typeof value === 'string';
if (isValid) {
value = value.trim().replaceAll(/\s+/g, ' ');
}
return {
raw,
value,
isSet: value !== undefined,
isValid,
isEmpty: !isValid || value === '',
};
};
export default function parseTestArgs(args) {
const rawTitle = typeof args[0] === 'string' ? args.shift() : undefined;
const implementation = args.shift();
return {
args,
implementation: implementation?.exec ?? implementation,
title: buildTitle(rawTitle, implementation, args),
};
}