diff --git a/test/sandbox-coverage.js b/test/sandbox-coverage.js index 1632f427..c6fb7595 100644 --- a/test/sandbox-coverage.js +++ b/test/sandbox-coverage.js @@ -13,3 +13,34 @@ 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, + })) + ) + )); + +// 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())); + })); 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/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: { 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' ); 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' },