7
7
8
8
/* eslint-env jest */
9
9
10
- const snapshotModule = { snapshot : jest . fn ( ) } ;
10
+ const { createMockPage, mockRunnerModule} = require ( './gather/mock-driver.js' ) ;
11
+
12
+ const snapshotModule = { snapshotGather : jest . fn ( ) } ;
11
13
jest . mock ( '../../fraggle-rock/gather/snapshot-runner.js' , ( ) => snapshotModule ) ;
12
- const navigationModule = { navigation : jest . fn ( ) } ;
14
+ const navigationModule = { navigationGather : jest . fn ( ) } ;
13
15
jest . mock ( '../../fraggle-rock/gather/navigation-runner.js' , ( ) => navigationModule ) ;
14
- const timespanModule = { startTimespan : jest . fn ( ) } ;
16
+ const timespanModule = { startTimespanGather : jest . fn ( ) } ;
15
17
jest . mock ( '../../fraggle-rock/gather/timespan-runner.js' , ( ) => timespanModule ) ;
16
18
17
- const { createMockPage} = require ( './gather/mock-driver.js' ) ;
19
+ const mockRunner = mockRunnerModule ( ) ;
20
+
18
21
const UserFlow = require ( '../../fraggle-rock/user-flow.js' ) ;
19
22
20
23
describe ( 'UserFlow' , ( ) => {
21
24
let mockPage = createMockPage ( ) ;
22
25
23
26
beforeEach ( ( ) => {
24
27
mockPage = createMockPage ( ) ;
25
- const lhr = { finalUrl : 'https://www.example.com' } ;
26
28
27
- snapshotModule . snapshot . mockReset ( ) ;
28
- snapshotModule . snapshot . mockResolvedValue ( { lhr : { ...lhr , gatherMode : 'snapshot' } } ) ;
29
+ mockRunner . reset ( ) ;
30
+
31
+ snapshotModule . snapshotGather . mockReset ( ) ;
32
+ snapshotModule . snapshotGather . mockResolvedValue ( {
33
+ artifacts : {
34
+ URL : { finalUrl : 'https://www.example.com' } ,
35
+ GatherContext : { gatherMode : 'snapshot' } ,
36
+ } ,
37
+ runnerOptions : {
38
+ config : { } ,
39
+ computedCache : new Map ( ) ,
40
+ } ,
41
+ } ) ;
29
42
30
- navigationModule . navigation . mockReset ( ) ;
31
- navigationModule . navigation . mockResolvedValue ( { lhr : { ...lhr , gatherMode : 'navigation' } } ) ;
43
+ navigationModule . navigationGather . mockReset ( ) ;
44
+ navigationModule . navigationGather . mockResolvedValue ( {
45
+ artifacts : {
46
+ URL : { finalUrl : 'https://www.example.com' } ,
47
+ GatherContext : { gatherMode : 'navigation' } ,
48
+ } ,
49
+ runnerOptions : {
50
+ config : { } ,
51
+ computedCache : new Map ( ) ,
52
+ } ,
53
+ } ) ;
32
54
33
- const timespanLhr = { ...lhr , gatherMode : 'timespan' } ;
34
- const timespan = { endTimespan : jest . fn ( ) . mockResolvedValue ( { lhr : timespanLhr } ) } ;
35
- timespanModule . startTimespan . mockReset ( ) ;
36
- timespanModule . startTimespan . mockResolvedValue ( timespan ) ;
55
+ const timespanGatherResult = {
56
+ artifacts : {
57
+ URL : { finalUrl : 'https://www.example.com' } ,
58
+ GatherContext : { gatherMode : 'timespan' } ,
59
+ } ,
60
+ runnerOptions : {
61
+ config : { } ,
62
+ computedCache : new Map ( ) ,
63
+ } ,
64
+ } ;
65
+ const timespan = { endTimespanGather : jest . fn ( ) . mockResolvedValue ( timespanGatherResult ) } ;
66
+ timespanModule . startTimespanGather . mockReset ( ) ;
67
+ timespanModule . startTimespanGather . mockResolvedValue ( timespan ) ;
37
68
} ) ;
38
69
39
70
describe ( '.navigate()' , ( ) => {
@@ -53,11 +84,11 @@ describe('UserFlow', () => {
53
84
54
85
await flow . navigate ( 'https://example.com/3' ) ;
55
86
56
- expect ( navigationModule . navigation ) . toHaveBeenCalledTimes ( 3 ) ;
57
- expect ( flow . steps ) . toMatchObject ( [
58
- { name : 'My Step' , lhr : { finalUrl : 'https://www.example.com' } } ,
59
- { name : 'Navigation report (www.example.com/)' , lhr : { finalUrl : 'https://www.example.com' } } ,
60
- { name : 'Navigation report (www.example.com/)' , lhr : { finalUrl : 'https://www.example.com' } } ,
87
+ expect ( navigationModule . navigationGather ) . toHaveBeenCalledTimes ( 3 ) ;
88
+ expect ( flow . stepArtifacts ) . toMatchObject ( [
89
+ { name : 'My Step' } ,
90
+ { name : 'Navigation report (www.example.com/)' } ,
91
+ { name : 'Navigation report (www.example.com/)' } ,
61
92
] ) ;
62
93
} ) ;
63
94
@@ -77,8 +108,9 @@ describe('UserFlow', () => {
77
108
await flow . navigate ( 'https://example.com/4' , { configContext : configContextExplicit } ) ;
78
109
79
110
// Check that we have the property set.
80
- expect ( navigationModule . navigation ) . toHaveBeenCalledTimes ( 4 ) ;
81
- const [ [ , call1 ] , [ , call2 ] , [ , call3 ] , [ , call4 ] ] = navigationModule . navigation . mock . calls ;
111
+ expect ( navigationModule . navigationGather ) . toHaveBeenCalledTimes ( 4 ) ;
112
+ const [ [ , call1 ] , [ , call2 ] , [ , call3 ] , [ , call4 ] ] =
113
+ navigationModule . navigationGather . mock . calls ;
82
114
expect ( call1 ) . not . toHaveProperty ( 'configContext.settingsOverrides.disableStorageReset' ) ;
83
115
expect ( call2 ) . toHaveProperty ( 'configContext.settingsOverrides.disableStorageReset' ) ;
84
116
expect ( call3 ) . toHaveProperty ( 'configContext.settingsOverrides.disableStorageReset' ) ;
@@ -105,8 +137,8 @@ describe('UserFlow', () => {
105
137
await flow . navigate ( 'https://example.com/3' , { configContext : configContextExplicit } ) ;
106
138
107
139
// Check that we have the property set.
108
- expect ( navigationModule . navigation ) . toHaveBeenCalledTimes ( 3 ) ;
109
- const [ [ , call1 ] , [ , call2 ] , [ , call3 ] ] = navigationModule . navigation . mock . calls ;
140
+ expect ( navigationModule . navigationGather ) . toHaveBeenCalledTimes ( 3 ) ;
141
+ const [ [ , call1 ] , [ , call2 ] , [ , call3 ] ] = navigationModule . navigationGather . mock . calls ;
110
142
expect ( call1 ) . toHaveProperty ( 'configContext.skipAboutBlank' ) ;
111
143
expect ( call2 ) . toHaveProperty ( 'configContext.skipAboutBlank' ) ;
112
144
expect ( call3 ) . toHaveProperty ( 'configContext.skipAboutBlank' ) ;
@@ -136,10 +168,10 @@ describe('UserFlow', () => {
136
168
await flow . startTimespan ( ) ;
137
169
await flow . endTimespan ( ) ;
138
170
139
- expect ( timespanModule . startTimespan ) . toHaveBeenCalledTimes ( 2 ) ;
140
- expect ( flow . steps ) . toMatchObject ( [
141
- { name : 'My Timespan' , lhr : { finalUrl : 'https://www.example.com' } } ,
142
- { name : 'Timespan report (www.example.com/)' , lhr : { finalUrl : 'https://www.example.com' } } ,
171
+ expect ( timespanModule . startTimespanGather ) . toHaveBeenCalledTimes ( 2 ) ;
172
+ expect ( flow . stepArtifacts ) . toMatchObject ( [
173
+ { name : 'My Timespan' } ,
174
+ { name : 'Timespan report (www.example.com/)' } ,
143
175
] ) ;
144
176
} ) ;
145
177
} ) ;
@@ -164,11 +196,53 @@ describe('UserFlow', () => {
164
196
await flow . snapshot ( { stepName : 'My Snapshot' } ) ;
165
197
await flow . snapshot ( ) ;
166
198
167
- expect ( snapshotModule . snapshot ) . toHaveBeenCalledTimes ( 2 ) ;
168
- expect ( flow . steps ) . toMatchObject ( [
169
- { name : 'My Snapshot' , lhr : { finalUrl : 'https://www.example.com' } } ,
170
- { name : 'Snapshot report (www.example.com/)' , lhr : { finalUrl : 'https://www.example.com' } } ,
199
+ expect ( snapshotModule . snapshotGather ) . toHaveBeenCalledTimes ( 2 ) ;
200
+ expect ( flow . stepArtifacts ) . toMatchObject ( [
201
+ { name : 'My Snapshot' } ,
202
+ { name : 'Snapshot report (www.example.com/)' } ,
171
203
] ) ;
172
204
} ) ;
173
205
} ) ;
206
+
207
+ describe ( '.getFlowResult' , ( ) => {
208
+ it ( 'should throw if no flow steps have been run' , async ( ) => {
209
+ const flow = new UserFlow ( mockPage . asPage ( ) ) ;
210
+ const flowResultPromise = flow . createFlowResult ( ) ;
211
+ await expect ( flowResultPromise ) . rejects . toThrow ( / N e e d a t l e a s t o n e s t e p / ) ;
212
+ } ) ;
213
+
214
+ it ( 'should get flow result' , async ( ) => {
215
+ mockRunner . audit . mockImplementation ( artifacts => ( {
216
+ lhr : {
217
+ finalUrl : artifacts . URL . finalUrl ,
218
+ gatherMode : artifacts . GatherContext . gatherMode ,
219
+ } ,
220
+ } ) ) ;
221
+ const flow = new UserFlow ( mockPage . asPage ( ) ) ;
222
+
223
+ await flow . navigate ( 'https://www.example.com/' ) ;
224
+ await flow . startTimespan ( { stepName : 'My Timespan' } ) ;
225
+ await flow . endTimespan ( ) ;
226
+ await flow . snapshot ( { stepName : 'My Snapshot' } ) ;
227
+
228
+ const flowResult = await flow . createFlowResult ( ) ;
229
+ expect ( flowResult ) . toMatchObject ( {
230
+ steps : [
231
+ {
232
+ lhr : { finalUrl : 'https://www.example.com' , gatherMode : 'navigation' } ,
233
+ name : 'Navigation report (www.example.com/)' ,
234
+ } ,
235
+ {
236
+ lhr : { finalUrl : 'https://www.example.com' , gatherMode : 'timespan' } ,
237
+ name : 'My Timespan' ,
238
+ } ,
239
+ {
240
+ lhr : { finalUrl : 'https://www.example.com' , gatherMode : 'snapshot' } ,
241
+ name : 'My Snapshot' ,
242
+ } ,
243
+ ] ,
244
+ name : 'User flow (www.example.com)' ,
245
+ } ) ;
246
+ } ) ;
247
+ } ) ;
174
248
} ) ;
0 commit comments