-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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(smoke): convert to single LH run per test #12818
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @license Copyright 2021 The Lighthouse Authors. 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'; | ||
|
||
/** | ||
* COMPAT: update from the old TestDefn format (array of `expectations` per | ||
* definition) to the new format (single `expectations` per def), doing our best | ||
* generating some unique IDs. | ||
* TODO: remove in Lighthouse 9+ once PubAds (and others?) are updated. | ||
* @see https://github.com/GoogleChrome/lighthouse/issues/11950 | ||
* @param {ReadonlyArray<Smokehouse.BackCompatTestDefn>} allTestDefns | ||
* @return {Array<Smokehouse.TestDfn>} | ||
*/ | ||
function updateTestDefnFormat(allTestDefns) { | ||
const expandedTestDefns = allTestDefns.map(testDefn => { | ||
if (!Array.isArray(testDefn.expectations)) { | ||
// New object to make tsc happy. | ||
return { | ||
...testDefn, | ||
expectations: testDefn.expectations, | ||
}; | ||
} else { | ||
// Create a testDefn per expectation. | ||
return testDefn.expectations.map((expectations, index) => { | ||
return { | ||
...testDefn, | ||
id: `${testDefn.id}-${index}`, | ||
expectations, | ||
}; | ||
}); | ||
} | ||
}); | ||
|
||
return expandedTestDefns.flat(); | ||
} | ||
|
||
module.exports = { | ||
updateTestDefnFormat, | ||
}; |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ const cloneDeep = require('lodash.clonedeep'); | |||||||
const yargs = require('yargs'); | ||||||||
const log = require('lighthouse-logger'); | ||||||||
const {runSmokehouse} = require('../smokehouse.js'); | ||||||||
const {updateTestDefnFormat} = require('./back-compat-util.js'); | ||||||||
|
||||||||
const coreTestDefnsPath = path.join(__dirname, '../test-definitions/core-tests.js'); | ||||||||
|
||||||||
|
@@ -46,12 +47,17 @@ function getDefinitionsToRun(allTestDefns, requestedIds, {invertMatch}) { | |||||||
console.log('Running ALL smoketests. Equivalent to:'); | ||||||||
console.log(usage); | ||||||||
} else { | ||||||||
smokes = allTestDefns.filter(test => invertMatch !== requestedIds.includes(test.id)); | ||||||||
smokes = allTestDefns.filter(test => { | ||||||||
// Include all tests that *include* requested id. | ||||||||
// e.g. a requested 'pwa' will match 'pwa-airhorner', 'pwa-caltrain', etc | ||||||||
const isRequested = requestedIds.some(requestedId => test.id.includes(requestedId)); | ||||||||
return invertMatch !== isRequested; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're not trying to fit this on one line anymore, it could be more explicit.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I like it |
||||||||
}); | ||||||||
console.log(`Running ONLY smoketests for: ${smokes.map(t => t.id).join(' ')}\n`); | ||||||||
} | ||||||||
|
||||||||
const unmatchedIds = requestedIds.filter(requestedId => { | ||||||||
return !allTestDefns.map(t => t.id).includes(requestedId); | ||||||||
return !allTestDefns.map(t => t.id).some(id => id.includes(requestedId)); | ||||||||
}); | ||||||||
if (unmatchedIds.length) { | ||||||||
console.log(log.redify(`Smoketests not found for: ${unmatchedIds.join(' ')}`)); | ||||||||
|
@@ -80,23 +86,21 @@ function pruneExpectedNetworkRequests(testDefns, takeNetworkRequestUrls) { | |||||||
|
||||||||
const clonedDefns = cloneDeep(testDefns); | ||||||||
for (const {id, expectations, runSerially} of clonedDefns) { | ||||||||
for (const expectation of expectations) { | ||||||||
if (!runSerially && expectation.networkRequests) { | ||||||||
throw new Error(`'${id}' must be set to 'runSerially: true' to assert 'networkRequests'`); | ||||||||
} | ||||||||
if (!runSerially && expectations.networkRequests) { | ||||||||
throw new Error(`'${id}' must be set to 'runSerially: true' to assert 'networkRequests'`); | ||||||||
} | ||||||||
|
||||||||
if (pruneNetworkRequests && expectation.networkRequests) { | ||||||||
// eslint-disable-next-line max-len | ||||||||
const msg = `'networkRequests' cannot be asserted in test '${id}'. They should only be asserted on tests from an in-process server`; | ||||||||
if (process.env.CI) { | ||||||||
// If we're in CI, we require any networkRequests expectations to be asserted. | ||||||||
throw new Error(msg); | ||||||||
} | ||||||||
|
||||||||
console.warn(log.redify('Warning:'), | ||||||||
`${msg}. Pruning expectation: ${JSON.stringify(expectation.networkRequests)}`); | ||||||||
expectation.networkRequests = undefined; | ||||||||
if (pruneNetworkRequests && expectations.networkRequests) { | ||||||||
// eslint-disable-next-line max-len | ||||||||
const msg = `'networkRequests' cannot be asserted in test '${id}'. They should only be asserted on tests from an in-process server`; | ||||||||
if (process.env.CI) { | ||||||||
// If we're in CI, we require any networkRequests expectations to be asserted. | ||||||||
throw new Error(msg); | ||||||||
} | ||||||||
|
||||||||
console.warn(log.redify('Warning:'), | ||||||||
`${msg}. Pruning expectation: ${JSON.stringify(expectations.networkRequests)}`); | ||||||||
expectations.networkRequests = undefined; | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
|
@@ -166,7 +170,8 @@ async function begin() { | |||||||
let testDefnPath = argv.testsPath || coreTestDefnsPath; | ||||||||
testDefnPath = path.resolve(process.cwd(), testDefnPath); | ||||||||
const requestedTestIds = argv._; | ||||||||
const allTestDefns = require(testDefnPath); | ||||||||
const rawTestDefns = require(testDefnPath); | ||||||||
const allTestDefns = updateTestDefnFormat(rawTestDefns); | ||||||||
const invertMatch = argv.invertMatch; | ||||||||
const testDefns = getDefinitionsToRun(allTestDefns, requestedTestIds, {invertMatch}); | ||||||||
|
||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: flip case to use positive condition