Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(ses): fix 1973, unskip log test #2049

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
// 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]);

// Specialized for the test below.
// See https://github.com/endojs/endo/issues/1973
const compareLogs = (t, log, goldenLog) => {
erights marked this conversation as resolved.
Show resolved Hide resolved
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,
},
erights marked this conversation as resolved.
Show resolved Hide resolved
);
});
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
Loading