Skip to content

Commit f46d944

Browse files
sonicoder86ngabor84
andcommitted
chore(test): cleanup scope usage
EME-5173 Co-authored-by: Gabor Nemeth <[email protected]>
1 parent 38367fa commit f46d944

File tree

7 files changed

+35
-24
lines changed

7 files changed

+35
-24
lines changed

src/enabled/enabled.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { isNamespaceEnabled } = require('./enabled');
2+
const { expect } = require('chai');
23

34
describe('isNamespaceAvailable', function() {
45
it('should enable when variables only contain one', function() {

src/formatter/json.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { expect } = require('chai');
12
const { jsonFormatter } = require('./json');
23

34
describe('json formatter', function() {

src/formatter/logentries.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { expect } = require('chai');
12
const { logentriesFormatter } = require('./logentries');
23

34
describe('logentries formatter', function() {

src/index.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { expect } = require('chai');
12
const { createLogger, Logger } = require('./index');
23

34
describe('createLogger', function() {

src/logger/logger.spec.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
const { expect } = require('chai');
2+
const sinon = require('sinon');
13
const { Logger } = require('./logger');
24
const { jsonFormatter } = require('../formatter/json');
35
const { consoleOutput } = require('../output/console');
46

57
describe('Logger', function() {
68
let logger;
9+
let clock;
710

811
beforeEach(function() {
912
logger = new Logger('mongo', true);
10-
this.sandbox.stub(Logger.config, 'output');
13+
sinon.stub(Logger.config, 'output');
14+
clock = sinon.useFakeTimers();
1115
});
1216

1317
afterEach(function() {
@@ -16,6 +20,7 @@ describe('Logger', function() {
1620
output: consoleOutput,
1721
transformers: []
1822
});
23+
clock.restore();
1924
});
2025

2126
it('should call log info method when enabled', function() {
@@ -48,9 +53,9 @@ describe('Logger', function() {
4853
it('should not call log info method when disabled', function() {
4954
logger = new Logger('mongo', false);
5055
const timer = logger.timer();
51-
const infoStub = this.sandbox.stub(logger, 'info');
56+
const infoStub = sinon.stub(logger, 'info');
5257

53-
this.clock.tick(100);
58+
clock.tick(100);
5459
timer.info('hi');
5560

5661
expect(infoStub).to.have.been.calledWith('hi', { duration: 100 });
@@ -253,7 +258,7 @@ describe('Logger', function() {
253258
describe('#configure', function() {
254259
it('should change format method', function() {
255260
const formattedOutput = '{"my":"method"}';
256-
const formatterStub = this.sandbox.stub();
261+
const formatterStub = sinon.stub();
257262
formatterStub.returns(formattedOutput);
258263

259264
Logger.configure({
@@ -266,7 +271,7 @@ describe('Logger', function() {
266271
});
267272

268273
it('should change output method', function() {
269-
const outputStub = this.sandbox.stub();
274+
const outputStub = sinon.stub();
270275
Logger.configure({
271276
output: outputStub
272277
});

src/setup.spec.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
const sinon = require('sinon');
22
const chai = require('chai');
33
const sinonChai = require('sinon-chai');
4-
global.expect = require('chai').expect;
54

65
chai.use(sinonChai);
7-
global.expect = chai.expect;
86

9-
beforeEach(function() {
10-
this.sandbox = sinon.createSandbox();
11-
this.clock = sinon.useFakeTimers();
12-
});
13-
14-
afterEach(function() {
15-
this.sandbox.restore();
16-
this.sandbox = undefined;
17-
this.clock.restore();
18-
this.clock = undefined;
7+
afterEach(() => {
8+
sinon.restore();
199
});

src/timer/timer.spec.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,51 @@
1+
const { expect } = require('chai');
2+
const sinon = require('sinon');
13
const { Logger } = require('../logger/logger');
24
const { Timer } = require('./timer');
35

46
describe('Timer', function() {
7+
let clock;
8+
9+
beforeEach(() => {
10+
clock = sinon.useFakeTimers();
11+
});
12+
13+
afterEach(() => {
14+
clock.restore();
15+
});
16+
517
it('should log elapsed time', function() {
618
const logger = new Logger('test', false);
7-
const infoStub = this.sandbox.stub(logger, 'info');
19+
const infoStub = sinon.stub(logger, 'info');
820
const timer = new Timer(logger);
921

10-
this.clock.tick(100);
22+
clock.tick(100);
1123
timer.info('time', { customer_id: 10 });
1224

1325
expect(infoStub).to.have.been. calledWith('time', { customer_id: 10, duration: 100 });
1426
});
1527

1628
it('should log elapsed time with error', function() {
1729
const logger = new Logger('test', false);
18-
const errorStub = this.sandbox.stub(logger, 'fromError');
30+
const errorStub = sinon.stub(logger, 'fromError');
1931
const timer = new Timer(logger);
2032
const error = new Error('intended');
2133

22-
this.clock.tick(100);
34+
clock.tick(100);
2335
timer.fromError('time', error, { customer_id: 10 });
2436

2537
expect(errorStub).to.have.been. calledWith('time', error, { customer_id: 10, duration: 100 });
2638
});
2739

2840
it('should log elapsed time with error', function() {
2941
const logger = new Logger('test', false);
30-
const errorStub = this.sandbox.stub(logger, 'warnFromError');
42+
const errorStub = sinon.stub(logger, 'warnFromError');
3143
const timer = new Timer(logger);
3244
const error = new Error('intended');
3345

34-
this.clock.tick(100);
46+
clock.tick(100);
3547
timer.warnFromError('time', error, { customer_id: 10 });
3648

37-
expect(errorStub).to.have.been. calledWith('time', error, { customer_id: 10, duration: 100 });
49+
expect(errorStub).to.have.been.calledWith('time', error, { customer_id: 10, duration: 100 });
3850
});
3951
});

0 commit comments

Comments
 (0)