@@ -12,11 +12,16 @@ import {Component} from '@angular/core';
12
12
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
13
13
import { MatButtonModule } from '@angular/material/button' ;
14
14
import { MatButtonHarness } from '@angular/material/button/testing/button-harness' ;
15
- import { benchmark , getButtonWithText } from './testbed-benchmark-utilities ' ;
16
- import { FIRST_BUTTON , MIDDLE_BUTTON , NUM_BUTTONS , LAST_BUTTON } from './constants ' ;
15
+ import { MIDDLE_BUTTON , NUM_BUTTONS } from './constants ' ;
16
+ import { benchmark } from './testbed-benchmark-utilities ' ;
17
17
18
- describe ( 'performance baseline for the testbed harness' , ( ) => {
18
+ describe ( 'performance for the testbed harness environment ' , ( ) => {
19
19
let fixture : ComponentFixture < ButtonHarnessTest > ;
20
+ let loader : HarnessLoader ;
21
+
22
+ beforeAll ( ( ) => {
23
+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 36000000 ;
24
+ } ) ;
20
25
21
26
beforeEach ( async ( ) => {
22
27
await TestBed . configureTestingModule ( {
@@ -26,103 +31,81 @@ describe('performance baseline for the testbed harness', () => {
26
31
27
32
fixture = TestBed . createComponent ( ButtonHarnessTest ) ;
28
33
fixture . detectChanges ( ) ;
34
+ loader = TestbedHarnessEnvironment . loader ( fixture ) ;
29
35
} ) ;
30
36
31
- it ( '(baseline) should retrieve all of the buttons' , async ( ) => {
32
- await benchmark ( '(baseline) get every button' , async ( ) => {
33
- document . querySelectorAll ( 'button' ) ;
34
- } ) ;
35
- } ) ;
36
-
37
- it ( '(baseline) should click the first button' , async ( ) => {
38
- await benchmark ( '(baseline) click first button' , async ( ) => {
39
- const button = getButtonWithText ( FIRST_BUTTON ) ;
40
- button . click ( ) ;
37
+ describe ( '(baseline)' , ( ) => {
38
+ it ( 'should find a button' , async ( ) => {
39
+ await benchmark ( '(baseline) find a button' , async ( ) => {
40
+ document . querySelector ( 'button' ) ;
41
+ } ) ;
41
42
} ) ;
42
- } ) ;
43
43
44
- it ( '(baseline) should click the middle button ' , async ( ) => {
45
- await benchmark ( '(baseline) click middle button ' , async ( ) => {
46
- const button = getButtonWithText ( MIDDLE_BUTTON ) ;
47
- button . click ( ) ;
44
+ it ( 'should find all buttons ' , async ( ) => {
45
+ await benchmark ( '(baseline) find all buttons ' , async ( ) => {
46
+ document . querySelectorAll ( 'button' ) ;
47
+ } ) ;
48
48
} ) ;
49
- } ) ;
50
49
51
- it ( '(baseline) should click the last button' , async ( ) => {
52
- await benchmark ( '(baseline) click last button' , async ( ) => {
53
- const button = getButtonWithText ( LAST_BUTTON ) ;
54
- button . click ( ) ;
50
+ it ( 'should find a button via text filter' , async ( ) => {
51
+ await benchmark ( '(baseline) find a button via text filter' , async ( ) => {
52
+ return Array . from ( document . querySelectorAll ( 'button' ) )
53
+ . filter ( b => b . innerText === MIDDLE_BUTTON ) ;
54
+ } ) ;
55
55
} ) ;
56
- } ) ;
57
56
58
- it ( '(baseline) should click all of the buttons' , async ( ) => {
59
- await benchmark ( '(baseline) click every button' , async ( ) => {
60
- const buttons = document . getElementsByTagName ( 'button' ) ;
61
- for ( let i = 0 ; i < buttons . length ; i ++ ) {
62
- const button = buttons [ i ] ;
57
+ it ( 'should click a button' , async ( ) => {
58
+ const button = document . querySelector ( 'button' ) ! ;
59
+ await benchmark ( '(baseline) click a button' , async ( ) => {
63
60
button . click ( ) ;
64
- }
61
+ fixture . detectChanges ( ) ;
62
+ } ) ;
65
63
} ) ;
66
- } ) ;
67
- } ) ;
68
64
69
- describe ( 'performance tests for the testbed harness' , ( ) => {
70
- let fixture : ComponentFixture < ButtonHarnessTest > ;
71
- let loader : HarnessLoader ;
72
-
73
- beforeEach ( async ( ) => {
74
- await TestBed . configureTestingModule ( {
75
- imports : [ MatButtonModule ] ,
76
- declarations : [ ButtonHarnessTest ] ,
77
- } ) . compileComponents ( ) ;
78
-
79
- fixture = TestBed . createComponent ( ButtonHarnessTest ) ;
80
- fixture . detectChanges ( ) ;
81
- loader = TestbedHarnessEnvironment . loader ( fixture ) ;
65
+ it ( 'should click all buttons' , async ( ) => {
66
+ const buttons = Array . prototype . slice . call ( document . querySelectorAll ( 'button' ) ) ;
67
+ await benchmark ( '(baseline) click all buttons' , async ( ) => {
68
+ buttons . forEach ( button => button . click ( ) ) ;
69
+ fixture . detectChanges ( ) ;
70
+ } ) ;
71
+ } ) ;
82
72
} ) ;
83
73
84
- it ( 'should retrieve all of the buttons' , async ( ) => {
85
- await benchmark ( 'get every button' , async ( ) => {
86
- await loader . getAllHarnesses ( MatButtonHarness ) ;
74
+ describe ( '(with harness)' , ( ) => {
75
+ it ( 'should find a button' , async ( ) => {
76
+ await benchmark ( '(with harness) find a button' , async ( ) => {
77
+ await loader . getHarness ( MatButtonHarness ) ;
78
+ } ) ;
87
79
} ) ;
88
- } ) ;
89
80
90
- it ( 'should click the first button ' , async ( ) => {
91
- await benchmark ( 'click first button ' , async ( ) => {
92
- const button = await loader . getHarness ( MatButtonHarness . with ( { text : FIRST_BUTTON } ) ) ;
93
- await button . click ( ) ;
81
+ it ( 'should find all buttons ' , async ( ) => {
82
+ await benchmark ( '(with harness) find all buttons ' , async ( ) => {
83
+ await loader . getAllHarnesses ( MatButtonHarness ) ;
84
+ } ) ;
94
85
} ) ;
95
- } ) ;
96
86
97
- it ( 'should click the middle button' , async ( ) => {
98
- await benchmark ( 'click middle button' , async ( ) => {
99
- const button = await loader . getHarness ( MatButtonHarness . with ( { text : MIDDLE_BUTTON } ) ) ;
100
- await button . click ( ) ;
87
+ it ( 'should find a button via text filter ' , async ( ) => {
88
+ await benchmark ( '(with harness) find a button via text filter ' , async ( ) => {
89
+ await loader . getAllHarnesses ( MatButtonHarness . with ( { text : MIDDLE_BUTTON } ) ) ;
90
+ } ) ;
101
91
} ) ;
102
- } ) ;
103
92
104
- it ( 'should click the last button' , async ( ) => {
105
- await benchmark ( 'click last button' , async ( ) => {
106
- const button = await loader . getHarness ( MatButtonHarness . with ( { text : LAST_BUTTON } ) ) ;
107
- await button . click ( ) ;
93
+ it ( 'should click a button' , async ( ) => {
94
+ const button = await loader . getHarness ( MatButtonHarness ) ;
95
+ await benchmark ( '(with harness) click a button' , async ( ) => {
96
+ await button . click ( ) ;
97
+ } ) ;
108
98
} ) ;
109
- } ) ;
110
99
111
- it ( 'should click all of the buttons' , async ( ) => {
112
- await benchmark ( 'click every button' , async ( ) => {
100
+ it ( 'should click all buttons' , async ( ) => {
113
101
const buttons = await loader . getAllHarnesses ( MatButtonHarness ) ;
114
- for ( let i = 0 ; i < buttons . length ; i ++ ) {
115
- const button = buttons [ i ] ;
116
- await button . click ( ) ;
117
- }
102
+ await benchmark ( '(with harness) click all buttons' , async ( ) => {
103
+ await Promise . all ( buttons . map ( button => button . click ( ) ) ) ;
104
+ } ) ;
118
105
} ) ;
119
106
} ) ;
120
107
121
- // To see the benchmarks for this test, uncomment the it test below.
122
- //
123
- // I don't know how to force karma_web_test to show logs in the console so we are using this as
124
- // a solution for now.
125
- // it('should fail intentionally', () => expect(1).toBe(2));
108
+ it ( 'should fail intentionally so performance numbers are logged' , fail ) ;
126
109
} ) ;
127
110
128
111
@Component ( {
0 commit comments