mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 21:07:48 +00:00
29 lines
752 B
JavaScript
29 lines
752 B
JavaScript
const fs = require('fs');
|
|
const util = require('util');
|
|
const isCi = require('is-ci');
|
|
|
|
const shouldWriteToFile = isCi || process.env.WRITE_LOGS_TO_FILES;
|
|
|
|
exports.logWithinTest = logWithinTest;
|
|
|
|
const dateFormat = new Intl.DateTimeFormat('en-us', {
|
|
dateStyle: 'short',
|
|
timeStyle: 'medium',
|
|
});
|
|
|
|
function logWithinTest(...inputs) {
|
|
const { testPath, currentTestName } = expect.getState();
|
|
|
|
const messages = [dateFormat.format(new Date()), currentTestName, ...inputs];
|
|
const message = messages
|
|
.map(x => (typeof x === 'string' ? x : util.inspect(x)))
|
|
.join('\t');
|
|
|
|
if (shouldWriteToFile) {
|
|
const filePath = `${testPath}.artifact.log`;
|
|
fs.appendFileSync(filePath, `${message.trim()}\n`);
|
|
}
|
|
|
|
console.log(message.trim());
|
|
}
|