test log messages

This commit is contained in:
Jan Prochazka
2024-09-12 08:24:50 +02:00
parent 51c8169232
commit 00a6c19f09
4 changed files with 61 additions and 7 deletions

View File

@@ -0,0 +1,3 @@
module.exports = {
setupFilesAfterEnv: ['<rootDir>/setupTests.js'],
};

View File

@@ -11,12 +11,9 @@
"scripts": {
"wait:local": "cross-env DEVMODE=1 LOCALTEST=1 node wait.js",
"wait:ci": "cross-env DEVMODE=1 CITEST=1 node wait.js",
"test:local": "cross-env DEVMODE=1 LOCALTEST=1 jest",
"test:local:path": "cross-env DEVMODE=1 LOCALTEST=1 jest --runTestsByPath __tests__/data-duplicator.spec.js",
"test:ci": "cross-env DEVMODE=1 CITEST=1 jest --runInBand --json --outputFile=result.json --testLocationInResults",
"run:local": "docker-compose down && docker-compose up -d && yarn wait:local && yarn test:local"
},
"jest": {
@@ -24,7 +21,7 @@
},
"devDependencies": {
"cross-env": "^7.0.3",
"jest": "^27.0.1"
},
"dependencies": {}
"jest": "^27.0.1",
"pino-pretty": "^11.2.2"
}
}

View File

@@ -0,0 +1,22 @@
const { prettyFactory } = require('pino-pretty');
const pretty = prettyFactory({
colorize: true,
translateTime: 'SYS:standard',
ignore: 'pid,hostname',
});
global.console = {
...console,
log: (...messages) => {
try {
const parsedMessage = JSON.parse(messages[0]);
process.stdout.write(pretty(parsedMessage) + '\n');
} catch (error) {
process.stdout.write(messages.join(' ') + '\n');
}
},
debug: (...messages) => {
process.stdout.write(messages.join(' ') + '\n');
},
};