Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
evanplaice committed Jun 22, 2020
1 parent c725589 commit fd8194a
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 92 deletions.
2 changes: 1 addition & 1 deletion index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MockConsole {
this.errors = [];
proto.instance = this;
}
return proto.instance;
return proto.instance
}

/**
Expand Down
44 changes: 22 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,54 @@
*/
export class MockConsole {
constructor () {
const proto = Object.getPrototypeOf(this);
const proto = Object.getPrototypeOf(this)
if (!proto.instance) {
this.log = console.log;
this.info = console.info;
this.error = console.error;
this.logs = [];
this.infos = [];
this.errors = [];
proto.instance = this;
this.log = console.log
this.info = console.info
this.error = console.error
this.logs = []
this.infos = []
this.errors = []
proto.instance = this
}
return proto.instance;
return proto.instance
}

/**
* Disable the console built-in methods
*/
disable () {
console.log = () => {};
console.info = () => {};
console.error = () => {};
console.log = () => {}
console.info = () => {}
console.error = () => {}
}

/**
* Capture the output of the console built-ins
*/
capture () {
console.log = log => { this.logs.push(log); };
console.info = info => { this.infos.push(info); };
console.error = err => { this.errors.push(err); };
console.log = log => { this.logs.push(log) }
console.info = info => { this.infos.push(info) }
console.error = err => { this.errors.push(err) }
}

/**
* Restore the built-in console methods
*/
restore () {
console.log = this.log;
console.info = this.info;
console.error = this.error;
console.log = this.log
console.info = this.info
console.error = this.error
}

/**
* Flush the captured console output
*/
flush () {
this.logs = [];
this.infos = [];
this.errors = [];
this.logs = []
this.infos = []
this.errors = []
}
}

export { MockConsole as default };
export { MockConsole as default }
32 changes: 16 additions & 16 deletions test/capture.spec.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import test from 'tape';
import { MockConsole } from '@vanillaes/mock-console';
import test from 'tape'
import { MockConsole } from '@vanillaes/mock-console'

test('MockConsole.capture() - Should should capture logs', (t) => {
const mc = new MockConsole();
mc.capture();
const log = 'console.log captured';
const info = 'console.info captured';
const error = 'console.error captured';
console.log(log);
console.info(info);
console.error(error);
mc.restore();
const mc = new MockConsole()
mc.capture()
const log = 'console.log captured'
const info = 'console.info captured'
const error = 'console.error captured'
console.log(log)
console.info(info)
console.error(error)
mc.restore()

t.deepEqual(mc.logs, [log], 'console.log() should be captured');
t.deepEqual(mc.infos, [info], 'console.info() should be captured');
t.deepEqual(mc.errors, [error], 'console.error() should be captured');
t.deepEqual(mc.logs, [log], 'console.log() should be captured')
t.deepEqual(mc.infos, [info], 'console.info() should be captured')
t.deepEqual(mc.errors, [error], 'console.error() should be captured')

t.end();
});
t.end()
})
24 changes: 12 additions & 12 deletions test/compat.spec.cjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const test = require('tape');
const { MockConsole } = require('@vanillaes/mock-console');
const test = require('tape')
const { MockConsole } = require('@vanillaes/mock-console')

test('Compat - Ensure the package works with CommonJS', (t) => {
const mc = new MockConsole();
const mc = new MockConsole()

t.notEqual(mc, null, 'MockConsole should exist');
t.equal(mc.log, console.log, 'MockConsole.log should store a reference to console.log');
t.equal(mc.info, console.info, 'MockConsole.info should store a reference to console.info');
t.equal(mc.error, console.error, 'MockConsole.error should store a reference to console.error');
t.deepEqual(mc.logs, [], 'MockConsole.logs should contain an empty array');
t.deepEqual(mc.infos, [], 'MockConsole.infos should contain an empty array');
t.deepEqual(mc.errors, [], 'MockConsole.errors should contain an empty array');
t.notEqual(mc, null, 'MockConsole should exist')
t.equal(mc.log, console.log, 'MockConsole.log should store a reference to console.log')
t.equal(mc.info, console.info, 'MockConsole.info should store a reference to console.info')
t.equal(mc.error, console.error, 'MockConsole.error should store a reference to console.error')
t.deepEqual(mc.logs, [], 'MockConsole.logs should contain an empty array')
t.deepEqual(mc.infos, [], 'MockConsole.infos should contain an empty array')
t.deepEqual(mc.errors, [], 'MockConsole.errors should contain an empty array')

t.end();
});
t.end()
})
20 changes: 10 additions & 10 deletions test/disable.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import test from 'tape';
import { MockConsole } from '@vanillaes/mock-console';
import test from 'tape'
import { MockConsole } from '@vanillaes/mock-console'

