lighthouse 9.5.0-dev.20221020 → 9.5.0-dev.20221022

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/user-flow.js CHANGED
@@ -11,6 +11,7 @@ import {navigationGather} from './gather/navigation-runner.js';
11
11
  import {Runner} from './runner.js';
12
12
  import {initializeConfig} from './config/config.js';
13
13
  import {getFormatted} from '../shared/localization/format.js';
14
+ import {mergeConfigFragment, deepClone} from './config/config-helpers.js';
14
15
  import * as i18n from './lib/i18n/i18n.js';
15
16
 
16
17
  /** @typedef {WeakMap<LH.UserFlow.GatherStep, LH.Gatherer.FRGatherResult['runnerOptions']>} GatherStepRunnerOptions */
@@ -67,30 +68,39 @@ class UserFlow {
67
68
  }
68
69
 
69
70
  /**
70
- * @param {LH.UserFlow.StepFlags} [flags]
71
+ * @param {LH.UserFlow.StepFlags|undefined} flags
72
+ * @return {LH.UserFlow.StepFlags|undefined}
73
+ */
74
+ _getNextFlags(flags) {
75
+ const clonedFlowFlags = this._options?.flags && deepClone(this._options?.flags);
76
+ if (!flags) return clonedFlowFlags;
77
+ return mergeConfigFragment(clonedFlowFlags || {}, flags, true);
78
+ }
79
+
80
+ /**
81
+ * @param {LH.UserFlow.StepFlags|undefined} flags
71
82
  * @return {LH.UserFlow.StepFlags}
72
83
  */
