0.20.8 • Published 14 days ago

@push-based/user-flow v0.20.8

Weekly downloads
-
License
MIT
Repository
github
Last release
14 days ago

@push-based/user-flow

Runtime performance measurements done right, with Lighthouse user flows!

npm


This is a library & CLI to organize and run Lighthouse user flows in an organized and scalable way 🛸 with CI automation in place


What is it?

A CLI tool to measure performance continuously and also integrate it into your CI. It provides lot's of DX features, nice commands with rich arguments and integration with the latest dev tooling.

Why to use it?

It will enable you to measure bootstrap as well as runtime performance with minimum effort, speed up your performance test development and reduced the needed code and configuration to a minimum.

user-flow-code-reduction

In addition, it is always up-to-date with the latest Chrome DevTools features.

Benefits

Install

Run npm i @push-based/user-flow --save-dev or yarn add @push-based/user-flow --dev to install the library.

After that you can run:
user-flow --helpor user-flow --help

Run without install

You can also use npx to run it in e.g. the CI setup: npx @push-based/user-flow --help

Quick Start

As the CLI needs a npm project to run in we explain 2 common things, using the package in an existing project and using it in a fresh project. Both ways require a node and npm project setup to install user-flow and folders to store the reports and test files.

  1. have node v14.X.X installed
    run node -v and npm -v to check it.

To start from scratch read setup an empty project

Set up and run user flows in an existing npm project

In this chapter we will learn how to install and configure user flows, as well as create a first example test and see the resulting performance report.

  1. Install:
npm i @push-based/user-flow --save-dev
  1. Set up the .user-flowrc.json config file

Run

npx @push-based/user-flow init

or if you already installed it,

npx user-flow init

in the console and accept the default value for every question.

Set up user-flow in existing project gif

This results in the following file:

./.user-flowrc.json

{
  "collect": {
    "url": "https://coffee-cart.netlify.app/",
    "ufPath": "./user-flows"
  },
  "persist": { "outPath": "./measures", "format": ["html"] }
}
  1. The CLI automatically creates an example user-flow. (./user-flows/basic-navigation.uf.ts)

It is a simple navigation measurement to start from.

./basic-navigation.uf.ts

import {
  UserFlowInteractionsFn,
  UserFlowContext,
  UserFlowProvider
} from '@push-based/user-flow';

// Your custom interactions with the page 
const interactions: UserFlowInteractionsFn = async (ctx: UserFlowContext): Promise<any> => {
  const { page, flow, browser, collectOptions } = ctx;
  const { url } = collectOptions;

  // Navigate to URL
  await flow.navigate(url, {
    stepName: `Navigate to ${url}`,
  });

};

const userFlowProvider: UserFlowProvider = {
  flowOptions: {name: 'Order Coffee'},
  interactions
};

module.exports = userFlowProvider;
  1. Run CLI You can directly run the cli command. The typescript files will get resolved and compiled live.

npx user-flow collect or just npx user-flow as collect is the default.

This will execute the user flow and opens the HTML report in the browser:

For more information on how to write user-flows read in the Writing user flows for the CLI section.

Optionally you can pass params to overwrite the values form .user-flowrc.ts in the file directly or over the CLI:

npx user-flow --ufPath=./user-flows-new --outPath=./user-flows-reports --url=https://localhost:4200

🤓 DX Tip:
For a faster development process you can use the --dryRun option to skip measurement and perform the interactions only
This is a multitude faster e.g. 3s vs 53s for a simple 2 step flow with navigation

CLI

You can read more about tricks and DX the general CLI features in our docs.

Global Options

OptionTypeDefaultDescription
--help, -hbooleanundefinedShow help
--versionbooleanundefinedShow version number of cli
--rcPath, -pstring./user-flowrc.jsonPath to user-flow.config.json. e.g. ./user-flowrc.json
--verbose, -vbooleanundefinedRun with verbose logging
--interactive -ibooleantrue (false in CI mode)When false questions are skipped with the values from the suggestions. This is useful for CI integrations.

Commands

* command

Run the default command over:
@npx @push-based/user-flow [options]

Description:
The default command forwards all options to the collect command.

init command

Run command over:
@npx @push-based/user-flow init [options]

Description:
This command helps you to set up a .user-flowrc.json and asks for input over CLI prompts.

OptionTypeDefaultDescription
-h, --generateFlowbooleann/aGenerate basic user-flow file under ufPath
-g, --generateGhWorkflowbooleann/aGenerate user-flow.yml file under .github/workflows
-x, --generateBudgetsbooleann/aGenerate budget.json file under the current working directury
--lhrstringn/aUsed together with --generateBudgets. Path to lighthouse report for initial budget

As a result we get a .user-flowrc.json and an example flow if answered with yes.

🤓 DX Tip: Set up user flows in a sub directory:
npx @push-based/user-flow init --rcPath ./path/to/project/.user-flowrc.json

collect command

Run command over:
@npx @push-based/user-flow collect [options] or @npx @push-based/user-flow [options] as it is the default command.

Description:
This command executes a set of user-flow definitions against the target URL and saves the output.

OptionTypeDefaultDescription
-t, --urlstringn/aURL to analyze
-u, --ufPathstring./user-flowsPath to user-flow file or folder containing user-flow files to run. (*.uf.ts or*.uf.js)
-c, --configPathstringn/aPath to the lighthouse config.json file
-b, --budgetPathstringn/aPath to the lighthouse budget.json file
-s, --serveCommandstringn/aRuns a npm script to serve the target app. This has to be used in combination with --awaitServeStdout
-a, --awaitServeStdoutstring.user-flowrc settingWaits for stdout from the serve command to start collecting user-flows
-f, --formatstringhtml, json settingFormat of the creates reports ( html, json, md, stdout)
-o, --outPathstring./measuresoutput folder for the user-flow reports
-e, --openReportbooleantrueOpens file automatically after the user-flow is captured
-d, --dryRunbooleanfalseWhen true the user-flow test will get executed without measures (for fast development)

