diff --git a/packages/ses/test/error/test-permit-removal-warnings.js b/packages/ses/test/error/test-permit-removal-warnings.js index 2f4da38712..ab83b430f9 100644 --- a/packages/ses/test/error/test-permit-removal-warnings.js +++ b/packages/ses/test/error/test-permit-removal-warnings.js @@ -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; @@ -18,10 +17,60 @@ defineProperties(Array, { return apply(originalIsArray, this, args); }, }, + // To ensure that the test below remains tolerant of future engines + // adding unexpected properties, causing extra warnings on removal. + // 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]); + +/** + * Test that log includes goldenLog in order + * that is: test that they match but for possible extra warning lines in log. + * Specialized for the test below. + * See https://github.com/endojs/endo/issues/1973 + * + * @param {Implementation} t + * @param {any[][]} log + * @param {any[][]} goldenLog + */ +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(), @@ -35,6 +84,6 @@ test.skip('permit removal warnings', t => { ['warn', 'Removing intrinsics.Array.extraRemovableDataProperty'], ['groupEnd'], ], - {}, + { compareLogs }, ); }); diff --git a/packages/ses/test/error/throws-and-logs.js b/packages/ses/test/error/throws-and-logs.js index f6ebd6d791..c07e366572 100644 --- a/packages/ses/test/error/throws-and-logs.js +++ b/packages/ses/test/error/throws-and-logs.js @@ -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); @@ -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 },