From 5f617cc94b9d5aedaa81696bc00bcc07568bb477 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Sun, 24 Jul 2022 16:30:36 +0800 Subject: [PATCH 1/2] refactor(test): added `callback` for `beforeEach()` and `afterEach()` for tap v14 downgrade --- test/tap/appender-dependencies-test.js | 6 ++++-- test/tap/categoryFilter-test.js | 3 ++- test/tap/configuration-test.js | 4 +++- test/tap/connect-context-test.js | 6 ++++-- test/tap/connect-nolog-test.js | 18 ++++++++++++------ test/tap/logger-test.js | 3 ++- test/tap/multiprocess-test.js | 3 ++- test/tap/newLevel-test.js | 3 ++- test/tap/noLogFilter-test.js | 3 ++- 9 files changed, 33 insertions(+), 16 deletions(-) diff --git a/test/tap/appender-dependencies-test.js b/test/tap/appender-dependencies-test.js index 045c8c1..84afeb8 100644 --- a/test/tap/appender-dependencies-test.js +++ b/test/tap/appender-dependencies-test.js @@ -8,12 +8,14 @@ let log4js; let recording; test('log4js appender dependencies', (batch) => { - batch.beforeEach(() => { + batch.beforeEach((done) => { log4js = require('../../lib/log4js'); recording = require('../../lib/appenders/recording'); + done(); }); - batch.afterEach(() => { + batch.afterEach((done) => { recording.erase(); + done(); }); batch.test('in order', (t) => { const config = { diff --git a/test/tap/categoryFilter-test.js b/test/tap/categoryFilter-test.js index af9bba7..45f2f7d 100644 --- a/test/tap/categoryFilter-test.js +++ b/test/tap/categoryFilter-test.js @@ -3,8 +3,9 @@ const log4js = require('../../lib/log4js'); const recording = require('../../lib/appenders/recording'); test('log4js categoryFilter', (batch) => { - batch.beforeEach(() => { + batch.beforeEach((done) => { recording.reset(); + done(); }); batch.test('appender should exclude categories', (t) => { diff --git a/test/tap/configuration-test.js b/test/tap/configuration-test.js index 1fced15..dd359dd 100644 --- a/test/tap/configuration-test.js +++ b/test/tap/configuration-test.js @@ -10,7 +10,7 @@ let dependencies; let fileRead; test('log4js configure', (batch) => { - batch.beforeEach(() => { + batch.beforeEach((done) => { fileRead = 0; fakeFS = { @@ -55,6 +55,8 @@ test('log4js configure', (batch) => { fs: fakeFS, }, }; + + done(); }); batch.test( diff --git a/test/tap/connect-context-test.js b/test/tap/connect-context-test.js index f843222..17f41a4 100644 --- a/test/tap/connect-context-test.js +++ b/test/tap/connect-context-test.js @@ -68,8 +68,9 @@ test('log4js connect logger', (batch) => { const ml = new MockLogger(); const cl = clm(ml, { context: true }); - t.beforeEach(() => { + t.beforeEach((done) => { ml.contexts = []; + done(); }); t.test('response should be included in context', (assert) => { @@ -96,8 +97,9 @@ test('log4js connect logger', (batch) => { const ml = new MockLogger(); const cl = clm(ml, {}); - t.beforeEach(() => { + t.beforeEach((done) => { ml.contexts = []; + done(); }); t.test('response should not be included in context', (assert) => { diff --git a/test/tap/connect-nolog-test.js b/test/tap/connect-nolog-test.js index a0b1e30..9ee0e9b 100644 --- a/test/tap/connect-nolog-test.js +++ b/test/tap/connect-nolog-test.js @@ -59,8 +59,9 @@ test('log4js connect logger', (batch) => { const ml = new MockLogger(); const cl = clm(ml, { nolog: '\\.gif' }); - t.beforeEach(() => { + t.beforeEach((done) => { ml.messages = []; + done(); }); t.test('check unmatch url request', (assert) => { @@ -106,8 +107,9 @@ test('log4js connect logger', (batch) => { const ml = new MockLogger(); const cl = clm(ml, { nolog: '\\.gif|\\.jpe?g' }); - t.beforeEach(() => { + t.beforeEach((done) => { ml.messages = []; + done(); }); t.test('check unmatch url request (png)', (assert) => { @@ -167,8 +169,9 @@ test('log4js connect logger', (batch) => { const ml = new MockLogger(); const cl = clm(ml, { nolog: ['\\.gif', '\\.jpe?g'] }); - t.beforeEach(() => { + t.beforeEach((done) => { ml.messages = []; + done(); }); t.test('check unmatch url request (png)', (assert) => { @@ -228,8 +231,9 @@ test('log4js connect logger', (batch) => { const ml = new MockLogger(); const cl = clm(ml, { nolog: /\.gif|\.jpe?g/ }); - t.beforeEach(() => { + t.beforeEach((done) => { ml.messages = []; + done(); }); t.test('check unmatch url request (png)', (assert) => { @@ -289,8 +293,9 @@ test('log4js connect logger', (batch) => { const ml = new MockLogger(); const cl = clm(ml, { nolog: [/\.gif/, /\.jpe?g/] }); - t.beforeEach(() => { + t.beforeEach((done) => { ml.messages = []; + done(); }); t.test('check unmatch url request (png)', (assert) => { @@ -353,8 +358,9 @@ test('log4js connect logger', (batch) => { res.getHeader('content-type') === 'image/png' || res.statusCode < 400, }); - t.beforeEach(() => { + t.beforeEach((done) => { ml.messages = []; + done(); }); t.test('check unmatch function return (statusCode < 400)', (assert) => { diff --git a/test/tap/logger-test.js b/test/tap/logger-test.js index a3eb738..9b8930f 100644 --- a/test/tap/logger-test.js +++ b/test/tap/logger-test.js @@ -35,9 +35,10 @@ const testConfig = { }; test('../../lib/logger', (batch) => { - batch.beforeEach(() => { + batch.beforeEach((done) => { events.length = 0; testConfig.level = levels.TRACE; + done(); }); batch.test('constructor with no parameters', (t) => { diff --git a/test/tap/multiprocess-test.js b/test/tap/multiprocess-test.js index b67aa55..7fbc5b8 100644 --- a/test/tap/multiprocess-test.js +++ b/test/tap/multiprocess-test.js @@ -51,8 +51,9 @@ function makeFakeNet() { } test('Multiprocess Appender', async (batch) => { - batch.beforeEach(() => { + batch.beforeEach((done) => { recording.erase(); + done(); }); batch.test('worker', (t) => { diff --git a/test/tap/newLevel-test.js b/test/tap/newLevel-test.js index 4f58148..1fa0e7f 100644 --- a/test/tap/newLevel-test.js +++ b/test/tap/newLevel-test.js @@ -3,8 +3,9 @@ const log4js = require('../../lib/log4js'); const recording = require('../../lib/appenders/recording'); test('../../lib/logger', (batch) => { - batch.beforeEach(() => { + batch.beforeEach((done) => { recording.reset(); + done(); }); batch.test('creating a new log level', (t) => { diff --git a/test/tap/noLogFilter-test.js b/test/tap/noLogFilter-test.js index d52cf48..0230d14 100644 --- a/test/tap/noLogFilter-test.js +++ b/test/tap/noLogFilter-test.js @@ -6,8 +6,9 @@ const recording = require('../../lib/appenders/recording'); * test a simple regexp */ test('log4js noLogFilter', (batch) => { - batch.beforeEach(() => { + batch.beforeEach((done) => { recording.reset(); + done(); }); batch.test( From 879e8c764691c0372878b830488d85d64946ce0f Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Mon, 25 Jul 2022 14:42:36 +0800 Subject: [PATCH 2/2] refactor(test): forward-compatible with tap v15 when `callback` is removed from `beforeEach` and `afterEach` in tap 15.0.0, libtap was added: https://github.com/tapjs/libtap/compare/v0.3.0...v1.0.0#diff-e41924228a867ab0a0d8689f84ae6d826da70a0d65fc59ae2c69539035c4ef6aL905-L915 --- test/tap/appender-dependencies-test.js | 8 ++++++-- test/tap/categoryFilter-test.js | 4 +++- test/tap/configuration-test.js | 4 +++- test/tap/connect-context-test.js | 8 ++++++-- test/tap/connect-nolog-test.js | 24 ++++++++++++++++++------ test/tap/logger-test.js | 4 +++- test/tap/multiprocess-test.js | 4 +++- test/tap/newLevel-test.js | 4 +++- test/tap/noLogFilter-test.js | 4 +++- 9 files changed, 48 insertions(+), 16 deletions(-) diff --git a/test/tap/appender-dependencies-test.js b/test/tap/appender-dependencies-test.js index 84afeb8..4c680e7 100644 --- a/test/tap/appender-dependencies-test.js +++ b/test/tap/appender-dependencies-test.js @@ -11,11 +11,15 @@ test('log4js appender dependencies', (batch) => { batch.beforeEach((done) => { log4js = require('../../lib/log4js'); recording = require('../../lib/appenders/recording'); - done(); + if (typeof done === 'function') { + done(); + } }); batch.afterEach((done) => { recording.erase(); - done(); + if (typeof done === 'function') { + done(); + } }); batch.test('in order', (t) => { const config = { diff --git a/test/tap/categoryFilter-test.js b/test/tap/categoryFilter-test.js index 45f2f7d..40c2840 100644 --- a/test/tap/categoryFilter-test.js +++ b/test/tap/categoryFilter-test.js @@ -5,7 +5,9 @@ const recording = require('../../lib/appenders/recording'); test('log4js categoryFilter', (batch) => { batch.beforeEach((done) => { recording.reset(); - done(); + if (typeof done === 'function') { + done(); + } }); batch.test('appender should exclude categories', (t) => { diff --git a/test/tap/configuration-test.js b/test/tap/configuration-test.js index dd359dd..dfcaeac 100644 --- a/test/tap/configuration-test.js +++ b/test/tap/configuration-test.js @@ -56,7 +56,9 @@ test('log4js configure', (batch) => { }, }; - done(); + if (typeof done === 'function') { + done(); + } }); batch.test( diff --git a/test/tap/connect-context-test.js b/test/tap/connect-context-test.js index 17f41a4..ffd88dc 100644 --- a/test/tap/connect-context-test.js +++ b/test/tap/connect-context-test.js @@ -70,7 +70,9 @@ test('log4js connect logger', (batch) => { t.beforeEach((done) => { ml.contexts = []; - done(); + if (typeof done === 'function') { + done(); + } }); t.test('response should be included in context', (assert) => { @@ -99,7 +101,9 @@ test('log4js connect logger', (batch) => { t.beforeEach((done) => { ml.contexts = []; - done(); + if (typeof done === 'function') { + done(); + } }); t.test('response should not be included in context', (assert) => { diff --git a/test/tap/connect-nolog-test.js b/test/tap/connect-nolog-test.js index 9ee0e9b..1d780a7 100644 --- a/test/tap/connect-nolog-test.js +++ b/test/tap/connect-nolog-test.js @@ -61,7 +61,9 @@ test('log4js connect logger', (batch) => { t.beforeEach((done) => { ml.messages = []; - done(); + if (typeof done === 'function') { + done(); + } }); t.test('check unmatch url request', (assert) => { @@ -109,7 +111,9 @@ test('log4js connect logger', (batch) => { t.beforeEach((done) => { ml.messages = []; - done(); + if (typeof done === 'function') { + done(); + } }); t.test('check unmatch url request (png)', (assert) => { @@ -171,7 +175,9 @@ test('log4js connect logger', (batch) => { t.beforeEach((done) => { ml.messages = []; - done(); + if (typeof done === 'function') { + done(); + } }); t.test('check unmatch url request (png)', (assert) => { @@ -233,7 +239,9 @@ test('log4js connect logger', (batch) => { t.beforeEach((done) => { ml.messages = []; - done(); + if (typeof done === 'function') { + done(); + } }); t.test('check unmatch url request (png)', (assert) => { @@ -295,7 +303,9 @@ test('log4js connect logger', (batch) => { t.beforeEach((done) => { ml.messages = []; - done(); + if (typeof done === 'function') { + done(); + } }); t.test('check unmatch url request (png)', (assert) => { @@ -360,7 +370,9 @@ test('log4js connect logger', (batch) => { t.beforeEach((done) => { ml.messages = []; - done(); + if (typeof done === 'function') { + done(); + } }); t.test('check unmatch function return (statusCode < 400)', (assert) => { diff --git a/test/tap/logger-test.js b/test/tap/logger-test.js index 9b8930f..62c5834 100644 --- a/test/tap/logger-test.js +++ b/test/tap/logger-test.js @@ -38,7 +38,9 @@ test('../../lib/logger', (batch) => { batch.beforeEach((done) => { events.length = 0; testConfig.level = levels.TRACE; - done(); + if (typeof done === 'function') { + done(); + } }); batch.test('constructor with no parameters', (t) => { diff --git a/test/tap/multiprocess-test.js b/test/tap/multiprocess-test.js index 7fbc5b8..7577b1d 100644 --- a/test/tap/multiprocess-test.js +++ b/test/tap/multiprocess-test.js @@ -53,7 +53,9 @@ function makeFakeNet() { test('Multiprocess Appender', async (batch) => { batch.beforeEach((done) => { recording.erase(); - done(); + if (typeof done === 'function') { + done(); + } }); batch.test('worker', (t) => { diff --git a/test/tap/newLevel-test.js b/test/tap/newLevel-test.js index 1fa0e7f..10714fe 100644 --- a/test/tap/newLevel-test.js +++ b/test/tap/newLevel-test.js @@ -5,7 +5,9 @@ const recording = require('../../lib/appenders/recording'); test('../../lib/logger', (batch) => { batch.beforeEach((done) => { recording.reset(); - done(); + if (typeof done === 'function') { + done(); + } }); batch.test('creating a new log level', (t) => { diff --git a/test/tap/noLogFilter-test.js b/test/tap/noLogFilter-test.js index 0230d14..00fe6a3 100644 --- a/test/tap/noLogFilter-test.js +++ b/test/tap/noLogFilter-test.js @@ -8,7 +8,9 @@ const recording = require('../../lib/appenders/recording'); test('log4js noLogFilter', (batch) => { batch.beforeEach((done) => { recording.reset(); - done(); + if (typeof done === 'function') { + done(); + } }); batch.test(