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

test(smokehouse): use static requires for test definitions #9501

Merged
merged 11 commits into from
Oct 2, 2019
5 changes: 4 additions & 1 deletion lighthouse-cli/test/smokehouse/a11y/expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
/* eslint-disable max-len */

/**
* @type {Array<Smokehouse.ExpectedRunnerResult>}
* Expected Lighthouse audit values for byte efficiency tests
*/
module.exports = [
const expectations = [
{
lhr: {
requestedUrl: 'http://localhost:10200/a11y/a11y_tester.html',
Expand Down Expand Up @@ -462,3 +463,5 @@ module.exports = [
},
},
];

module.exports = expectations;
5 changes: 4 additions & 1 deletion lighthouse-cli/test/smokehouse/byte-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
'use strict';

/**
* @type {LH.Config.Json}
* Config file for running byte efficiency smokehouse audits.
*/
module.exports = {
const config = {
extends: 'lighthouse:full',
settings: {
onlyAudits: [
Expand All @@ -27,3 +28,5 @@ module.exports = {
throttlingMethod: 'devtools',
},
};

module.exports = config;
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
'use strict';

/**
* @type {Array<Smokehouse.ExpectedRunnerResult>}
* Expected Lighthouse audit values for byte efficiency tests
*/
module.exports = [
const expectations = [
{
lhr: {
requestedUrl: 'http://localhost:10200/byte-efficiency/tester.html',
Expand Down Expand Up @@ -150,3 +151,5 @@ module.exports = [
},
},
];

module.exports = expectations;
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
'use strict';

/**
* @type {Array<Smokehouse.ExpectedRunnerResult>}
* Expected Lighthouse audit values for Do Better Web tests.
*/
module.exports = [
const expectations = [
{
artifacts: {
Stacks: [{
Expand Down Expand Up @@ -249,3 +250,5 @@ module.exports = [
},
},
];

module.exports = expectations;
5 changes: 4 additions & 1 deletion lighthouse-cli/test/smokehouse/error-expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ const NONEMPTY_ARRAY = {
};

/**
* @type {Array<Smokehouse.ExpectedRunnerResult>}
* Expected Lighthouse audit values for sites with various errors.
*/
module.exports = [
const expectations = [
{
lhr: {
requestedUrl: 'http://localhost:10200/infinite-loop.html',
Expand Down Expand Up @@ -60,3 +61,5 @@ module.exports = [
},
},
];

module.exports = expectations;
9 changes: 6 additions & 3 deletions lighthouse-cli/test/smokehouse/redirects/expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
*/
'use strict';

const cacheBuster = Number(new Date());

/**
* @type {Array<Smokehouse.ExpectedRunnerResult>}
* Expected Lighthouse audit values for redirects tests
*/
const cacheBuster = Number(new Date());

module.exports = [
const expectations = [
{
lhr: {
requestedUrl: `http://localhost:10200/online-only.html?delay=500&redirect=%2Foffline-only.html%3Fcb=${cacheBuster}%26delay=500%26redirect%3D%2Fredirects-final.html`,
Expand Down Expand Up @@ -46,3 +47,5 @@ module.exports = [
},
},
];

module.exports = expectations;
19 changes: 9 additions & 10 deletions lighthouse-cli/test/smokehouse/run-smoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const log = require('lighthouse-logger');

/** @param {string} str */
const purpleify = str => `${log.purple}${str}${log.reset}`;
const SMOKETESTS = require('./smoke-test-dfns.js').SMOKE_TEST_DFNS;
const smokeTests = require('./smoke-test-dfns.js');

/**
* Display smokehouse output from child process
Expand All @@ -35,18 +35,17 @@ function displaySmokehouseOutput(result) {
/**
* Run smokehouse in child processes for selected smoketests
* Display output from each as soon as they finish, but resolve function when ALL are complete
* @param {Array<Smokehouse.TestDfn>} smokes
* @param {Array<Smokehouse.Test>} smokes
* @return {Promise<Array<{id: string, error?: Error}>>}
*/
async function runSmokehouse(smokes) {
const cmdPromises = [];
for (const {id, expectations, config} of smokes) {
for (const {id} of smokes) {
console.log(`${purpleify(id)} smoketest starting…`);
console.time(`smoketest-${id}`);
const cmd = [
'node lighthouse-cli/test/smokehouse/smokehouse.js',
`--config-path=${config}`,
`--expectations-path=${expectations}`,
`--smoke-id=${id}`,
].join(' ');

// The promise ensures we output immediately, even if the process errors
Expand All @@ -68,22 +67,22 @@ async function runSmokehouse(smokes) {
/**
* Determine batches of smoketests to run, based on argv
* @param {string[]} argv
* @return {Map<string|undefined, Array<Smokehouse.TestDfn>>}
* @return {Map<string|undefined, Array<Smokehouse.Test>>}
*/
function getSmoketestBatches(argv) {
let smokes = [];
const usage = ` ${log.dim}yarn smoke ${SMOKETESTS.map(t => t.id).join(' ')}${log.reset}\n`;
const usage = ` ${log.dim}yarn smoke ${smokeTests.map(t => t.id).join(' ')}${log.reset}\n`;

if (argv.length === 0) {
smokes = SMOKETESTS;
smokes = smokeTests;
console.log('Running ALL smoketests. Equivalent to:');
console.log(usage);
} else {
smokes = SMOKETESTS.filter(test => argv.includes(test.id));
smokes = smokeTests.filter(test => argv.includes(test.id));
console.log(`Running ONLY smoketests for: ${smokes.map(t => t.id).join(' ')}\n`);
}

const unmatchedIds = argv.filter(requestedId => !SMOKETESTS.map(t => t.id).includes(requestedId));
const unmatchedIds = argv.filter(requestedId => !smokeTests.map(t => t.id).includes(requestedId));
if (unmatchedIds.length) {
console.log(log.redify(`Smoketests not found for: ${unmatchedIds.join(' ')}`));
console.log(usage);
Expand Down
17 changes: 15 additions & 2 deletions lighthouse-cli/test/smokehouse/seo/expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@
* 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';
/* global window */

/** @type {typeof import('url').URLSearchParams} */
let URLSearchParams;
if (typeof window !== 'undefined') {
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
// @ts-ignore
URLSearchParams = window.URLSearchParams;
} else {
URLSearchParams = require('url').URLSearchParams;
}

const BASE_URL = 'http://localhost:10200/seo/';
const URLSearchParams = require('url').URLSearchParams;

/**
* @param {[string, string][]} headers
Expand Down Expand Up @@ -94,9 +104,10 @@ const passHeaders = headersParam([[
]]);

/**
* @type {Array<Smokehouse.ExpectedRunnerResult>}
* Expected Lighthouse audit values for seo tests
*/
module.exports = [
const expectations = [
{
lhr: {
requestedUrl: BASE_URL + 'seo-tester.html?' + passHeaders,
Expand Down Expand Up @@ -391,3 +402,5 @@ module.exports = [
},
},
];

module.exports = expectations;
Loading