Skip to content

Commit 9d6e435

Browse files
authored
chore: Improves Integration CI logs (#577)
1 parent feb35f3 commit 9d6e435

File tree

9 files changed

+45
-18
lines changed

9 files changed

+45
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ If you observe an incorrect behavior while using Hathor headless wallet, see [th
2323
The Hathor headless wallet is tested automatically with unit tests and integration tests. See the following documentation for more information:
2424
- [Testing guidelines](/docs/testing.md)
2525

26-
Eventually, some changes to plugins or scripts may require specific testing not covered by those automated tests, but those should be analysed case by case on each PR.
26+
Eventually, some changes to plugins or scripts may require specific testing not covered by those automated tests, but those should be analyzed case by case on each PR.
2727

2828
## Contributing
2929

__tests__/integration/configuration/settings-fixture.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@ const defaultConfig = {
1818

1919
multisig: {},
2020

21+
// File logging for tests - captures verbose app logs for CI artifacts
22+
// This uses the existing config.logging mechanism in src/logger.js
23+
logging: {
24+
app: {
25+
filename: 'tmp/app.log',
26+
level: 'silly',
27+
},
28+
},
29+
2130
httpLogFormat: null,
22-
consoleLevel: 'silly',
31+
// Use TEST_CONSOLE_LEVEL=silly for verbose debugging
32+
consoleLevel: process.env.TEST_CONSOLE_LEVEL || 'warn',
2333
tokenUid: '',
2434
gapLimit: null,
2535

__tests__/integration/configuration/test.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ module.exports = {
77
// On CI, should match .github/workflows/integration-test.yml -> upload-artifact
88
logOutputFolder: process.env.TEST_LOG_OUTPUT_FOLDER || 'tmp/',
99

10-
// Console level used on winston
11-
consoleLevel: process.env.TEST_CONSOLE_LEVEL || 'silly',
10+
// Console level used on winston (defaults to 'warn' for quieter CI output)
11+
consoleLevel: process.env.TEST_CONSOLE_LEVEL || 'warn',
12+
13+
// File level used on winston (defaults to 'silly' for complete debugging in artifacts)
14+
fileLevel: process.env.TEST_FILE_LEVEL || 'silly',
1215

1316
// Defines how long tests should wait before consulting balances after transactions
1417
wsUpdateDelay: process.env.TEST_WS_UPDATE_DELAY || 2000,

__tests__/integration/plugins/integration_test_plugin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77
import _ from 'lodash';
8+
import { loggers } from '../utils/logger.util';
89

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

3435
messageListener = data => {
35-
console.log(`[${receivedEvents.length}] ${data.type} message added on ${data.walletId}.`);
36+
loggers.test?.insertLineToLog(
37+
`[${receivedEvents.length}] ${data.type} message added`,
38+
{ walletId: data.walletId }
39+
);
3640
receivedEvents.push(data);
3741
};
3842
busObject.on('message', messageListener);
3943

40-
console.log('plugin[test custom]: loaded');
44+
loggers.test?.insertLineToLog('plugin[test custom]: loaded');
4145
};
4246

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

5256
/**

__tests__/integration/utils/benchmark/wallet-benchmark.util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class WalletBenchmarkUtil {
9595
walletObj.hasFailed = true;
9696
break;
9797
default:
98-
console.warn(`Unknown wallet event: ${event}`);
98+
loggers.walletBenchmark?.insertWarnToLog(`Unknown wallet event: ${event}`);
9999
}
100100
}
101101

__tests__/integration/utils/logger.util.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable no-console */
2-
31
import winston from 'winston';
42
import testConfig from '../configuration/test.config';
53

@@ -73,7 +71,7 @@ export class LoggerUtil {
7371
winston.format.timestamp(),
7472
winston.format.colorize(),
7573
),
76-
level: testConfig.consoleLevel || 'silly',
74+
level: testConfig.consoleLevel,
7775
};
7876
const fileOptions = {
7977
format: options.filePrettyPrint
@@ -86,7 +84,7 @@ export class LoggerUtil {
8684
winston.format.json(),
8785
),
8886
filename: `${testConfig.logOutputFolder}${this.#instanceFilename}`,
89-
level: testConfig.consoleLevel || 'silly',
87+
level: testConfig.fileLevel,
9088
};
9189

9290
this.#logger = winston.createLogger({

__tests__/integration/utils/test-utils-integration.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable no-console */
2-
31
import supertest from 'supertest';
42
import superagent from 'superagent';
53
import { txApi, walletApi, HathorWallet, walletUtils, bigIntUtils } from '@hathor/wallet-lib';
@@ -186,7 +184,7 @@ export class TestUtils {
186184
* @param {string} message Custom error message
187185
*/
188186
static logError(message) {
189-
console.error(message);
187+
loggers.test.insertErrorToLog(message);
190188
}
191189

192190
/**
@@ -257,7 +255,7 @@ export class TestUtils {
257255
throw new Error(`Unable to start the wallet: ${walletObj.walletId}`);
258256
}
259257
if (!response.body.success) {
260-
console.error(`Failure starting the wallet: ${response.body.message}`);
258+
loggers.test.insertErrorToLog(`Failure starting the wallet: ${response.body.message}`);
261259
throw new Error(response.body.message);
262260
}
263261
const start = response.body;

docs/testing.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ On the [`./setupTests-integration.js` file](https://github.com/HathorNetwork/hat
4747
- All benchmarks files are handled to measure test times
4848
- The precalculated wallets persistent file is handled between test suites
4949

50+
### Log and debug outputs
51+
52+
All the logs generated by the integration tests are stored in the `tmp/` folder.
53+
- Each test suite has its own log file named after the suite file name
54+
- The application logs are stored on the `tmp/app.log` file
55+
- Other helper logs are stored in their respective files
56+
57+
On the CI context, all logs inside the `tmp` folder are collected and attached to the test run as _artifacts_ for further investigation. On the CI console, only `warn` and `error` logs are printed to avoid cluttering the output.
58+
59+
To find this artifact:
60+
- Open the GitHub Actions run page
61+
- Scroll to the bottom and find the `Upload debug transaction logs` section
62+
- Find the `Artifact download URL` and click it
63+
5064
### Sequential running
5165

5266
Currently the integration tests must be executed in sequence using the `--runInBand` jest feature. This means many of the tests expects the previous ones to have been run sucessfully and put the network state in a specific condition.

src/logger.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ function buildAppLogger(config) {
8686
// create a stream object with a 'write' function that will be used by `morgan`
8787
appLogger.stream = {
8888
write(message, _encoding) {
89-
// use the 'info' log level so the output will be picked up by
90-
// both transports (file + console)
89+
// Log HTTP requests at 'info' level. These will appear on transports
90+
// configured with level 'info' or more verbose (debug, silly, etc.)
9191
appLogger.info(message.trim(), {
9292
service: 'http',
9393
});

0 commit comments

Comments
 (0)