这是indexloc提供的服务,不要输入任何密码
Skip to content

Add more fixture files with Lighthouse data #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

ediamin
Copy link
Collaborator

@ediamin ediamin commented Feb 28, 2022

Fixes #6

Currently we have only one single fixture file for the https:\\amp-wp.org page. The goal of this PR is to add more fixture files so we can use them with --url flag.

This PR introduces two new binaries,

  1. generate-fixture: This will spin up a WP site to test against PageSpeed Insights API. It'll create/update a fixture file psi_local-wp_amp-page.json file in tests/fixtures directory.
  2. stop-server: It cleans up/destroys everything that setup by generate-fixture. This is helpful when we work in our local.

Prerequisite:

To make the action workable in GitHub, we need to setup two secrets:

  • PSI_API_KEY: The PageSpeed Insights API key,
  • NGROK_AUTH_TOKEN: ngrok auth token that can be found in ngrok dashboard.

To work in local

  • We need to setup a .env file that can be generated from the .env.example file.
  • mysql server.
  • WP CLI.
  • ngrok with auth token setup.

To-dos:

  • Build a script to create a WordPress site that is accessible to public so we can audit its pages with PageSpeed Insights API.
  • Use a test WP plugin to build a "worst possible site" that can trigger all warnings that Lighthouse has to offer.
  • Build a script to audit a URL via the PSI API and store the JSON result under the tests/fixtures folder, using the URL and the versions of both PSI API and the embedded Lighthouse audit.
  • Automate these processes with GitHub Actions workflow.

ref: #6 (comment)

@codecov-commenter
Copy link

codecov-commenter commented Mar 1, 2022

Codecov Report

Merging #22 (04789b4) into main (f01a864) will increase coverage by 1.84%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##               main      #22      +/-   ##
============================================
+ Coverage     61.25%   63.09%   +1.84%     
+ Complexity      340      338       -2     
============================================
  Files            50       50              
  Lines           831      794      -37     
============================================
- Hits            509      501       -8     
+ Misses          322      293      -29     
Flag Coverage Δ
php 63.09% <ø> (+1.84%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/PageSpeed/PageSpeedInsightsApi.php 70.00% <0.00%> (-2.73%) ⬇️
src/Cli/Command/Optimize.php 89.47% <0.00%> (-1.84%) ⬇️
src/Cli/Command/Analyze.php 0.00% <0.00%> (ø)
src/Cli/Command/PageSpeedInsights.php 0.00% <0.00%> (ø)
src/Engine/Exception/InvalidJsonFile.php 100.00% <0.00%> (ø)
src/Engine/ToolStack/ParallelToolStack.php 0.00% <0.00%> (ø)
src/Engine/Exception/FailedToProcessTimestamp.php 100.00% <0.00%> (ø)
src/Engine/StringStream.php 10.00% <0.00%> (+0.24%) ⬆️
src/Engine/Context.php 25.00% <0.00%> (+2.77%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f01a864...04789b4. Read the comment docs.

@ediamin ediamin requested a review from schlessera March 7, 2022 06:16
@ediamin ediamin marked this pull request as ready for review March 7, 2022 06:16
Comment on lines +102 to +104
- name: Check if there are changes
id: changes
run: echo ::set-output name=changed::$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to improve this specific step, otherwise there will always be changes, as the timestamp alone will already cause this to be triggered.

What about using jq to fetch the lighthouseVersion key, and only updating if that key has changed? It would mean storing the version somewhere, either in the name (which would require a smarter way of adding/removing the files) or as the contents of a separate file (which makes it easy to compare with a git diff against that singe file).

cd ../

# Generate the fixture file for the amp-page.
./bin/px psi --json --key $PSI_API_KEY $publicUrl/amp-page/ > ./tests/fixtures/psi_local-wp_amp-page.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simplify the check for changes, we could extract the lighthouseVersion here and store it in a psi_local-wp_amp-page.version file. Then the workflow can just git diff that file to decide whether a pull request needs to be changed.

@ediamin
Copy link
Collaborator Author

ediamin commented Mar 14, 2022

Updated the generate-fixture script to check the lighthouseVersion change. Now the fixture file will only update if lighthouseVersion are different in the API data and in the existing psi_local-wp_amp-page.json in the project.

@ediamin ediamin requested a review from schlessera March 14, 2022 11:54
@schlessera
Copy link
Collaborator

@ediamin That looks pretty good so far. How many audits are we triggering so far with the current site setup?

@ediamin
Copy link
Collaborator Author

ediamin commented Mar 15, 2022

@schlessera I've added a testing plugin which will simulate bad audit scores for the following,

cumulative-layout-shift
largest-contentful-paint
first-contentful-paint
speed-index
unminified-javascript
unminified-css
uses-rel-preconnect

in addition to these, I've found that overall performance stays under 60 in multiple tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more fixture files with Lighthouse data
3 participants