From bf57536760e8cf89fbbab43dde130dab9cb9380f Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Sat, 23 Jul 2022 16:16:59 +0800 Subject: [PATCH 1/6] test: polyfill `Promise.allSettled` for Node.js <12 --- test/sandbox-coverage.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/sandbox-coverage.js b/test/sandbox-coverage.js index 1632f427..eed75444 100644 --- a/test/sandbox-coverage.js +++ b/test/sandbox-coverage.js @@ -13,3 +13,21 @@ sandbox.configure({ }, }, }); + +// polyfill for Node.js <12 +Promise.allSettled = + Promise.allSettled || + ((promises) => + Promise.all( + promises.map((p) => + p + .then((value) => ({ + status: 'fulfilled', + value, + })) + .catch((reason) => ({ + status: 'rejected', + reason, + })) + ) + )); From 35080bde5ec1104b82a8f8e193bd248b7da9cf14 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Sat, 23 Jul 2022 22:54:24 +0800 Subject: [PATCH 2/6] test: polyfill `process.off` for Node.js <10 --- test/sandbox-coverage.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/sandbox-coverage.js b/test/sandbox-coverage.js index eed75444..b6c922fa 100644 --- a/test/sandbox-coverage.js +++ b/test/sandbox-coverage.js @@ -31,3 +31,6 @@ Promise.allSettled = })) ) )); + +// polyfill for Node.js <10 +process.off = process.off || process.removeListener; From abe8e67a5c04f5a9a248103067698d7f2c49716c Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Sun, 24 Jul 2022 20:28:10 +0800 Subject: [PATCH 3/6] test: polyfill `fs.promises.unlink` for Node.js <10 --- test/sandbox-coverage.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/sandbox-coverage.js b/test/sandbox-coverage.js index b6c922fa..c6fb7595 100644 --- a/test/sandbox-coverage.js +++ b/test/sandbox-coverage.js @@ -34,3 +34,13 @@ Promise.allSettled = // polyfill for Node.js <10 process.off = process.off || process.removeListener; + +// polyfill for Node.js <10 +const fs = require('fs'); // eslint-disable-line import/newline-after-import +fs.promises = fs.promises || {}; +fs.promises.unlink = + fs.promises.unlink || + ((...args) => + new Promise((resolve, reject) => { + fs.unlink(...args, (err) => (err ? reject(err) : resolve())); + })); From adcc06fb88523a3bfe64c7883efd501f2ce59963 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Mon, 25 Jul 2022 00:16:05 +0800 Subject: [PATCH 4/6] test: refactor `fs.mkdirSync(..., { recursive: true })` for Node.js <10.12.0 --- test/tap/fileSyncAppender-test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/tap/fileSyncAppender-test.js b/test/tap/fileSyncAppender-test.js index 1330d10b..912b1ab0 100644 --- a/test/tap/fileSyncAppender-test.js +++ b/test/tap/fileSyncAppender-test.js @@ -524,7 +524,9 @@ test('log4js fileSyncAppender', (batch) => { errorEROFS ); - fs.mkdirSync('tmpA/tmpB/tmpC', { recursive: true }); + fs.mkdirSync('tmpA'); + fs.mkdirSync('tmpA/tmpB'); + fs.mkdirSync('tmpA/tmpB/tmpC'); sandboxedLog4js = sandbox.require('../../lib/log4js', { requires: { From 09c4096c49d64d9893b4e8e2a4614dfabbee44ae Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Mon, 25 Jul 2022 00:25:27 +0800 Subject: [PATCH 5/6] test: adjusted regexp for stacktrace for Node.js <=10 --- test/tap/layouts-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tap/layouts-test.js b/test/tap/layouts-test.js index e925bf54..8a77b483 100644 --- a/test/tap/layouts-test.js +++ b/test/tap/layouts-test.js @@ -121,7 +121,7 @@ test('log4js layouts', (batch) => { }, }, }), - /at (Test\.batch\.test\.t|Test\.)\s+\((.*)test[\\/]tap[\\/]layouts-test\.js:\d+:\d+\)/, + /at (Test\.batch\.test(\.t)?|Test\.)\s+\((.*)test[\\/]tap[\\/]layouts-test\.js:\d+:\d+\)/, 'regexp did not return a match - should print the stacks of a passed error objects' ); From 0a936d1831bbfeb93ca3f157c880bfed244cb2f0 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Mon, 25 Jul 2022 00:27:29 +0800 Subject: [PATCH 6/6] test: extended timeout interval for OS operations --- test/tap/fileAppender-test.js | 2 +- test/tap/multiprocess-shutdown-test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tap/fileAppender-test.js b/test/tap/fileAppender-test.js index e7a79347..964942c8 100644 --- a/test/tap/fileAppender-test.js +++ b/test/tap/fileAppender-test.js @@ -151,7 +151,7 @@ test('log4js fileAppender', (batch) => { logger.info('This is an intermediate log message.'); logger.info('This is the second log message.'); // wait for the file system to catch up - await sleep(100); + await sleep(250); const fileContents = await fs.readFile(testFile, 'utf8'); t.match(fileContents, 'This is the second log message.'); t.equal(fileContents.indexOf('This is the first log message.'), -1); diff --git a/test/tap/multiprocess-shutdown-test.js b/test/tap/multiprocess-shutdown-test.js index e46fede7..e62cf765 100644 --- a/test/tap/multiprocess-shutdown-test.js +++ b/test/tap/multiprocess-shutdown-test.js @@ -4,7 +4,7 @@ const childProcess = require('child_process'); const sandbox = require('@log4js-node/sandboxed-module'); const log4js = require('../../lib/log4js'); -test('multiprocess appender shutdown (master)', { timeout: 5000 }, (t) => { +test('multiprocess appender shutdown (master)', { timeout: 10000 }, (t) => { log4js.configure({ appenders: { stdout: { type: 'stdout' },