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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ Options:
continuing [number] [default: 10000]
--settings The Lighthouse settings and flags to use when collecting
--numberOfRuns, -n The number of times to run Lighthouse. [number] [default: 3]
--maxAutodiscoverUrls The maximum number of pages to collect when using the staticDistDir
option with no specified URL. Disable this limit by setting to 0.
[number] [default: 5]
```

#### `method`
Expand Down
9 changes: 8 additions & 1 deletion packages/cli/src/collect/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ function buildCommand(yargs) {
default: 3,
type: 'number',
},
maxAutodiscoverUrls: {
description:
'The maximum number of pages to collect when using the staticDistDir option with no specified URLs. Disable this limit by setting to 0.',
default: 5,
type: 'number',
},
});
}

Expand Down Expand Up @@ -167,7 +173,8 @@ async function startServerAndDetermineUrls(options) {

const urls = urlsAsArray;
if (!urls.length) {
urls.push(...server.getAvailableUrls().slice(0, 5));
const maxNumberOfUrls = options.maxAutodiscoverUrls || Infinity;
urls.push(...server.getAvailableUrls().slice(0, maxNumberOfUrls));
}

if (!urls.length) {
Expand Down
36 changes: 0 additions & 36 deletions packages/cli/test/collect-static-dir-with-urls.test.js

This file was deleted.

111 changes: 111 additions & 0 deletions packages/cli/test/collect-static-dir.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* @license Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* 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.
*/
'use strict';

jest.retryTimes(3);

/* eslint-env jest */

const path = require('path');
const {runCLI} = require('./test-utils.js');

describe('Lighthouse CI collect CLI', () => {
describe('with URLs', () => {
const staticDistDir = path.join(__dirname, 'fixtures/collect-static-dir-with-urls');
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);
});

describe('with autodiscover limit', () => {
const staticDistDir = path.join(__dirname, 'fixtures/collect-static-dir-autodiscover-limit');
it('should collect a single page from static dir', async () => {
const {stdout, stderr, status} = await runCLI(
['collect', '-n=1', '--staticDistDir=./', '--maxAutodiscoverUrls=1'],
{
cwd: staticDistDir,
}
);
expect(stdout).toMatchInlineSnapshot(`
"Started a web server on port XXXX...
Running Lighthouse 1 time(s) on http://localhost:XXXX/board.html
Run #1...done.
Done running Lighthouse!
"
`);
expect(stderr).toMatchInlineSnapshot(`""`);
expect(status).toEqual(0);
}, 180000);

it('should collect all available pages from static dir', async () => {
const {stdout, stderr, status} = await runCLI(
['collect', '-n=1', '--staticDistDir=./', '--maxAutodiscoverUrls=0'],
{
cwd: staticDistDir,
}
);
expect(stdout).toMatchInlineSnapshot(`
"Started a web server on port XXXX...
Running Lighthouse 1 time(s) on http://localhost:XXXX/board.html
Run #1...done.
Running Lighthouse 1 time(s) on http://localhost:XXXX/checkout.html
Run #1...done.
Running Lighthouse 1 time(s) on http://localhost:XXXX/index.html
Run #1...done.
Running Lighthouse 1 time(s) on http://localhost:XXXX/jobs.html
Run #1...done.
Running Lighthouse 1 time(s) on http://localhost:XXXX/shop.html
Run #1...done.
Running Lighthouse 1 time(s) on http://localhost:XXXX/team.html
Run #1...done.
Done running Lighthouse!
"
`);
expect(stderr).toMatchInlineSnapshot(`""`);
expect(status).toEqual(0);
}, 180000);
});
describe('by default', () => {
const staticDistDir = path.join(__dirname, 'fixtures/collect-static-dir-autodiscover-limit');

it('should collect 5 pages from static dir', async () => {
const {stdout, stderr, status} = await runCLI(['collect', '-n=1', '--staticDistDir=./'], {
cwd: staticDistDir,
});
expect(stdout).toMatchInlineSnapshot(`
"Started a web server on port XXXX...
Running Lighthouse 1 time(s) on http://localhost:XXXX/board.html
Run #1...done.
Running Lighthouse 1 time(s) on http://localhost:XXXX/checkout.html
Run #1...done.
Running Lighthouse 1 time(s) on http://localhost:XXXX/index.html
Run #1...done.
Running Lighthouse 1 time(s) on http://localhost:XXXX/jobs.html
Run #1...done.
Running Lighthouse 1 time(s) on http://localhost:XXXX/shop.html
Run #1...done.
Done running Lighthouse!
"
`);
expect(stderr).toMatchInlineSnapshot(`""`);
expect(status).toEqual(0);
}, 180000);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>board test page for staticDistDir usage</title>
</head>
<body>
test
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>checkout test page for staticDistDir usage</title>
</head>
<body>
test
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>index test page for staticDistDir usage</title>
</head>
<body>
test
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jobs test page for staticDistDir usage</title>
</head>
<body>
test
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>shop test page for staticDistDir usage</title>
</head>
<body>
test
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>team test page for staticDistDir usage</title>
</head>
<body>
test
</body>
</html>
1 change: 1 addition & 0 deletions types/collect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ declare global {
headful: boolean;
additive: boolean;
settings?: LighthouseSettings;
maxAutodiscoverUrls?: number;
}
}
}
Expand Down