73
84
  _getNextNavigationFlags(flags) {
74
- const newStepFlags = {...flags};
85
+ const nextFlags = this._getNextFlags(flags) || {};
75
86
 
76
- if (newStepFlags.skipAboutBlank === undefined) {
77
- newStepFlags.skipAboutBlank = true;
87
+ if (nextFlags.skipAboutBlank === undefined) {
88
+ nextFlags.skipAboutBlank = true;
78
89
  }
79
90
 
80
91
  // On repeat navigations, we want to disable storage reset by default (i.e. it's not a cold load).
81
92
  const isSubsequentNavigation = this._gatherSteps
82
93
  .some(step => step.artifacts.GatherContext.gatherMode === 'navigation');
83
94
  if (isSubsequentNavigation) {
84
- if (newStepFlags.disableStorageReset === undefined) {
85
- newStepFlags.disableStorageReset = true;
95
+ if (nextFlags.disableStorageReset === undefined) {
96
+ nextFlags.disableStorageReset = true;
86
97
  }
87
98
  }
88
99
 
89
- return newStepFlags;
100
+ return nextFlags;
90
101
  }
91
102
 
92
103
  /**
93
- *
94
104
  * @param {LH.Gatherer.FRGatherResult} gatherResult
95
105
  * @param {LH.UserFlow.StepFlags} [flags]
96
106
  */
@@ -111,13 +121,13 @@ class UserFlow {
111
121
  if (this.currentTimespan) throw new Error('Timespan already in progress');
112
122
  if (this.currentNavigation) throw new Error('Navigation already in progress');
113
123
 
114
- const newStepFlags = this._getNextNavigationFlags(flags);
124
+ const nextFlags = this._getNextNavigationFlags(flags);
115
125
  const gatherResult = await navigationGather(this._page, requestor, {
116
126
  config: this._options?.config,
117
- flags: newStepFlags,
127
+ flags: nextFlags,
118
128
  });
119
129
 
120
- this._addGatherStep(gatherResult, newStepFlags);
130
+ this._addGatherStep(gatherResult, nextFlags);
121
131
  }
122
132
 
123
133
  /**
@@ -179,11 +189,13 @@ class UserFlow {
179
189
  if (this.currentTimespan) throw new Error('Timespan already in progress');
180
190
  if (this.currentNavigation) throw new Error('Navigation already in progress');
181
191
 
192
+ const nextFlags = this._getNextFlags(flags);
193
+
182
194
  const timespan = await startTimespanGather(this._page, {
183
195
  config: this._options?.config,
184
- flags: flags,
196
+ flags: nextFlags,
185
197
  });
186
- this.currentTimespan = {timespan, flags};
198
+ this.currentTimespan = {timespan, flags: nextFlags};
187
199
  }
188
200
 
189
201
  async endTimespan() {
@@ -204,12 +216,14 @@ class UserFlow {
204
216
  if (this.currentTimespan) throw new Error('Timespan already in progress');
205
217
  if (this.currentNavigation) throw new Error('Navigation already in progress');
206
218
 
219
+ const nextFlags = this._getNextFlags(flags);
220
+
207
221
  const gatherResult = await snapshotGather(this._page, {
208
222
  config: this._options?.config,
209
- flags: flags,
223
+ flags: nextFlags,
210
224
  });
211
225
 
212
- this._addGatherStep(gatherResult, flags);
226
+ this._addGatherStep(gatherResult, nextFlags);
213
227
  }
214
228
 
215
229
  /**
@@ -16,7 +16,7 @@ import {Header} from './header';
16
16
  import {I18nProvider} from './i18n/i18n';
17
17
  import {Styles} from './wrappers/styles';
18
18
 
19
- function getAnchorElement(hashState: LH.FlowResult.HashState|null) {
19
+ function getAnchorElement(hashState: LH.HashState|null) {
20
20
  if (!hashState || !hashState.anchor) return null;
21
21
  return document.getElementById(hashState.anchor);
22
22
  }
@@ -29,7 +29,7 @@ const HeaderThumbnail: FunctionComponent<{
29
29
  );
30
30
  };
31
31
 
32
- export const Header: FunctionComponent<{hashState: LH.FlowResult.HashState}> =
32
+ export const Header: FunctionComponent<{hashState: LH.HashState}> =
33
33
  ({hashState}) => {
34
34
  const flowResult = useFlowResult();
35
35
  const {index} = hashState;
@@ -97,7 +97,7 @@ function useHashParams(...params: string[]) {
97
97
  return paramValues;
98
98
  }
99
99
 
100
- function useHashState(): LH.FlowResult.HashState|null {
100
+ function useHashState(): LH.HashState|null {
101
101
  const flowResult = useFlowResult();
102
102
  const [indexString, anchor] = useHashParams('index', 'anchor');
103
103
 
@@ -29,7 +29,7 @@ function convertAnchor(link: HTMLAnchorElement, index: number) {
29
29
  link.replaceWith(newLink);
30
30
  }
31
31
 
32
- export const Report: FunctionComponent<{hashState: LH.FlowResult.HashState}> =
32
+ export const Report: FunctionComponent<{hashState: LH.HashState}> =
33
33
  ({hashState}) => {
34
34
  const ref = useExternalRenderer<HTMLDivElement>(() => {
35
35
  return renderReport(hashState.currentLhr, {
@@ -4,7 +4,7 @@
4
4
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5
5
  */
6
6
 
7
- import FlowResult_ from '../../types/lhr/flow';
7
+ import FlowResult_ from '../../types/lhr/flow-result';
8
8
  import * as Settings from '../../types/lhr/settings';
9
9
 
10
10
  // Import to augment querySelector/querySelectorAll with stricter type checking.
@@ -20,11 +20,18 @@ declare global {
20
20
  // Expose global types in LH namespace.
21
21
  module LH {
22
22
  export type ConfigSettings = Settings.ConfigSettings;
23
+
23
24
  export interface FlowReportOptions {
24
25
  getReportHtml?: (flowResult: FlowResult_) => string;
25
26
  saveAsGist?: (flowResult: FlowResult_) => void;
26
27
  }
27
28
 
29
+ export interface HashState {
30
+ currentLhr: Result;
31
+ index: number;
32
+ anchor: string|null;
33
+ }
34
+
28
35
  export import FlowResult = FlowResult_;
29
36
  }
30
37
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lighthouse",
3
3
  "type": "module",
4
- "version": "9.5.0-dev.20221020",
4
+ "version": "9.5.0-dev.20221022",
5
5
  "description": "Automated auditing, performance metrics, and best practices for the web.",
6
6
  "main": "./core/index.js",
7
7
  "bin": {
@@ -8,7 +8,7 @@
8
8
  import {reportAssets} from './report-assets.js';
9
9
 
10
10
  /** @typedef {import('../../types/lhr/lhr').default} LHResult */
11
- /** @typedef {import('../../types/lhr/flow').default} FlowResult */
11
+ /** @typedef {import('../../types/lhr/flow-result').default} FlowResult */
12
12
 
13
13
  class ReportGenerator {
14
14
  /**
@@ -6,10 +6,10 @@
6
6
 
7
7
  import {IcuMessage as IcuMessage_} from '../../types/lhr/i18n';
8
8
  import LHResult from '../../types/lhr/lhr';
9
- import FlowResult_ from '../../types/lhr/flow';
9
+ import FlowResult_ from '../../types/lhr/flow-result';
10
10
 
11
11
  import {Locale as Locale_} from '../../types/lhr/settings';
12
-
12
+
13
13
  declare global {
14
14
  // Expose global types in LH namespace.
15
15
  module LH {
@@ -16,7 +16,7 @@ import Gatherer_ from './gatherer';
16
16
  import * as I18n from './lhr/i18n';
17
17
  import {LighthouseError as LighthouseError_} from '../core/lib/lh-error.js';
18
18
  import LHResult from './lhr/lhr';
19
- import FlowResult_ from './lhr/flow';
19
+ import FlowResult_ from './lhr/flow-result';
20
20
  import Protocol_ from './protocol';
21
21
  import * as Settings from './lhr/settings';
22
22
  import Treemap_ from './lhr/treemap';
@@ -8,15 +8,11 @@ import Result from './lhr';
8
8
 
9
9
  declare module FlowResult {
10
10
  interface Step {
11
+ /** Lighthouse report for this flow step. */
11
12
  lhr: Result;
13
+ /** Display name of this flow step. */
12
14
  name: string;
13
15
  }
14
-
15
- interface HashState {
16
- currentLhr: Result;
17
- index: number;
18
- anchor: string|null;
19
- }
20
16
  }
21
17
 
22
18
  /**
@@ -25,7 +21,7 @@ declare module FlowResult {
25
21
  interface FlowResult {
26
22
  /** Ordered list of flow steps, each corresponding to a navigation, timespan, or snapshot. */
27
23
  steps: FlowResult.Step[];
28
- /** Name given to this user flow. */
24
+ /** Display name of this user flow. */
29
25
  name: string;
30
26
  }
31
27
 
@@ -7,11 +7,16 @@ declare module UserFlow {
7
7
  }
8
8
 
9
9
  export interface Options {
10
- config: LH.Config.Json;
10
+ /** Config to use for each flow step. */
11
+ config?: LH.Config.Json;
12
+ /** Base flags to use for each flow step. Step specific flags will override these flags. */
13
+ flags?: LH.Flags;
14
+ /** Display name for this user flow. */
11
15
  name?: string;
12
16
  }
13
17
 
14
18
  export interface StepFlags extends LH.Flags {
19
+ /** Display name for this flow step. */
15
20
  name?: string;
16
21
  }
17
22
 
@@ -21,6 +26,6 @@ declare module UserFlow {
21
26
  }
22
27
  }
23
28
 
24
- type UserFlow = typeof UserFlow_;
29
+ type UserFlow = InstanceType<typeof UserFlow_>;
25
30
 
26
31
  export default UserFlow;