From 7e490aa13e8ed25c78e77faa6fed0337e948b619 Mon Sep 17 00:00:00 2001 From: Sujin Park Date: Sat, 31 Oct 2020 04:00:14 +0900 Subject: [PATCH] Change assert module's deprecated methods in testing files (#4435) * Change deprecated methods in assert library * update getDiffs when node version v10 * skip test in no-diff.spec.js when Node.js 10 * revert diffs.spec.js output changes, skip diffs.spec.js when Node.js 10 * skip diffs.spec.js when Node.js 10 --- docs/example/debug-hanging-mocha.js | 2 +- test/integration/diffs.spec.js | 6 +++++ .../fixtures/current-test-title.fixture.js | 14 ++++++------ .../fixtures/diffs/diffs.fixture.js | 22 +++++++++---------- test/integration/fixtures/no-diff.fixture.js | 2 +- .../fixtures/retries/early-pass.fixture.js | 4 ++-- .../fixtures/uncaught/listeners.fixture.js | 4 ++-- test/integration/no-diff.spec.js | 6 +++++ 8 files changed, 36 insertions(+), 24 deletions(-) diff --git a/docs/example/debug-hanging-mocha.js b/docs/example/debug-hanging-mocha.js index fb36dc83c4..92772ca0ab 100644 --- a/docs/example/debug-hanging-mocha.js +++ b/docs/example/debug-hanging-mocha.js @@ -15,7 +15,7 @@ describe('how to debug Mocha when it hangs', function () { it('should complete, but Mocha should not exit', function(done) { const sock = net.createConnection(10101, () => { - assert.deepEqual(sock.address().family, 'IPv4'); + assert.deepStrictEqual(sock.address().family, 'IPv4'); done(); }); }); diff --git a/test/integration/diffs.spec.js b/test/integration/diffs.spec.js index ac9ad18d26..1606b8579d 100644 --- a/test/integration/diffs.spec.js +++ b/test/integration/diffs.spec.js @@ -72,6 +72,12 @@ describe('diffs', function() { var diffs, expected; before(function(done) { + // @TODO: It should be removed when Node.js 10 LTS is not supported. + const nodeVersion = parseInt(process.version.match(/^v(\d+)\./)[1], 10); + if (nodeVersion === 10) { + this.skip(); + } + run('diffs/diffs.fixture.js', [], function(err, res) { if (err) { done(err); diff --git a/test/integration/fixtures/current-test-title.fixture.js b/test/integration/fixtures/current-test-title.fixture.js index 6b5057e780..6cf3dc3a7f 100644 --- a/test/integration/fixtures/current-test-title.fixture.js +++ b/test/integration/fixtures/current-test-title.fixture.js @@ -6,13 +6,13 @@ function getTitle(ctx) { }; before(function () { - assert.equal(getTitle(this), undefined); + assert.strictEqual(getTitle(this), undefined); }); describe('suite A', () => { before(function () { - assert.equal(getTitle(this), undefined); + assert.strictEqual(getTitle(this), undefined); }); describe('suite B', () => { @@ -23,25 +23,25 @@ describe('suite A', () => { var lap = 0; before(function () { - assert.equal(getTitle(this), 'test1 C'); + assert.strictEqual(getTitle(this), 'test1 C'); }); beforeEach(function () { - assert.equal(getTitle(this), ++lap === 1 ? 'test1 C' : 'test2 C'); + assert.strictEqual(getTitle(this), ++lap === 1 ? 'test1 C' : 'test2 C'); }); it('test1 C', function () {}); it('test2 C', function () {}); afterEach(function () { - assert.equal(getTitle(this), lap === 1 ? 'test1 C' : 'test2 C'); + assert.strictEqual(getTitle(this), lap === 1 ? 'test1 C' : 'test2 C'); }); after(function () { - assert.equal(getTitle(this), 'test2 C'); + assert.strictEqual(getTitle(this), 'test2 C'); }); }); }); }); after(function () { - assert.equal(getTitle(this), undefined); + assert.strictEqual(getTitle(this), undefined); }); diff --git a/test/integration/fixtures/diffs/diffs.fixture.js b/test/integration/fixtures/diffs/diffs.fixture.js index e9b01d351e..7dd8989bef 100644 --- a/test/integration/fixtures/diffs/diffs.fixture.js +++ b/test/integration/fixtures/diffs/diffs.fixture.js @@ -12,19 +12,19 @@ describe('diffs', function () { it('should display a diff for small strings', function () { actual = 'foo rar baz'; expected = 'foo bar baz'; - assert.equal(actual, expected); + assert.strictEqual(actual, expected); }); it('should display a diff of canonicalized objects', function () { actual = { name: 'travis j', age: 23 }; expected = { age: 23, name: 'travis' }; - assert.deepEqual(actual, expected); + assert.deepStrictEqual(actual, expected); }); it('should display a diff for medium strings', function () { actual = 'foo bar baz\nfoo rar baz\nfoo bar raz'; expected = 'foo bar baz\nfoo bar baz\nfoo bar baz'; - assert.equal(actual, expected); + assert.strictEqual(actual, expected); }); it('should display a diff for entire object dumps', function () { @@ -44,13 +44,13 @@ describe('diffs', function () { country: 'us' } }; - assert.deepEqual(actual, expected); + assert.deepStrictEqual(actual, expected); }); it('should display a diff for multi-line strings', function () { actual = 'one two three\nfour zzzz six\nseven eight nine'; expected = 'one two three\nfour five six\nseven eight nine'; - assert.equal(actual, expected); + assert.strictEqual(actual, expected); }); it('should display a diff for entire object dumps', function () { @@ -70,17 +70,17 @@ describe('diffs', function () { country: 'us' } }; - assert.deepEqual(actual, expected); + assert.deepStrictEqual(actual, expected); }); it('should display a full-comparison with escaped special characters', function () { actual = 'one\ttab\ntwo\t\t\ttabs'; expected = 'one\ttab\ntwo\t\ttabs'; - assert.equal(actual, expected); + assert.strictEqual(actual, expected); }); it('should display a word diff for large strings', function () { - assert.equal(cssin, cssout); + assert.strictEqual(cssin, cssout); }); it('should work with objects', function () { @@ -98,18 +98,18 @@ describe('diffs', function () { age: 2 }; - assert.deepEqual(actual, expected); + assert.deepStrictEqual(actual, expected); }); it('should show value diffs and not be affected by commas', function () { actual = { a: 123 }; expected = { a: 123, b: 456 }; - assert.deepEqual(actual, expected); + assert.deepStrictEqual(actual, expected); }); it('should display diff by data and not like an objects', function () { actual = Buffer.from([0x01]); expected = Buffer.from([0x02]); - assert.deepEqual(actual, expected); + assert.deepStrictEqual(actual, expected); }); }); diff --git a/test/integration/fixtures/no-diff.fixture.js b/test/integration/fixtures/no-diff.fixture.js index 22b80ae86e..a3715880dc 100644 --- a/test/integration/fixtures/no-diff.fixture.js +++ b/test/integration/fixtures/no-diff.fixture.js @@ -3,6 +3,6 @@ var assert = require('assert'); describe('Example test', function () { it('should fail', function () { - assert.deepEqual([1, 2, 3], ['foo', 'bar', 'baz']); + assert.deepStrictEqual([1, 2, 3], ['foo', 'bar', 'baz']); }); }); diff --git a/test/integration/fixtures/retries/early-pass.fixture.js b/test/integration/fixtures/retries/early-pass.fixture.js index 87ef703a7a..6153b9fb10 100644 --- a/test/integration/fixtures/retries/early-pass.fixture.js +++ b/test/integration/fixtures/retries/early-pass.fixture.js @@ -14,8 +14,8 @@ describe('retries', function () { }); it('check for updated `suite.tests`', function() { - assert.equal(self.tests[0]._currentRetry, 1); + assert.strictEqual(self.tests[0]._currentRetry, 1); assert.ok(self.tests[0]._retriedTest); - assert.equal(self.tests[0].state, 'passed'); + assert.strictEqual(self.tests[0].state, 'passed'); }) }); diff --git a/test/integration/fixtures/uncaught/listeners.fixture.js b/test/integration/fixtures/uncaught/listeners.fixture.js index fa7ba4106d..33c7089245 100644 --- a/test/integration/fixtures/uncaught/listeners.fixture.js +++ b/test/integration/fixtures/uncaught/listeners.fixture.js @@ -9,5 +9,5 @@ for (let i = 0; i < 5; i++) { r.run(); } -assert.equal(process.listenerCount('uncaughtException'), 1); -assert.equal(process.listeners('uncaughtException')[0].name, 'uncaught'); +assert.strictEqual(process.listenerCount('uncaughtException'), 1); +assert.strictEqual(process.listeners('uncaughtException')[0].name, 'uncaught'); diff --git a/test/integration/no-diff.spec.js b/test/integration/no-diff.spec.js index cc26fc24c3..1b791c1338 100644 --- a/test/integration/no-diff.spec.js +++ b/test/integration/no-diff.spec.js @@ -6,6 +6,12 @@ var run = helpers.runMocha; describe('no-diff', function() { describe('when enabled', function() { it('should not display a diff', function(done) { + // @TODO: It should be removed when Node.js 10 LTS is not supported. + const nodeVersion = parseInt(process.version.match(/^v(\d+)\./)[1], 10); + if (nodeVersion === 10) { + this.skip(); + } + run('no-diff.fixture.js', ['--no-diff'], function(err, res) { if (err) { done(err);