Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: support older Node.js versions #1295

Merged
merged 6 commits into from Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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