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

tests(fr): add fraggle rock smoke tests #12834

Merged
merged 3 commits into from
Aug 3, 2021
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
23 changes: 23 additions & 0 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,29 @@ jobs:
# Fail if any changes were written to source files.
- run: git diff --exit-code

smoke-fr:
runs-on: ubuntu-latest
name: Fraggle Rock

steps:
- name: git clone
uses: actions/checkout@v2

- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x

- run: yarn install --frozen-lockfile --network-timeout 1000000
- run: yarn build-report

- run: sudo apt-get install xvfb
- name: yarn smoke --fraggle-rock
run: xvfb-run --auto-servernum yarn smoke --debug --fraggle-rock -j=1 --retries=2 a11y lantern seo-passing seo-failing csp
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose the burndown in the inverse of this smoke list? It'd be nice to use --invert here and list just the tests that are failing (the ones we need to fix).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suppose the burndown in the inverse of this smoke list? It'd be nice to use --invert here and list just the tests that are failing (the ones we need to fix).

Great call, I'll do that when the list is a smidge shorter :D


# Fail if any changes were written to source files.
- run: git diff --exit-code

smoke-bundle:
runs-on: ubuntu-latest
name: Bundled Lighthouse
Expand Down
14 changes: 13 additions & 1 deletion lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ async function begin() {
default: false,
describe: 'Save test artifacts and output verbose logs',
},
'fraggle-rock': {
type: 'boolean',
default: false,
describe: 'Use the new Fraggle Rock runner',
},
'jobs': {
type: 'number',
alias: 'j',
Expand Down Expand Up @@ -191,7 +196,14 @@ async function begin() {
}

const prunedTestDefns = pruneExpectedNetworkRequests(testDefns, takeNetworkRequestUrls);
const options = {jobs, retries, isDebug: argv.debug, lighthouseRunner, takeNetworkRequestUrls};
const options = {
jobs,
retries,
isDebug: argv.debug,
useFraggleRock: argv.fraggleRock,
lighthouseRunner,
takeNetworkRequestUrls,
};

isPassing = (await runSmokehouse(prunedTestDefns, options)).success;
} finally {
Expand Down
28 changes: 24 additions & 4 deletions lighthouse-cli/test/smokehouse/lighthouse-runners/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,42 @@ const ChildProcessError = require('../lib/child-process-error.js');
* Launch Chrome and do a full Lighthouse run via the Lighthouse CLI.
* @param {string} url
* @param {LH.Config.Json=} configJson
* @param {{isDebug?: boolean}=} testRunnerOptions
* @param {{isDebug?: boolean, useFraggleRock?: boolean}=} testRunnerOptions
* @return {Promise<{lhr: LH.Result, artifacts: LH.Artifacts, log: string}>}
*/
async function runLighthouse(url, configJson, testRunnerOptions = {}) {
const tmpPath = await fs.mkdtemp(`${os.tmpdir()}/smokehouse-`);

const {isDebug} = testRunnerOptions;
return internalRun(url, tmpPath, configJson, isDebug)
return internalRun(url, tmpPath, configJson, testRunnerOptions)
// Wait for internalRun() before removing scratch directory.
.finally(() => !isDebug && fs.rmdir(tmpPath, {recursive: true}));
}

/**
* @param {LH.Config.Json=} configJson
* @return {LH.Config.Json|undefined}
*/
function convertToFraggleRockConfig(configJson) {
if (!configJson) return configJson;
if (!configJson.passes) return configJson;

return {
...configJson,
navigations: configJson.passes.map(pass => ({...pass, id: pass.passName})),
};
}

/**
* Internal runner.
* @param {string} url
* @param {string} tmpPath
* @param {LH.Config.Json=} configJson
* @param {boolean=} isDebug
* @param {{isDebug?: boolean, useFraggleRock?: boolean}=} options
* @return {Promise<{lhr: LH.Result, artifacts: LH.Artifacts, log: string}>}
*/
async function internalRun(url, tmpPath, configJson, isDebug) {
async function internalRun(url, tmpPath, configJson, options) {
const {isDebug = false, useFraggleRock = false} = options || {};
const localConsole = new LocalConsole();

const outputPath = `${tmpPath}/smokehouse.report.json`;
Expand All @@ -64,6 +79,11 @@ async function internalRun(url, tmpPath, configJson, isDebug) {
'--port=0',
];

if (useFraggleRock) {
args.push('--fraggle-rock');
configJson = convertToFraggleRockConfig(configJson);
}

// Config can be optionally provided.
if (configJson) {
const configPath = `${tmpPath}/config.json`;
Expand Down
9 changes: 5 additions & 4 deletions lighthouse-cli/test/smokehouse/smokehouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const DEFAULT_RETRIES = 0;
async function runSmokehouse(smokeTestDefns, smokehouseOptions) {
const {
isDebug,
useFraggleRock,
jobs = DEFAULT_CONCURRENT_RUNS,
retries = DEFAULT_RETRIES,
lighthouseRunner = cliLighthouseRunner,
Expand All @@ -52,7 +53,7 @@ async function runSmokehouse(smokeTestDefns, smokehouseOptions) {
// Run each testDefn in parallel based on the concurrencyLimit.
const concurrentMapper = new ConcurrentMapper();

const testOptions = {isDebug, retries, lighthouseRunner, takeNetworkRequestUrls};
const testOptions = {isDebug, useFraggleRock, retries, lighthouseRunner, takeNetworkRequestUrls};
const smokePromises = smokeTestDefns.map(testDefn => {
// If defn is set to `runSerially`, we'll run it in succession with other tests, not parallel.
const concurrency = testDefn.runSerially ? 1 : jobs;
Expand Down Expand Up @@ -108,12 +109,12 @@ function purpleify(str) {
/**
* Run Lighthouse in the selected runner.
* @param {Smokehouse.TestDfn} smokeTestDefn
* @param {{isDebug?: boolean, retries: number, lighthouseRunner: Smokehouse.LighthouseRunner, takeNetworkRequestUrls?: () => string[]}} testOptions
* @param {{isDebug?: boolean, useFraggleRock?: boolean, retries: number, lighthouseRunner: Smokehouse.LighthouseRunner, takeNetworkRequestUrls?: () => string[]}} testOptions
* @return {Promise<SmokehouseResult>}
*/
async function runSmokeTest(smokeTestDefn, testOptions) {
const {id, config: configJson, expectations} = smokeTestDefn;
const {lighthouseRunner, retries, isDebug, takeNetworkRequestUrls} = testOptions;
const {lighthouseRunner, retries, isDebug, useFraggleRock, takeNetworkRequestUrls} = testOptions;
const requestedUrl = expectations.lhr.requestedUrl;

console.log(`${purpleify(id)} smoketest starting…`);
Expand All @@ -131,7 +132,7 @@ async function runSmokeTest(smokeTestDefn, testOptions) {
// Run Lighthouse.
try {
result = {
...await lighthouseRunner(requestedUrl, configJson, {isDebug}),
...await lighthouseRunner(requestedUrl, configJson, {isDebug, useFraggleRock}),
networkRequests: takeNetworkRequestUrls ? takeNetworkRequestUrls() : undefined,
};
} catch (e) {
Expand Down
11 changes: 8 additions & 3 deletions lighthouse-core/fraggle-rock/config/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const baseArtifactKeys = Object.keys(baseArtifactKeySource);
// Keep these audits unless they are *directly* skipped with `skipAudits`.
const filterResistantAuditIds = ['full-page-screenshot'];

// Some artifacts are used by the report for additional information.
// Always run these artifacts even if audits do not request them.
const filterResistantArtifactIds = ['HostUserAgent', 'HostFormFactor', 'Stacks', 'GatherContext'];

/**
* Returns the set of audit IDs used in the list of categories.
* If `onlyCategories` is not set, this function returns the list of all audit IDs across all
Expand Down Expand Up @@ -56,9 +60,10 @@ function filterArtifactsByAvailableAudits(artifacts, audits) {
const artifactsById = new Map(artifacts.map(artifact => [artifact.id, artifact]));

/** @type {Set<string>} */
const artifactIdsToKeep = new Set(
audits.flatMap(audit => audit.implementation.meta.requiredArtifacts)
);
const artifactIdsToKeep = new Set([
...filterResistantArtifactIds,
...audits.flatMap(audit => audit.implementation.meta.requiredArtifacts),
]);

// Keep all artifacts in the dependency tree of required artifacts.
// Iterate through all kept artifacts, adding their dependencies along the way, until the set does not change.
Expand Down
4 changes: 3 additions & 1 deletion types/smokehouse.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@
{expectations: Smokehouse.ExpectedRunnerResult | Array<Smokehouse.ExpectedRunnerResult>}

export type LighthouseRunner =
(url: string, configJson?: LH.Config.Json, runnerOptions?: {isDebug?: boolean}) => Promise<{lhr: LH.Result, artifacts: LH.Artifacts, log: string}>;
(url: string, configJson?: LH.Config.Json, runnerOptions?: {isDebug?: boolean; useFraggleRock?: boolean}) => Promise<{lhr: LH.Result, artifacts: LH.Artifacts, log: string}>;

export interface SmokehouseOptions {
/** If true, performs extra logging from the test runs. */
isDebug?: boolean;
/** If true, uses the new Fraggle Rock runner. */
useFraggleRock?: boolean;
/** Manually set the number of jobs to run at once. `1` runs all tests serially. */
jobs?: number;
/** The number of times to retry failing tests before accepting. Defaults to 0. */
Expand Down