Skip to content

Commit

Permalink
test(ses): fix 1973, unskip log test
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Feb 10, 2024
1 parent b463c57 commit 71da02a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
51 changes: 47 additions & 4 deletions packages/ses/test/error/test-permit-removal-warnings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import test from 'ava';
import '../../index.js';
import { assertLogs } from './throws-and-logs.js';
// import { whitelistIntrinsics } from '../../src/permits-intrinsics.js';

const { defineProperties } = Object;
const { apply } = Reflect;
Expand All @@ -18,10 +17,52 @@ defineProperties(Array, {
return apply(originalIsArray, this, args);
},
},
// To ensure that the test below remains tolerant of future engines
// removing unexpected properties.
// See https://github.com/endojs/endo/issues/1973
anotherOne: {
value: `another removable property`,
configurable: true,
},
});

// TODO unskip once https://github.com/endojs/endo/issues/1973 is fixed.
test.skip('permit removal warnings', t => {
const logRecordMatches = (logRecord, goldenRecord) =>
Array.isArray(logRecord) &&
Array.isArray(goldenRecord) &&
logRecord.length === goldenRecord.length &&
logRecord.every((logEntry, i) => logEntry === goldenRecord[i]);

// Specialized for the test below.
// See https://github.com/endojs/endo/issues/1973
const compareLogs = (t, log, goldenLog) => {
t.deepEqual(log[0], goldenLog[0]);
const logLast = log.length - 1;
const goldenLast = goldenLog.length - 1;
t.deepEqual(log[logLast], goldenLog[goldenLast]);
t.assert(logLast >= goldenLast);

let g = 1;
let skip = 0;
for (; g < goldenLast; g += 1) {
const logRecord = log[g + skip];
const goldenRecord = goldenLog[g];
if (logRecordMatches(logRecord, goldenRecord)) {
// eslint-disable-next-line no-continue
continue;
}
if (g + skip >= logLast) {
// no more slack left
t.deepEqual(logRecord, goldenRecord, 'log record mismatch');
t.fail('log record mismatch');
}
if (logRecord[0] !== 'warn') {
t.fail('can only skip warnings');
}
skip += 1;
}
};

test('permit removal warnings', t => {
assertLogs(
t,
() => lockdown(),
Expand All @@ -35,6 +76,8 @@ test.skip('permit removal warnings', t => {
['warn', 'Removing intrinsics.Array.extraRemovableDataProperty'],
['groupEnd'],
],
{},
{
compareLogs,
},
);
});
8 changes: 6 additions & 2 deletions packages/ses/test/error/throws-and-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
// For our internal debugging purposes
// const internalDebugConsole = console;

const compareLogs = freeze((t, log, goldenLog) => {
const defaultCompareLogs = freeze((t, log, goldenLog) => {
// For our internal debugging purposes
// internalDebugConsole.log('LOG', log);

Expand Down Expand Up @@ -71,7 +71,11 @@ const getBogusStackString = error => {
// [['error', 'what ', err]]);
// ```
export const assertLogs = freeze((t, thunk, goldenLog, options = {}) => {
const { checkLogs = true, wrapWithCausal = false } = options;
const {
checkLogs = true,
wrapWithCausal = false,
compareLogs = defaultCompareLogs,
} = options;
const { loggingConsole, takeLog } = makeLoggingConsoleKit(
loggedErrorHandler,
{ shouldResetForDebugging: true },
Expand Down

0 comments on commit 71da02a

Please sign in to comment.