Skip to content

Commit

Permalink
feat(exo): defineExoClassKitFromJSClassKit
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Aug 14, 2024
1 parent bec206b commit 7beca66
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 51 deletions.
13 changes: 11 additions & 2 deletions packages/exo/test/exo-wobbly-point.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)),
Expand Down
50 changes: 21 additions & 29 deletions packages/ses/test/error/assert-log.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
() => {
Expand All @@ -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,
() => {
Expand Down
36 changes: 16 additions & 20 deletions packages/ses/test/error/filtering-console.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
]);
});

0 comments on commit 7beca66

Please sign in to comment.