Skip to content

Commit

Permalink
feat(ses): expose console tools support
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Feb 28, 2024
1 parent 18fb659 commit 87982e5
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 11 deletions.
8 changes: 8 additions & 0 deletions packages/ses/console-tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export { loggedErrorHandler } from './src/error/assert.js';
export {
makeCausalConsole,
consoleWhitelist,
makeLoggingConsoleKit,
filterConsole,
} from './src/error/console.js';
export { assertLogs, throwsAndLogs } from './src/error/throws-and-logs.js';
1 change: 1 addition & 0 deletions packages/ses/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"require": "./dist/ses.cjs"
},
"./tools.js": "./tools.js",
"./console-tools.js": "./console-tools.js",
"./assert-shim.js": "./assert-shim.js",
"./lockdown-shim.js": "./lockdown-shim.js",
"./compartment-shim.js": "./compartment-shim.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// This module supports testing/debugging, and should be exported from the
// 'ses' package only by console-tools.js
/* eslint-disable no-restricted-globals */
/* eslint-disable @endo/no-polymorphic-call */
/* global globalThis */

import { freeze, getPrototypeOf } from '../../src/commons.js';
import { loggedErrorHandler } from '../../src/error/assert.js';
import {
makeLoggingConsoleKit,
makeCausalConsole,
} from '../../src/error/console.js';
import { freeze, getPrototypeOf } from '../commons.js';
import { loggedErrorHandler } from './assert.js';
import { makeLoggingConsoleKit, makeCausalConsole } from './console.js';

// For our internal debugging purposes
// const internalDebugConsole = console;
Expand Down Expand Up @@ -80,20 +81,27 @@ export const assertLogs = freeze((t, thunk, goldenLog, options = {}) => {
loggedErrorHandler,
{ shouldResetForDebugging: true },
);
/** @type {VirtualConsole} */
let useConsole = console;
if (checkLogs) {
useConsole = loggingConsole;
if (wrapWithCausal) {
// @ts-ignore Console vs VirtualConsole vs undefined.
// Not interesting for the testing/debugging nature of this module
useConsole = makeCausalConsole(useConsole, {
...loggedErrorHandler,
getStackString: getBogusStackString,
});
}
} else if (wrapWithCausal) {
// @ts-ignore Console vs VirtualConsole vs undefined.
// Not interesting for the testing/debugging nature of this module
useConsole = nonLoggingConsole;
}

const priorConsole = console;
// @ts-ignore Console vs VirtualConsole vs undefined.
// Not interesting for the testing/debugging nature of this module
globalThis.console = useConsole;
try {
// If thunk() throws, we restore the console and the logging array.
Expand Down
2 changes: 1 addition & 1 deletion packages/ses/test/error/test-aggregate-error-console.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava';
import '../../index.js';
import { throwsAndLogs } from './throws-and-logs.js';
import { throwsAndLogs } from '../../src/error/throws-and-logs.js';

lockdown();

Expand Down
2 changes: 1 addition & 1 deletion packages/ses/test/error/test-assert-log.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import { assertLogs, throwsAndLogs } from './throws-and-logs.js';
import { assertLogs, throwsAndLogs } from '../../src/error/throws-and-logs.js';
import { assert } from '../../src/error/assert.js';

const { details: d, quote: q, bare: b } = assert;
Expand Down
2 changes: 1 addition & 1 deletion packages/ses/test/error/test-error-cause-console.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava';
import '../../index.js';
import { throwsAndLogs } from './throws-and-logs.js';
import { throwsAndLogs } from '../../src/error/throws-and-logs.js';

lockdown();

Expand Down
2 changes: 1 addition & 1 deletion packages/ses/test/error/test-filtering-console.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'ava';
import '../../index.js';
import { filterConsole } from '../../src/error/console.js';
import { assertLogs } from './throws-and-logs.js';
import { assertLogs } from '../../src/error/throws-and-logs.js';

lockdown();

Expand Down
2 changes: 1 addition & 1 deletion packages/ses/test/error/test-permit-removal-warnings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava';
import '../../index.js';
import { assertLogs } from './throws-and-logs.js';
import { assertLogs } from '../../src/error/throws-and-logs.js';

const { defineProperties } = Object;
const { apply } = Reflect;
Expand Down

0 comments on commit 87982e5

Please sign in to comment.