Skip to content

Add settings info to the message shown as each run starts #568

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

Merged
merged 1 commit into from
Apr 5, 2023
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
21 changes: 21 additions & 0 deletions src/lib/run-event/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const formatStartMessage = ({ count, path, formFactor, locale }) => {
const message = ['Running Lighthouse on', path];

// Build a list of settings used for this run.
const settings = [];
if (locale) {
settings.push(`the “${locale}” locale`);
}
if (formFactor === 'desktop') {
settings.push('the “desktop” preset');
}
if (settings.length) {
message.push(`using ${settings.join(' and ')}`);
}

if (count?.total > 1) {
message.push(`(${count.i}/${count.total})`);
}

return message.join(' ');
};
51 changes: 51 additions & 0 deletions src/lib/run-event/helpers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { formatStartMessage } from './helpers.js';

describe('formatStartMessage', () => {
it('should format a message using only the path', () => {
const result = formatStartMessage({ path: 'https://example.com/path' });
expect(result).toEqual('Running Lighthouse on https://example.com/path');
});

it('should format a message using only the path and count', () => {
const result = formatStartMessage({
count: { i: 1, total: 2 },
path: 'https://example.com/path',
});
expect(result).toEqual(
'Running Lighthouse on https://example.com/path (1/2)',
);
});

it('should format a message using a single feature', () => {
const result = formatStartMessage({
path: 'https://example.com/path',
formFactor: 'desktop',
});
expect(result).toEqual(
'Running Lighthouse on https://example.com/path using the “desktop” preset',
);
});

it('should format a message using multiple features', () => {
const result = formatStartMessage({
path: 'https://example.com/path',
formFactor: 'desktop',
locale: 'de',
});
expect(result).toEqual(
'Running Lighthouse on https://example.com/path using the “de” locale and the “desktop” preset',
);
});

it('should format a message using all available inputs', () => {
const result = formatStartMessage({
count: { i: 1, total: 2 },
path: 'https://example.com/path',
formFactor: 'desktop',
locale: 'es',
});
expect(result).toEqual(
'Running Lighthouse on https://example.com/path using the “es” locale and the “desktop” preset (1/2)',
);
});
});
14 changes: 9 additions & 5 deletions src/lib/run-event/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import runAuditWithUrl from '../../lib/run-audit-with-url/index.js';
import runAuditWithServer from '../../lib/run-audit-with-server/index.js';
import getConfiguration from '../get-configuration/index.js';

import { formatStartMessage } from './helpers.js';

const runEvent = async ({
event,
constants,
Expand Down Expand Up @@ -57,12 +59,14 @@ const runEvent = async ({
const { serveDir, path, url, thresholds, output_path } = auditConfig;
const fullPath = [serveDir, path].join('/');

let countMessage = '';
if (auditConfigs.length > 1) {
countMessage = ` (${i}/${auditConfigs.length})`;
}
const startMessage = formatStartMessage({
count: { i, total: auditConfigs.length },
path: fullPath,
formFactor: settings?.settings.formFactor,
locale: settings?.settings.locale,
});

console.log(`Running Lighthouse on ${fullPath}${countMessage}`);
console.log(startMessage);

const runner = isOnSuccess ? runAuditWithUrl : runAuditWithServer;
const { errors, summary, shortSummary, details, report, runtimeError } =
Expand Down