mirror of https://github.com/waku-org/js-waku.git
Improve helper function for log name
This commit is contained in:
parent
ea97bfa557
commit
ee0c63eba3
|
@ -1,6 +1,7 @@
|
|||
import { expect } from 'chai';
|
||||
|
||||
import { NOISE_KEY_1 } from '../test_utils/constants';
|
||||
import { makeLogFileName } from '../test_utils/log_file';
|
||||
import { NimWaku } from '../test_utils/nim_waku';
|
||||
|
||||
import Waku from './waku';
|
||||
|
@ -19,7 +20,7 @@ describe('Waku', function () {
|
|||
);
|
||||
const multiAddrWithId = localMultiaddr + '/p2p/' + peerId;
|
||||
|
||||
const nimWaku = new NimWaku(this.test!.title);
|
||||
const nimWaku = new NimWaku(makeLogFileName(this));
|
||||
await nimWaku.start({ staticnode: multiAddrWithId });
|
||||
|
||||
const nimPeers = await nimWaku.peers();
|
||||
|
|
|
@ -2,6 +2,7 @@ import { expect } from 'chai';
|
|||
import Pubsub from 'libp2p-interfaces/src/pubsub';
|
||||
|
||||
import { NOISE_KEY_1, NOISE_KEY_2 } from '../test_utils/constants';
|
||||
import { makeLogFileName } from '../test_utils/log_file';
|
||||
import { NimWaku } from '../test_utils/nim_waku';
|
||||
|
||||
import Waku from './waku';
|
||||
|
@ -77,7 +78,7 @@ describe('Waku Relay', () => {
|
|||
);
|
||||
const multiAddrWithId = localMultiaddr + '/p2p/' + peerId;
|
||||
|
||||
nimWaku = new NimWaku(this.test!.ctx!.currentTest!.title);
|
||||
nimWaku = new NimWaku(makeLogFileName(this));
|
||||
await nimWaku.start({ staticnode: multiAddrWithId });
|
||||
|
||||
await waku.relay.subscribe();
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
import { expect } from 'chai';
|
||||
|
||||
import { makeLogFileName } from './log_file';
|
||||
|
||||
describe('This', function () {
|
||||
describe('Is', function () {
|
||||
it('A test', function () {
|
||||
expect(makeLogFileName(this)).to.equal('This_Is_A_test');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Is also', function () {
|
||||
let testName: string;
|
||||
beforeEach(function () {
|
||||
testName = makeLogFileName(this);
|
||||
});
|
||||
it('A test', function () {
|
||||
expect(testName).to.equal('This_Is_also_A_test');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,3 +1,4 @@
|
|||
import { Context } from 'mocha';
|
||||
import pTimeout from 'p-timeout';
|
||||
import { Tail } from 'tail';
|
||||
|
||||
|
@ -34,3 +35,19 @@ async function find(tail: Tail, line: string) {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
function clean(str: string): string {
|
||||
return str.replace(/ /g, '_').replace(/[':()]/g, '');
|
||||
}
|
||||
|
||||
export function makeLogFileName(ctx: Context): string {
|
||||
const unitTest = ctx!.currentTest ? ctx!.currentTest : ctx.test;
|
||||
let name = clean(unitTest!.title);
|
||||
let suite = unitTest!.parent;
|
||||
|
||||
while (suite && suite.title) {
|
||||
name = clean(suite.title) + '_' + name;
|
||||
suite = suite.parent;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -37,12 +37,9 @@ export class NimWaku {
|
|||
private peerId?: PeerId;
|
||||
private logPath: string;
|
||||
|
||||
constructor(testName: string) {
|
||||
constructor(logName: string) {
|
||||
this.portsShift = randomInt(0, 5000);
|
||||
|
||||
const logFilePrefix = testName.replace(/ /g, '_').replace(/[':()]/g, '');
|
||||
|
||||
this.logPath = `${LOG_DIR}/${logFilePrefix}-nim-waku.log`;
|
||||
this.logPath = `${LOG_DIR}/nim-waku_${logName}.log`;
|
||||
}
|
||||
|
||||
async start(args: Args) {
|
||||
|
|
Loading…
Reference in New Issue