From f591b21fd948f7cbed1c1ca03f5f40bd2b3affd8 Mon Sep 17 00:00:00 2001 From: James Addison Date: Mon, 13 Apr 2020 11:01:09 +0100 Subject: [PATCH] Migrate away from deprecated function calls (#59) * Migrate away from deprecated function calls * Remove unnecessary function wrapping --- src/runner/configureMocha.ts | 13 ++++---- test/unit/runner/configureMocha.test.ts | 41 +++++++++++++++---------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/runner/configureMocha.ts b/src/runner/configureMocha.ts index fded8b0..e784d3d 100644 --- a/src/runner/configureMocha.ts +++ b/src/runner/configureMocha.ts @@ -7,19 +7,18 @@ export default function configureMocha(options: MochaWebpackOptions) { // infinite stack traces Error.stackTraceLimit = Infinity + const mochaOptions = { + color: !!options.colors, + inlineDiffs: !!options.useInlineDiffs + } + // init mocha - const mocha = new Mocha() + const mocha = new Mocha(mochaOptions) // reporter const reporter = loadReporter(options.reporter, options.cwd) mocha.reporter(reporter, options.reporterOptions) - // colors - mocha.useColors(options.colors) - - // inline-diffs - mocha.useInlineDiffs(options.useInlineDiffs) - // slow mocha.suite.slow(options.slow) diff --git a/test/unit/runner/configureMocha.test.ts b/test/unit/runner/configureMocha.test.ts index 24f4779..6836885 100644 --- a/test/unit/runner/configureMocha.test.ts +++ b/test/unit/runner/configureMocha.test.ts @@ -26,8 +26,6 @@ describe('configureMocha', function() { } this.sandbox = sandbox.create() this.spyReporter = this.sandbox.spy(Mocha.prototype, 'reporter') - this.spyUseColors = this.sandbox.spy(Mocha.prototype, 'useColors') - this.spyUseInlineDiffs = this.sandbox.spy(Mocha.prototype, 'useInlineDiffs') this.spyEnableTimeouts = this.sandbox.spy(Mocha.prototype, 'enableTimeouts') this.spyGrep = this.sandbox.spy(Mocha.prototype, 'grep') this.spyGrowl = this.sandbox.spy(Mocha.prototype, 'growl') @@ -60,27 +58,36 @@ describe('configureMocha', function() { ) }) - it('should call useColors()', function() { - configureMocha({ - ...this.options + it('should set color', function() { + var mocha = configureMocha({ + ...this.options, + colors: undefined }) - assert.isTrue(this.spyUseColors.called, 'useColors() should be called') - assert.isTrue(this.spyUseColors.calledWith(this.options.colors)) + assert.isFalse(mocha.options.color) + + mocha = configureMocha({ + ...this.options, + colors: true + }) + + assert.isTrue(mocha.options.color) }) - it('should call useInlineDiffs()', function() { - configureMocha({ - ...this.options + it('should set inlineDiffs', function() { + var mocha = configureMocha({ + ...this.options, + useInlineDiffs: undefined }) - assert.isTrue( - this.spyUseInlineDiffs.called, - 'useInlineDiffs() should be called' - ) - assert.isTrue( - this.spyUseInlineDiffs.calledWith(this.options.useInlineDiffs) - ) + assert.isFalse(mocha.options.inlineDiffs) + + mocha = configureMocha({ + ...this.options, + useInlineDiffs: true + }) + + assert.isTrue(mocha.options.inlineDiffs) }) it('should call enableTimeouts()', function() {