Skip to content

Commit

Permalink
fix: support Ava "macros" in ses-ava (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
FUDCo authored Mar 26, 2021
1 parent 51adac6 commit 01fabaf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 8 additions & 5 deletions packages/ses-ava/src/ses-ava-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ const testerMethodsWhitelist = [
*/
const wrapTester = (testerFunc, logger = defaultLogger) => {
/** @type {TesterFunc} */
const testerWrapper = (title, implFunc) => {
const testerWrapper = (title, implFunc, ...otherArgs) => {
/** @type {ImplFunc} */
const testFuncWrapper = t => {
harden(t);
return logErrorFirst(implFunc, [t], 'ava test', logger);
return logErrorFirst(implFunc, [t, ...otherArgs], 'ava test', logger);
};
return testerFunc(title, testFuncWrapper);
if (implFunc && implFunc.title) {
testFuncWrapper.title = implFunc.title;
}
return testerFunc(title, testFuncWrapper, ...otherArgs);
};
return testerWrapper;
};
Expand Down Expand Up @@ -112,8 +115,8 @@ const wrapTest = (avaTest, logger = defaultLogger) => {
for (const methodName of testerMethodsWhitelist) {
if (methodName in avaTest) {
/** @type {TesterFunc} */
const testerMethod = (title, implFunc) =>
avaTest[methodName](title, implFunc);
const testerMethod = (title, implFunc, ...otherArgs) =>
avaTest[methodName](title, implFunc, ...otherArgs);
testerWrapper[methodName] = wrapTester(testerMethod);
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/ses-ava/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@
*/

/**
* @callback ImplFunc
* @callback BaseImplFunc
* This is the function that invariably starts `t => {`.
* Ava's types call this `Implementation`, but that's just too confusing.
*
* @param {Assertions} t
* @returns {unknown}
*
* @typedef {BaseImplFunc | Object} ImplFunc
* @property {(...unknown) => string} [title]
*
* @callback TesterFunc
* @param {string} title
* @param {ImplFunc} implFunc
Expand Down

0 comments on commit 01fabaf

Please sign in to comment.