Skip to content

Commit 917e3c7

Browse files
committed
multiple parents
1 parent 6511f02 commit 917e3c7

File tree

4 files changed

+75
-44
lines changed

4 files changed

+75
-44
lines changed

dist/index.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -382,17 +382,17 @@ class DefaultView {
382382
testStart (test) {
383383
if (this.options.viewShowStarts) {
384384
const th = this.theme;
385-
const parent = test.parent ? test.parent.name : '';
385+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : '';
386386
this.log(`[${th.groupDark}]{∙ ${parent}} [${th.testDark}]{${test.name}}`);
387387
}
388388
}
389389

390-
testPass (test, result) {
390+
testPass (test) {
391391
const th = this.theme;
392-
const parent = test.parent ? test.parent.name : '';
393-
result = result === undefined ? '' : ` [${result}]`;
392+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : '';
393+
const result = test.result === undefined ? '' : ` [${test.result}]`;
394394
const duration = test.stats.duration.toFixed(1) + 'ms';
395-
this.log(`[${th.pass}]{✓} [${th.group}]{${parent}} ${test.name}${result} [${th.duration}]{${duration}}`);
395+
this.log(`[${th.pass}]{✓} [${th.group}]{${parent}}${test.name}${result} [${th.duration}]{${duration}}`);
396396
if (test.context.data) {
397397
if (typeof window === 'undefined') {
398398
const str = this.inspect(test.context.data);
@@ -404,8 +404,8 @@ class DefaultView {
404404

405405
testFail (test, err) {
406406
const th = this.theme;
407-
const parent = test.parent ? test.parent.name : '';
408-
this.log(`[${th.fail}]{⨯} [${th.group}]{${parent}}`, test.name);
407+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : '';
408+
this.log(`[${th.fail}]{⨯} [${th.group}]{${parent}}${test.name}`);
409409
const errMessage = this.indent(this.getErrorMessage(err), ' ');
410410
this.log(`\n${errMessage.trimEnd()}\n`);
411411
if (test.context.data) {
@@ -420,24 +420,24 @@ class DefaultView {
420420
testSkip (test) {
421421
if (!this.options.viewHideSkips) {
422422
const th = this.theme;
423-
const parent = test.parent ? test.parent.name : '';
424-
this.log(`[${th.skip}]{-} [${th.skip}]{${parent}} [${th.skip}]{${test.name}}`);
423+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : '';
424+
this.log(`[${th.skip}]{-} [${th.skip}]{${parent}}[${th.skip}]{${test.name}}`);
425425
}
426426
}
427427

428428
testTodo (test) {
429429
if (!this.options.viewHideSkips) {
430430
const th = this.theme;
431-
const parent = test.parent ? test.parent.name : '';
432-
this.log(`[${th.todo}]{-} [${th.todo}]{${parent}} [${th.todo}]{${test.name}}`);
431+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : '';
432+
this.log(`[${th.todo}]{-} [${th.todo}]{${parent}}[${th.todo}]{${test.name}}`);
433433
}
434434
}
435435

436436
testIgnore (test) {
437437
if (!this.options.viewHideSkips) {
438438
const th = this.theme;
439-
const parent = test.parent ? test.parent.name : '';
440-
this.log(`[${th.ignore}]{-} [${th.ignore}]{${parent}} [${th.ignore}]{${test.name}}`);
439+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : '';
440+
this.log(`[${th.ignore}]{-} [${th.ignore}]{${parent}}[${th.ignore}]{${test.name}}`);
441441
}
442442
}
443443

dist/index.mjs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,17 @@ class DefaultView {
361361
testStart (test) {
362362
if (this.options.viewShowStarts) {
363363
const th = this.theme;
364-
const parent = test.parent ? test.parent.name : '';
364+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : '';
365365
this.log(`[${th.groupDark}]{∙ ${parent}} [${th.testDark}]{${test.name}}`);
366366
}
367367
}
368368

369-
testPass (test, result) {
369+
testPass (test) {
370370
const th = this.theme;
371-
const parent = test.parent ? test.parent.name : '';
372-
result = result === undefined ? '' : ` [${result}]`;
371+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : '';
372+
const result = test.result === undefined ? '' : ` [${test.result}]`;
373373
const duration = test.stats.duration.toFixed(1) + 'ms';
374-
this.log(`[${th.pass}]{✓} [${th.group}]{${parent}} ${test.name}${result} [${th.duration}]{${duration}}`);
374+
this.log(`[${th.pass}]{✓} [${th.group}]{${parent}}${test.name}${result} [${th.duration}]{${duration}}`);
375375
if (test.context.data) {
376376
if (typeof window === 'undefined') {
377377
const str = this.inspect(test.context.data);
@@ -383,8 +383,8 @@ class DefaultView {
383383

384384
testFail (test, err) {
385385
const th = this.theme;
386-
const parent = test.parent ? test.parent.name : '';
387-
this.log(`[${th.fail}]{⨯} [${th.group}]{${parent}}`, test.name);
386+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : '';
387+
this.log(`[${th.fail}]{⨯} [${th.group}]{${parent}}${test.name}`);
388388
const errMessage = this.indent(this.getErrorMessage(err), ' ');
389389
this.log(`\n${errMessage.trimEnd()}\n`);
390390
if (test.context.data) {
@@ -399,24 +399,24 @@ class DefaultView {
399399
testSkip (test) {
400400
if (!this.options.viewHideSkips) {
401401
const th = this.theme;
402-
const parent = test.parent ? test.parent.name : '';
403-
this.log(`[${th.skip}]{-} [${th.skip}]{${parent}} [${th.skip}]{${test.name}}`);
402+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : '';
403+
this.log(`[${th.skip}]{-} [${th.skip}]{${parent}}[${th.skip}]{${test.name}}`);
404404
}
405405
}
406406

407407
testTodo (test) {
408408
if (!this.options.viewHideSkips) {
409409
const th = this.theme;
410-
const parent = test.parent ? test.parent.name : '';
411-
this.log(`[${th.todo}]{-} [${th.todo}]{${parent}} [${th.todo}]{${test.name}}`);
410+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : '';
411+
this.log(`[${th.todo}]{-} [${th.todo}]{${parent}}[${th.todo}]{${test.name}}`);
412412
}
413413
}
414414

415415
testIgnore (test) {
416416
if (!this.options.viewHideSkips) {
417417
const th = this.theme;
418-
const parent = test.parent ? test.parent.name : '';
419-
this.log(`[${th.ignore}]{-} [${th.ignore}]{${parent}} [${th.ignore}]{${test.name}}`);
418+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : '';
419+
this.log(`[${th.ignore}]{-} [${th.ignore}]{${parent}}[${th.ignore}]{${test.name}}`);
420420
}
421421
}
422422

index.mjs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ class DefaultView {
4242
testStart (test) {
4343
if (this.options.viewShowStarts) {
4444
const th = this.theme
45-
const parent = test.parent ? test.parent.name : ''
45+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : ''
4646
this.log(`[${th.groupDark}]{∙ ${parent}} [${th.testDark}]{${test.name}}`)
4747
}
4848
}
4949

50-
testPass (test, result) {
50+
testPass (test) {
5151
const th = this.theme
52-
const parent = test.parent ? test.parent.name : ''
53-
result = result === undefined ? '' : ` [${result}]`
52+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : ''
53+
const result = test.result === undefined ? '' : ` [${test.result}]`
5454
const duration = test.stats.duration.toFixed(1) + 'ms'
55-
this.log(`[${th.pass}]{✓} [${th.group}]{${parent}} ${test.name}${result} [${th.duration}]{${duration}}`)
55+
this.log(`[${th.pass}]{✓} [${th.group}]{${parent}}${test.name}${result} [${th.duration}]{${duration}}`)
5656
if (test.context.data) {
5757
if (typeof window === 'undefined') {
5858
const str = this.inspect(test.context.data)
@@ -64,8 +64,8 @@ class DefaultView {
6464

6565
testFail (test, err) {
6666
const th = this.theme
67-
const parent = test.parent ? test.parent.name : ''
68-
this.log(`[${th.fail}]{⨯} [${th.group}]{${parent}}`, test.name)
67+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : ''
68+
this.log(`[${th.fail}]{⨯} [${th.group}]{${parent}}${test.name}`)
6969
const errMessage = this.indent(this.getErrorMessage(err), ' ')
7070
this.log(`\n${errMessage.trimEnd()}\n`)
7171
if (test.context.data) {
@@ -80,24 +80,24 @@ class DefaultView {
8080
testSkip (test) {
8181
if (!this.options.viewHideSkips) {
8282
const th = this.theme
83-
const parent = test.parent ? test.parent.name : ''
84-
this.log(`[${th.skip}]{-} [${th.skip}]{${parent}} [${th.skip}]{${test.name}}`)
83+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : ''
84+
this.log(`[${th.skip}]{-} [${th.skip}]{${parent}}[${th.skip}]{${test.name}}`)
8585
}
8686
}
8787

8888
testTodo (test) {
8989
if (!this.options.viewHideSkips) {
9090
const th = this.theme
91-
const parent = test.parent ? test.parent.name : '';
92-
this.log(`[${th.todo}]{-} [${th.todo}]{${parent}} [${th.todo}]{${test.name}}`);
91+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : '';
92+
this.log(`[${th.todo}]{-} [${th.todo}]{${parent}}[${th.todo}]{${test.name}}`);
9393
}
9494
}
9595

9696
testIgnore (test) {
9797
if (!this.options.viewHideSkips) {
9898
const th = this.theme
99-
const parent = test.parent ? test.parent.name : '';
100-
this.log(`[${th.ignore}]{-} [${th.ignore}]{${parent}} [${th.ignore}]{${test.name}}`);
99+
const parent = test.parent ? test.parents().map(p => p.name).join(' > ').trim() + ' ' : '';
100+
this.log(`[${th.ignore}]{-} [${th.ignore}]{${parent}}[${th.ignore}]{${test.name}}`);
101101
}
102102
}
103103

test.mjs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ const defaultView = new DefaultView({ viewShowStarts: true })
99
console.log('Main report:')
1010
defaultView.start(10)
1111
const parent = new Tom('parent')
12-
const test = parent.test('test 1', () => 1)
12+
const test = parent.test('main test 1', () => 1)
1313
await test.run()
1414
defaultView.testStart(test)
1515
defaultView.testSkip(test)
16-
const test2 = parent.test('test 2', () => 2)
16+
const test2 = parent.test('main test 2', () => 2)
1717
await test2.run()
1818
defaultView.testPass(test2)
19-
const test3 = parent.test('test 3', () => { throw new Error('broken') })
19+
const test3 = parent.test('main test 3', () => { throw new Error('broken') })
2020
try {
2121
await test3.run()
2222
} catch (err) {
2323
defaultView.testFail(test3, test3.result)
2424
}
2525

26-
const todo = parent.todo('a todo')
26+
const todo = parent.todo('main: a todo')
2727
defaultView.testTodo(todo)
2828
}
2929

@@ -46,10 +46,41 @@ const defaultView = new DefaultView({ viewShowStarts: true })
4646
start().catch(console.error)
4747
}
4848

49+
{ /* deep tree, multiple parents: pass */
50+
async function start () {
51+
await defaultView.init()
52+
const tom = new Tom('root')
53+
const tom2 = tom.group('level 1')
54+
const test = tom2.test('deep tree', function () {})
55+
await test.run()
56+
defaultView.testPass(test)
57+
}
58+
59+
start().catch(console.error)
60+
}
61+
62+
{ /* deep tree, multiple parents: fail */
63+
async function start () {
64+
await defaultView.init()
65+
const tom = new Tom('root')
66+
const tom2 = tom.group('level 1')
67+
const test = tom2.test('deep tree fail', function () {
68+
throw new Error('broken')
69+
})
70+
try {
71+
await test.run()
72+
} catch (err) {
73+
defaultView.testFail(test, test.result)
74+
}
75+
}
76+
77+
start().catch(console.error)
78+
}
79+
4980
{ /* context data: fail */
5081
async function start () {
5182
await defaultView.init()
52-
const test = new Tom('test 2', function () {
83+
const test = new Tom('context data: fail', function () {
5384
this.data = {
5485
something: 'one',
5586
yeah: true

0 commit comments

Comments
 (0)