Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion __tests__/integration/configuration/settings-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ const defaultConfig = {

multisig: {},

// File logging for tests - captures verbose app logs for CI artifacts
// This uses the existing config.logging mechanism in src/logger.js
logging: {
app: {
filename: 'tmp/app.log',
level: 'silly',
},
},

httpLogFormat: null,
consoleLevel: 'silly',
// Use TEST_CONSOLE_LEVEL=silly for verbose debugging
consoleLevel: process.env.TEST_CONSOLE_LEVEL || 'warn',
tokenUid: '',
gapLimit: null,

Expand Down
7 changes: 5 additions & 2 deletions __tests__/integration/configuration/test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ module.exports = {
// On CI, should match .github/workflows/integration-test.yml -> upload-artifact
logOutputFolder: process.env.TEST_LOG_OUTPUT_FOLDER || 'tmp/',

// Console level used on winston
consoleLevel: process.env.TEST_CONSOLE_LEVEL || 'silly',
// Console level used on winston (defaults to 'warn' for quieter CI output)
consoleLevel: process.env.TEST_CONSOLE_LEVEL || 'warn',

// File level used on winston (defaults to 'silly' for complete debugging in artifacts)
fileLevel: process.env.TEST_FILE_LEVEL || 'silly',

// Defines how long tests should wait before consulting balances after transactions
wsUpdateDelay: process.env.TEST_WS_UPDATE_DELAY || 2000,
Expand Down
10 changes: 7 additions & 3 deletions __tests__/integration/plugins/integration_test_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import _ from 'lodash';
import { loggers } from '../utils/logger.util';

/**
* This plugin is used for testing purposes, storing all events received and allowing their easy
Expand Down Expand Up @@ -32,12 +33,15 @@ export const init = async bus => {
busObject = bus;

messageListener = data => {
console.log(`[${receivedEvents.length}] ${data.type} message added on ${data.walletId}.`);
loggers.test?.insertLineToLog(
`[${receivedEvents.length}] ${data.type} message added`,
{ walletId: data.walletId }
);
receivedEvents.push(data);
};
busObject.on('message', messageListener);

console.log('plugin[test custom]: loaded');
loggers.test?.insertLineToLog('plugin[test custom]: loaded');
};

/**
Expand All @@ -46,7 +50,7 @@ export const init = async bus => {
export const close = () => {
busObject.off('message', messageListener);
busObject = null;
console.log('plugin[test custom]: closed');
loggers.test?.insertLineToLog('plugin[test custom]: closed');
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class WalletBenchmarkUtil {
walletObj.hasFailed = true;
break;
default:
console.warn(`Unknown wallet event: ${event}`);
loggers.walletBenchmark?.insertWarnToLog(`Unknown wallet event: ${event}`);
}
}

Expand Down
6 changes: 2 additions & 4 deletions __tests__/integration/utils/logger.util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-console */

import winston from 'winston';
import testConfig from '../configuration/test.config';

Expand Down Expand Up @@ -73,7 +71,7 @@ export class LoggerUtil {
winston.format.timestamp(),
winston.format.colorize(),
),
level: testConfig.consoleLevel || 'silly',
level: testConfig.consoleLevel,
};
const fileOptions = {
format: options.filePrettyPrint
Expand All @@ -86,7 +84,7 @@ export class LoggerUtil {
winston.format.json(),
),
filename: `${testConfig.logOutputFolder}${this.#instanceFilename}`,
level: testConfig.consoleLevel || 'silly',
level: testConfig.fileLevel,
};

this.#logger = winston.createLogger({
Expand Down
6 changes: 2 additions & 4 deletions __tests__/integration/utils/test-utils-integration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-console */

import supertest from 'supertest';
import superagent from 'superagent';
import { txApi, walletApi, HathorWallet, walletUtils, bigIntUtils } from '@hathor/wallet-lib';
Expand Down Expand Up @@ -186,7 +184,7 @@ export class TestUtils {
* @param {string} message Custom error message
*/
static logError(message) {
console.error(message);
loggers.test.insertErrorToLog(message);
}

/**
Expand Down Expand Up @@ -257,7 +255,7 @@ export class TestUtils {
throw new Error(`Unable to start the wallet: ${walletObj.walletId}`);
}
if (!response.body.success) {
console.error(`Failure starting the wallet: ${response.body.message}`);
loggers.test.insertErrorToLog(`Failure starting the wallet: ${response.body.message}`);
throw new Error(response.body.message);
}
const start = response.body;
Expand Down
4 changes: 2 additions & 2 deletions src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ function buildAppLogger(config) {
// create a stream object with a 'write' function that will be used by `morgan`
appLogger.stream = {
write(message, _encoding) {
// use the 'info' log level so the output will be picked up by
// both transports (file + console)
// Log HTTP requests at 'info' level. These will appear on transports
// configured with level 'info' or more verbose (debug, silly, etc.)
appLogger.info(message.trim(), {
service: 'http',
});
Expand Down