Skip to content

Commit

Permalink
fix(ses-ava): wrap test deeply (#2589)
Browse files Browse the repository at this point in the history
Refs: Agoric/agoric-sdk#10208

## Description

the `ava` test functions can be nested more than one level deep. This
change recurses test functions with known names until none is found.

### Security Considerations

None

### Scaling Considerations

None

### Documentation Considerations

Relaxes the type of acceptable test functions as it only really cares
about it being a test function, regardless of whatever chain expandos it
may have.

### Testing Considerations

Manually verified that a `test.serial.only` does show errors details as
expected. Not sure if we have any automated coverage for this.

### Compatibility Considerations

None

### Upgrade Considerations

This is used by tests only, and can be consumed as a non breaking change
simply by using the new NPM package including this fix.
  • Loading branch information
mhofman authored Oct 17, 2024
1 parent 271aa92 commit 7a991aa
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/ses-ava/src/ses-ava-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const {
freeze,
getPrototypeOf,
getOwnPropertyDescriptors,
hasOwn,
entries,
} = Object;
const { apply } = Reflect;
Expand Down Expand Up @@ -176,7 +177,7 @@ const makeVirtualExecutionContext = originalT => {
};

/**
* @template {import('ava').TestFn} [T=import('ava').TestFn]
* @template {import('ava').OnlyFn} [T=import('ava').TestFn]
* @param {T} testerFunc
* @returns {T} Not yet frozen!
*/
Expand Down Expand Up @@ -248,7 +249,7 @@ const augmentLogging = testerFunc => {
// https://github.com/endojs/endo/issues/647#issuecomment-809010961
Object.assign(augmented, testerFunc);
// @ts-expect-error cast
return /** @type {import('ava').TestFn} */ augmented;
return /** @type {import('ava').OnlyFn} */ augmented;
};

/**
Expand Down Expand Up @@ -278,19 +279,21 @@ const augmentLogging = testerFunc => {
* (which defaults to using the SES-aware `console.error`)
* before propagating into `rawTest`.
*
* @template {import('ava').TestFn} [T=import('ava').TestFn] ava `test`
* @template {import('ava').OnlyFn} [T=import('ava').TestFn] ava `test`
* @param {T} avaTest
* @returns {T}
*/
const wrapTest = avaTest => {
const sesAvaTest = augmentLogging(avaTest);
for (const methodName of overrideList) {
defineProperty(sesAvaTest, methodName, {
value: augmentLogging(avaTest[methodName]),
writable: true,
enumerable: true,
configurable: true,
});
if (hasOwn(avaTest, methodName)) {
defineProperty(sesAvaTest, methodName, {
value: wrapTest(avaTest[methodName]),
writable: true,
enumerable: true,
configurable: true,
});
}
}
harden(sesAvaTest);
return sesAvaTest;
Expand Down

0 comments on commit 7a991aa

Please sign in to comment.