Skip to content

Commit

Permalink
Modernize a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Jun 23, 2019
1 parent f083a24 commit baf34a6
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions lib/uninspected.js
@@ -1,12 +1,10 @@
const unexpected = require('unexpected').clone();

const unexpected = require('unexpected')
.clone()
.use(require('magicpen-prism'));
const originalConsole = console; // Take a copy so we don't loop infinitely when someone goes: console=uninspected;console.log('foo');

unexpected.installPlugin(require('magicpen-prism'));

function uninspected() {
// ...
return uninspected.log.apply(uninspected, arguments);
function uninspected(...args) {
return uninspected.log.apply(uninspected, args);
}

uninspected.inspect = (obj, options) => {
Expand Down Expand Up @@ -46,11 +44,10 @@ function createOutput() {
);
}

['log', 'info', 'warn', 'error'].forEach(methodName => {
uninspected[methodName] = function() {
// ...
for (const methodName of ['log', 'info', 'warn', 'error']) {
uninspected[methodName] = function(...args) {
const output = createOutput();
Array.prototype.forEach.call(arguments, (obj, i) => {
for (const [i, obj] of args.entries()) {
if (i > 0) {
output.sp();
}
Expand All @@ -61,14 +58,14 @@ function createOutput() {
} else {
output.appendInspected(obj, uninspected.defaultDepth);
}
});
}
if (isChrome) {
originalConsole[methodName].apply(originalConsole, output.toString());
} else {
originalConsole[methodName](output.toString());
}
};
});
}

uninspected.dir = originalConsole.dir.bind(originalConsole);

Expand Down Expand Up @@ -96,28 +93,24 @@ uninspected.diff = (a, b) => {
};

// Support trace, time, timeEnd etc.
Object.keys(originalConsole).forEach(key => {
for (const key of Object.keys(originalConsole)) {
if (typeof originalConsole[key] === 'function' && !uninspected[key]) {
uninspected[key] = function() {
// ...
return originalConsole[key].apply(originalConsole, arguments);
uninspected[key] = function(...args) {
return originalConsole[key].apply(originalConsole, args);
};
}
});
}

uninspected.addType = function() {
// ...
return unexpected.addType.apply(unexpected, arguments);
uninspected.addType = function(...args) {
return unexpected.addType.apply(unexpected, args);
};

uninspected.addStyle = function() {
// ...
return unexpected.output.addStyle.apply(unexpected.output, arguments);
uninspected.addStyle = function(...args) {
return unexpected.output.addStyle.apply(unexpected.output, args);
};

uninspected.use = function() {
// ...
return unexpected.use.apply(unexpected, arguments);
uninspected.use = function(...args) {
return unexpected.use.apply(unexpected, args);
};

module.exports = uninspected;

0 comments on commit baf34a6

Please sign in to comment.