Skip to content

Commit

Permalink
Merge pull request #1295 from log4js-node/update-test
Browse files Browse the repository at this point in the history
test: support older Node.js versions
  • Loading branch information
lamweili committed Jul 24, 2022
2 parents 39218cc + 0a936d1 commit 76c6230
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
31 changes: 31 additions & 0 deletions test/sandbox-coverage.js
Expand Up @@ -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()));
}));
2 changes: 1 addition & 1 deletion test/tap/fileAppender-test.js
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion test/tap/fileSyncAppender-test.js
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion test/tap/layouts-test.js
Expand Up @@ -121,7 +121,7 @@ test('log4js layouts', (batch) => {
},
},
}),
/at (Test\.batch\.test\.t|Test\.<anonymous>)\s+\((.*)test[\\/]tap[\\/]layouts-test\.js:\d+:\d+\)/,
/at (Test\.batch\.test(\.t)?|Test\.<anonymous>)\s+\((.*)test[\\/]tap[\\/]layouts-test\.js:\d+:\d+\)/,
'regexp did not return a match - should print the stacks of a passed error objects'
);

Expand Down
2 changes: 1 addition & 1 deletion test/tap/multiprocess-shutdown-test.js
Expand Up @@ -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' },
Expand Down

0 comments on commit 76c6230

Please sign in to comment.