Console.error tantrums
MODIFY
package.json
package.json
"rollup": "^0.62.0",
"rollup-plugin-babel-minify": "^5.0.0",
"rollup-watch": "^4.3.1",
+ "sinon": "^6.1.3",
"tap-nyc": "^1.0.3",
"tape": "^4.9.1"
}

MODIFY
shim/src/utilities.js
shim/src/utilities.js
export function throwTantrum(s, err = undefined) {
const msg = `please report internal shim error: ${s}`;
+
// note: we really do want to log these 'should never happen' things. there
// might be a better way to convince the linter, though.
// eslint-disable-next-line no-console
- console.log(msg);
+ console.error(msg);
if (err) {
// eslint-disable-next-line no-console
- console.log(`${err}`);
+ console.error(`${err}`);
// eslint-disable-next-line no-console
- console.log(`${err.stack}`);
+ console.error(`${err.stack}`);
}
+
// eslint-disable-next-line no-debugger
debugger;
throw msg;

MODIFY
shim/test/realm/utilities.js
shim/test/realm/utilities.js
import test from 'tape';
+import sinon from 'sinon';
import { throwTantrum, assert } from '../../src/utilities';
+/* eslint-disable no-console */
+
test('throwTantrum', t => {
- t.plan(1);
+ t.plan(3);
+
+ sinon.stub(console, 'error').callsFake();
t.throws(() => throwTantrum('foo'), /^please report internal shim error: foo$/);
+
+ t.equals(console.error.callCount, 1);
+ t.equals(console.error.getCall(0).args[0], 'please report internal shim error: foo');
+
+ console.error.restore();
+});
+
+test('throwTantrum', t => {
+ t.plan(5);
+
+ sinon.stub(console, 'error');
+
+ t.throws(() => throwTantrum('foo', new Error('bar')), /^please report internal shim error: foo$/);
+
+ t.equals(console.error.callCount, 3);
+ t.equals(console.error.getCall(0).args[0], 'please report internal shim error: foo');
+ t.equals(console.error.getCall(1).args[0], 'Error: bar');
+ t.ok(console.error.getCall(2).args[0].includes('at t.throws'));
+
+ console.error.restore();
});
test('assert', t => {
- t.plan(2);
+ t.plan(4);
+
+ sinon.stub(console, 'error').callsFake();
t.doesNotThrow(() => assert(true, 'foo'));
t.throws(() => assert(false, 'foo'), /^please report internal shim error: failed to: foo$/);
+
+ t.equals(console.error.callCount, 1);
+ t.equals(console.error.getCall(0).args[0], 'please report internal shim error: failed to: foo');
+
+ console.error.restore();
});

Console.error tantrums