Skip to content
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

Add flag to set the limit of files to be tested. #434

Merged
merged 16 commits into from
Aug 28, 2020
Merged

Add flag to set the limit of files to be tested. #434

merged 16 commits into from
Aug 28, 2020

Conversation

chronark
Copy link
Contributor

This would fix #95

Right now lhci will only test 5 files.
With this PR you can specify the limit to any number or even remove it.

Example:

lhci autorun                            -> Will test 5 files
lhci autorun --collect.numberOfFiles=10 -> Will test 10 files
lhci autorun --collect.numberOfFiles=0  -> Will test all files

Default is still at 5.
A value less or equal than 0 will disable the limit alltogether.

I didn't write any tests yet, because I never wrote CLI tests before, but I'll get around to it soon.
I just wanted to create a PR first to see if you would even consider adding it.

Example:
lhci autorun --collect.numberOfFiles=10

Default is still at 5.
A value less or equal than 0 will disable the limit alltogether.
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@chronark
Copy link
Contributor Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

thanks very much @chronark! great job hunting down the correct places to add all this :)

as for a test case, you can use

it('should collect a static dir with explicit URLs', async () => {
const {stdout, stderr, status} = await runCLI(
['collect', '-n=1', '--staticDistDir=./', '--url=/child/grandchild.html'],
{
cwd: staticDistDir,
}
);
expect(stdout).toMatchInlineSnapshot(`
"Started a web server on port XXXX...
Running Lighthouse 1 time(s) on http://localhost:XXXX/child/grandchild.html
Run #1...done.
Done running Lighthouse!
"
`);
expect(stderr).toMatchInlineSnapshot(`""`);
expect(status).toEqual(0);
}, 180000);

as a model, you'll just want to adjust the arguments to not provide a URL, use the collect-static-dir-without-urls fixture dir instead, and then use your flag to limit the URLs to 1

packages/cli/src/collect/collect.js Outdated Show resolved Hide resolved
packages/cli/src/collect/collect.js Outdated Show resolved Hide resolved
packages/cli/src/collect/collect.js Outdated Show resolved Hide resolved
packages/cli/src/collect/collect.js Outdated Show resolved Hide resolved
chronark and others added 13 commits August 28, 2020 09:42
Co-authored-by: Patrick Hulce <[email protected]>
To really test more edge cases I added a new folder with 6 pages, this
way we can test the default limit of 5 as well disabling the limit.

First I tried to do it in the same fixture folder but that obviously
broke other tests because they were pickng up the wrong pages.
@chronark
Copy link
Contributor Author

Alright here we go. Thank you for guiding me @patrickhulce and for your suggestions, I learned something new :)

I added some more tests, so we are testing if it correctly

  • limits it to a number
  • disables the limit
  • defaults to 5

I had to create a new fixture folder but I hope that is fine.

I also added the flag to the configuration.md

@chronark chronark marked this pull request as ready for review August 28, 2020 09:31
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

this is great thanks @chronark! 🎉 💯

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

Successfully merging this pull request may close these issues.

Only files in staticDistDir root are collected
3 participants