💡 Pro Tip: CLI arguments that accept multiple values can be set by using the param multiple times in a row:

As an example we could apply two different formats as output for the collect command: npx user-flow collect --format=json --format=md

Configuration

The CLI supports the official user-flow/lighthouse configuration.

Details on how to work with configurations can be found in the configuratin section.

Writing user flows for the CLI

You can think of user flows as front end e2e tests which measures performance related information during the test.

Basic user flows

Write basic user flows leveraging all 3 measurement modes of lighthouse.

User flow measurement modes

IconModeMeasurePerformanceAccessibilityBest PracticesSEOPWA
user-flow_navigation-iconNavigationPage load100% / 30100% / 30100% / 30100% / 30✔ / 7
user-flow_timespan-iconTimespanUser Interaction10 / 107 / 7
user-flow_snapshot-iconSnapshotCurrent page state4 / 416 / 165 / 59 / 9

When you execute and open the user-flow report you will see the measurement modes also visualized there.

user-flow--example

Advanced architecture

Organizing testing logic is an art. If you don't own that knowledge, the amount of low-level code get's a night mare to maintain in bigger projects...

This is the reason we introduced UFO's! Organize clutter code 👽 in developer friendly shells 🛸

user-flow--advanced-architecture

See ufo-architecture for more details.

Working with DevTools Recorder exports

Chrome DevTools provides a feature to help with record and export user interactions. This can replace any handwritten code and organizes interactions in a JSON structure. user-flow--replay-scripts

This library provides a way to replay and enrich those interactions over the CLI.

See recorder-exports for more details.

Performance Budgets

Implementing performance improvements without breaking something is hard.
Even harder is it, to keep it that way. 🔒

img-budgets-mode-support

Automatically create budgets with:
npx user-flow init --generateBudgets
Automatically create budgets from an existing lhr with:
npx user-flow init --generateBudgets --lhr path/to/lhr.json

See performance-budgets for more details.

GitHub workflow integration of lighthouse user flows in your PR

With just a few steps you can run your user flows in as a GitHub workflow to enrich your PR's with report summaries as comments.

Automatically create a workflow with:
npx user-flow init --generateGhWorkflow

user-flow-gh-action-cover

See github-workflow-integration for more details.

Nx workspace integration of lighthouse user flows as nx-plugin

With just a few steps you can run your user flows in as a Nx workspace to enrich your DX with a nx-plugin.

Automatically generate/execute/migrate with user-flow-nx-plugin:

  • nx g @push-based/user-flow-nx-plugin:install
  • nx g @push-based/user-flow-nx-plugin:target e2e

See user-flow-nx-plugin for more details.

Examples

Resources


made with ❤ by push-based.io

0.20.8

14 days ago

0.20.7

2 months ago

0.20.6

2 months ago

0.20.5

2 months ago

0.20.4

2 months ago

0.20.3

2 months ago

0.20.2

6 months ago

0.20.1

11 months ago

0.20.0

11 months ago

0.19.3

11 months ago

0.19.0

1 year ago

0.19.1

1 year ago

0.19.2

1 year ago

0.17.0

1 year ago

0.17.1

1 year ago

0.18.1

1 year ago

0.18.2

1 year ago

0.18.3

1 year ago

0.18.4

1 year ago

0.18.5

1 year ago

0.18.6

1 year ago

0.14.0

1 year ago

0.14.1

1 year ago

0.18.0

1 year ago

0.15.0

1 year ago

0.13.16

1 year ago

0.13.15

1 year ago

0.13.14

1 year ago

0.13.13

1 year ago

0.13.19

1 year ago

0.13.18

1 year ago

0.13.17

1 year ago

0.16.3

1 year ago

0.16.0

1 year ago

0.16.1

1 year ago

0.16.2

1 year ago

0.13.6

1 year ago

0.13.7

1 year ago

0.13.8

1 year ago

0.13.9

1 year ago

0.13.3

1 year ago

0.13.4

1 year ago

0.13.5

1 year ago

0.13.12

1 year ago

0.13.11

1 year ago

0.13.10

1 year ago

0.8.5

2 years ago

0.8.4

2 years ago

0.8.7

2 years ago

0.8.6

2 years ago

0.11.0

1 year ago

0.11.1

1 year ago

0.13.0

1 year ago

0.13.1

1 year ago

0.13.2

1 year ago

0.10.31

1 year ago

0.10.36

1 year ago

0.12.0

1 year ago

0.10.37

1 year ago

0.10.38

1 year ago

0.10.39

1 year ago

0.10.32

1 year ago

0.10.33

1 year ago

0.10.34

1 year ago

0.10.35

1 year ago

0.10.40

1 year ago

0.10.41

1 year ago

0.10.42

1 year ago

0.8.1

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

0.10.43

1 year ago

0.10.44

1 year ago

0.10.45

1 year ago

0.7.8

2 years ago

0.8.0

2 years ago

0.7.6

2 years ago

0.7.5

2 years ago

0.7.7

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.7

2 years ago

0.6.6

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.5.3

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.6.1

2 years ago

0.5.2

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.4.2

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.1.2

2 years ago

0.2.0

2 years ago

0.2.3

2 years ago

0.1.4

2 years ago

0.3.1

2 years ago

0.2.2

2 years ago

0.1.3

2 years ago

0.2.4

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago