From 7beca6658e07bfab8155152f092c9984cdb126a3 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Thu, 8 Aug 2024 16:11:08 -0700 Subject: [PATCH] feat(exo): defineExoClassKitFromJSClassKit --- packages/exo/test/exo-wobbly-point.test.js | 13 ++++- packages/ses/test/error/assert-log.test.js | 50 ++++++++----------- .../ses/test/error/filtering-console.test.js | 36 ++++++------- 3 files changed, 48 insertions(+), 51 deletions(-) diff --git a/packages/exo/test/exo-wobbly-point.test.js b/packages/exo/test/exo-wobbly-point.test.js index 1553ded80a..95db531846 100644 --- a/packages/exo/test/exo-wobbly-point.test.js +++ b/packages/exo/test/exo-wobbly-point.test.js @@ -9,13 +9,14 @@ /* eslint-disable max-classes-per-file */ import test from '@endo/ses-ava/prepare-endo.js'; +import { Fail, q } from '@endo/errors'; +import { objectMap } from '@endo/common/object-map.js'; import { getMethodNames } from '@endo/eventual-send/utils.js'; import { passStyleOf, Far, GET_METHOD_NAMES } from '@endo/pass-style'; import { M } from '@endo/patterns'; -import { Fail, q } from '@endo/errors'; import { GET_INTERFACE_GUARD } from '../src/get-interface.js'; -import { defineExoClass } from '../src/exo-makers.js'; +import { defineExoClass, defineExoClassKit } from '../src/exo-makers.js'; const { apply } = Reflect; @@ -40,6 +41,14 @@ const defineExoClassFromJSClass = klass => defineExoClass(klass.name, klass.implements, klass.init, klass.prototype); harden(defineExoClassFromJSClass); +const defineExoClassKitFromJSClassKit = (name, init, klassKit) => + defineExoClassKit( + name, + objectMap(klassKit, klass => klass.implements), + init, + objectMap(klassKit, klass => klass.prototype), + ); + const ExoPointI = M.interface('ExoPoint', { toString: M.call().returns(M.string()), getX: M.call().returns(M.gte(0)), diff --git a/packages/ses/test/error/assert-log.test.js b/packages/ses/test/error/assert-log.test.js index 76b82d9948..c8eaf412a2 100644 --- a/packages/ses/test/error/assert-log.test.js +++ b/packages/ses/test/error/assert-log.test.js @@ -126,17 +126,13 @@ test('causal tree', t => { }); test('a causal tree falls silently', t => { - assertLogs( - t, - () => { - try { - assert(false); - } catch (err) { - t.assert(err instanceof Error); - } - }, - [], - ); + assertLogs(t, () => { + try { + assert(false); + } catch (err) { + t.assert(err instanceof Error); + } + }, []); assertLogs( t, () => { @@ -149,24 +145,20 @@ test('a causal tree falls silently', t => { [], { wrapWithCausal: true }, ); - assertLogs( - t, - () => { - const fooErr = SyntaxError('foo'); - let err1; - try { - assert.fail(X`synful ${fooErr}`); - } catch (e1) { - err1 = e1; - } - try { - assert.fail(X`because ${err1}`); - } catch (e2) { - t.assert(e2 instanceof Error); - } - }, - [], - ); + assertLogs(t, () => { + const fooErr = SyntaxError('foo'); + let err1; + try { + assert.fail(X`synful ${fooErr}`); + } catch (e1) { + err1 = e1; + } + try { + assert.fail(X`because ${err1}`); + } catch (e2) { + t.assert(e2 instanceof Error); + } + }, []); assertLogs( t, () => { diff --git a/packages/ses/test/error/filtering-console.test.js b/packages/ses/test/error/filtering-console.test.js index 745548b1a1..72ae662e82 100644 --- a/packages/ses/test/error/filtering-console.test.js +++ b/packages/ses/test/error/filtering-console.test.js @@ -6,24 +6,20 @@ import { assertLogs } from './throws-and-logs.js'; lockdown(); test('filtering console', t => { - assertLogs( - t, - () => { - // sampled inside the thunk, in the environment set up by - // assertLogs - const testingConsole = console; - let filterFlag = true; - const filter = { canLog: _severity => filterFlag }; - const filteringConsole = filterConsole(testingConsole, filter); - filteringConsole.log('foo'); - filterFlag = false; - filteringConsole.log('bar'); - filterFlag = true; - filteringConsole.log('baz'); - }, - [ - ['log', 'foo'], - ['log', 'baz'], - ], - ); + assertLogs(t, () => { + // sampled inside the thunk, in the environment set up by + // assertLogs + const testingConsole = console; + let filterFlag = true; + const filter = { canLog: _severity => filterFlag }; + const filteringConsole = filterConsole(testingConsole, filter); + filteringConsole.log('foo'); + filterFlag = false; + filteringConsole.log('bar'); + filterFlag = true; + filteringConsole.log('baz'); + }, [ + ['log', 'foo'], + ['log', 'baz'], + ]); });