test('MockConsole.disable() - Should disable logging', (t) => {
const mc = new MockConsole();
mc.disable();
const mc = new MockConsole()
mc.disable()

t.notEqual(mc.log, console.log, 'console.log() should be disabled');
t.notEqual(mc.info, console.info, 'console.info() should be disabled');
t.notEqual(mc.error, console.error, 'console.error() should be disabled');
t.notEqual(mc.log, console.log, 'console.log() should be disabled')
t.notEqual(mc.info, console.info, 'console.info() should be disabled')
t.notEqual(mc.error, console.error, 'console.error() should be disabled')

mc.restore();
t.end();
});
mc.restore()
t.end()
})
28 changes: 14 additions & 14 deletions test/flush.spec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import test from 'tape';
import { MockConsole } from '@vanillaes/mock-console';
import test from 'tape'
import { MockConsole } from '@vanillaes/mock-console'

test('MockConsole.flush() - Should flushes all log buffers', (t) => {
const mc = new MockConsole();
mc.capture();
console.log('console.log captured');
console.info('console.info captured');
console.error('console.error captured');
mc.flush();
mc.restore();
const mc = new MockConsole()
mc.capture()
console.log('console.log captured')
console.info('console.info captured')
console.error('console.error captured')
mc.flush()
mc.restore()

t.deepEqual(mc.logs, [], 'console.logs should be empty');
t.deepEqual(mc.infos, [], 'console.infos should be empty');
t.deepEqual(mc.errors, [], 'console.errors should be empty');
t.deepEqual(mc.logs, [], 'console.logs should be empty')
t.deepEqual(mc.infos, [], 'console.infos should be empty')
t.deepEqual(mc.errors, [], 'console.errors should be empty')

t.end();
});
t.end()
})
20 changes: 10 additions & 10 deletions test/restore.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import test from 'tape';
import { MockConsole } from '@vanillaes/mock-console';
import test from 'tape'
import { MockConsole } from '@vanillaes/mock-console'

test('MockConsole.restore() - Should restore built-in logging', (t) => {
const mc = new MockConsole();
mc.disable();
mc.restore();
const mc = new MockConsole()
mc.disable()
mc.restore()

t.equal(mc.log, console.log, 'console.log() should be restored');
t.equal(mc.info, console.info, 'console.info() should be restored');
t.equal(mc.error, console.error, 'console.error() should be restored');
t.equal(mc.log, console.log, 'console.log() should be restored')
t.equal(mc.info, console.info, 'console.info() should be restored')
t.equal(mc.error, console.error, 'console.error() should be restored')

t.end();
});
t.end()
})
14 changes: 7 additions & 7 deletions test/singleton.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import test from 'tape';
import { MockConsole } from '@vanillaes/mock-console';
import test from 'tape'
import { MockConsole } from '@vanillaes/mock-console'

test('Singleton - MockConsole should be a singleton', (t) => {
const mc = new MockConsole();
const mc2 = new MockConsole();
const mc = new MockConsole()
const mc2 = new MockConsole()

t.equal(mc, mc2, 'MockConsoles should all point to the same instance');
t.equal(mc, mc2, 'MockConsoles should all point to the same instance')

t.end();
});
t.end()
})

0 comments on commit fd8194a

Please sign in to comment.