Skip to content

Commit 3f8d598

Browse files
authored
core(fr): index test parity (#13867)
1 parent c873d92 commit 3f8d598

File tree

4 files changed

+139
-1
lines changed

4 files changed

+139
-1
lines changed

lighthouse-core/fraggle-rock/config/filters.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ function filterConfigByExplicitFilters(config, filters) {
294294
baseAuditIds = getAuditIdsInCategories(config.categories, onlyCategories);
295295
} else if (onlyAudits) {
296296
baseAuditIds = new Set();
297+
} else if (!config.categories || !Object.keys(config.categories).length) {
298+
baseAuditIds = new Set(config.audits?.map(audit => audit.implementation.meta.id));
297299
}
298300

299301
const auditIdsToKeep = new Set(

lighthouse-core/fraggle-rock/gather/navigation-runner.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ async function navigationGather(requestor, options) {
327327
const artifacts = await Runner.gather(
328328
async () => {
329329
let {page} = options;
330+
const normalizedRequestor = isCallback ? requestor : URL.normalizeUrl(requestor);
330331

331332
// For navigation mode, we shouldn't connect to a browser in audit mode,
332333
// therefore we connect to the browser in the gatherFn callback.
@@ -340,7 +341,7 @@ async function navigationGather(requestor, options) {
340341
const context = {
341342
driver,
342343
config,
343-
requestor: isCallback ? requestor : URL.normalizeUrl(requestor),
344+
requestor: normalizedRequestor,
344345
options: internalOptions,
345346
};
346347
const {baseArtifacts} = await _setup(context);

lighthouse-core/test/fraggle-rock/config/filters-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,34 @@ describe('Fraggle Rock Config Filtering', () => {
525525
});
526526
});
527527

528+
it('should keep all audits if there are no categories', () => {
529+
config = {
530+
...config,
531+
audits: [
532+
...audits,
533+
{implementation: NavigationOnlyAudit, options: {}},
534+
],
535+
categories: {},
536+
};
537+
538+
const filtered = filters.filterConfigByExplicitFilters(config, {
539+
onlyAudits: null,
540+
onlyCategories: null,
541+
skipAudits: null,
542+
});
543+
expect(filtered).toMatchObject({
544+
navigations: [{id: 'firstPass'}],
545+
artifacts: [{id: 'Snapshot'}, {id: 'Timespan'}],
546+
audits: [
547+
{implementation: SnapshotAudit},
548+
{implementation: TimespanAudit},
549+
{implementation: NavigationAudit},
550+
{implementation: ManualAudit},
551+
{implementation: NavigationOnlyAudit},
552+
],
553+
});
554+
});
555+
528556
it('should preserve full-page-screenshot', async () => {
529557
config = (await initializeConfig(undefined, {gatherMode: 'navigation'})).config;
530558

lighthouse-core/test/index-test.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,113 @@ describe('Module Tests', function() {
3737
assert.notEqual(lighthouseTraceCategories.length, 0);
3838
});
3939

40+
describe('lighthouse', () => {
41+
it('should throw an error when the first parameter is not defined', async () => {
42+
const resultPromise = lighthouse();
43+
await expect(resultPromise).rejects.toThrow();
44+
});
45+
46+
it('should throw an error when the first parameter is an empty string', async () => {
47+
const resultPromise = lighthouse('');
48+
await expect(resultPromise).rejects.toThrow();
49+
});
50+
51+
it('should throw an error when the first parameter is not a string', async () => {
52+
const resultPromise = lighthouse({});
53+
await expect(resultPromise).rejects.toThrow();
54+
});
55+
56+
it('should throw an error when the second parameter is not an object', async () => {
57+
const resultPromise = lighthouse('chrome://version', 'flags');
58+
await expect(resultPromise).rejects.toThrow();
59+
});
60+
61+
it('should throw an error when the config is invalid', async () => {
62+
const resultPromise = lighthouse('chrome://version', {}, {});
63+
await expect(resultPromise).rejects.toThrow();
64+
});
65+
66+
it('should throw an error when the config contains incorrect audits', async () => {
67+
const resultPromise = lighthouse('chrome://version', {}, {
68+
passes: [{
69+
gatherers: [
70+
'script-elements',
71+
],
72+
}],
73+
audits: [
74+
'fluff',
75+
],
76+
});
77+
await expect(resultPromise).rejects.toThrow();
78+
});
79+
80+
it('should throw an error when the url is invalid', async () => {
81+
const resultPromise = lighthouse('i-am-not-valid', {}, {});
82+
await expect(resultPromise).rejects.toThrow('INVALID_URL');
83+
});
84+
85+
it('should throw an error when the url is invalid protocol (file:///)', async () => {
86+
const resultPromise = lighthouse('file:///a/fake/index.html', {}, {});
87+
await expect(resultPromise).rejects.toThrow('INVALID_URL');
88+
});
89+
90+
it('should return formatted LHR when given no categories', async () => {
91+
const exampleUrl = 'https://www.reddit.com/r/nba';
92+
const result = await lighthouse(exampleUrl, {
93+
output: 'html',
94+
}, {
95+
settings: {
96+
auditMode: TEST_DIR + '/fixtures/artifacts/perflog/',
97+
formFactor: 'mobile',
98+
},
99+
artifacts: [
100+
{id: 'MetaElements', gatherer: 'meta-elements'},
101+
],
102+
audits: [
103+
'viewport',
104+
],
105+
});
106+
107+
assert.ok(/<html/.test(result.report), 'did not create html report');
108+
assert.ok(result.artifacts.ViewportDimensions, 'did not set artifacts');
109+
assert.ok(result.lhr.lighthouseVersion);
110+
assert.ok(result.lhr.fetchTime);
111+
assert.equal(result.lhr.finalUrl, exampleUrl);
112+
assert.equal(result.lhr.requestedUrl, exampleUrl);
113+
assert.equal(Object.values(result.lhr.categories).length, 0);
114+
assert.ok(result.lhr.audits.viewport);
115+
assert.strictEqual(result.lhr.audits.viewport.score, 0);
116+
assert.ok(result.lhr.audits.viewport.explanation);
117+
assert.ok(result.lhr.timing);
118+
assert.ok(result.lhr.timing.entries.length > 3, 'timing entries not populated');
119+
});
120+
121+
it('should specify the channel as node by default', async () => {
122+
const exampleUrl = 'https://www.reddit.com/r/nba';
123+
const result = await lighthouse(exampleUrl, {}, {
124+
settings: {
125+
auditMode: TEST_DIR + '/fixtures/artifacts/perflog/',
126+
formFactor: 'mobile',
127+
},
128+
audits: [],
129+
});
130+
assert.equal(result.lhr.configSettings.channel, 'node');
131+
});
132+
133+
it('lets consumers pass in a custom channel', async () => {
134+
const exampleUrl = 'https://www.reddit.com/r/nba';
135+
const result = await lighthouse(exampleUrl, {}, {
136+
settings: {
137+
auditMode: TEST_DIR + '/fixtures/artifacts/perflog/',
138+
formFactor: 'mobile',
139+
channel: 'custom',
140+
},
141+
audits: [],
142+
});
143+
assert.equal(result.lhr.configSettings.channel, 'custom');
144+
});
145+
});
146+
40147
describe('legacyNavigation', () => {
41148
it('should throw an error when the first parameter is not defined', function() {
42149
return legacyNavigation()

0 commit comments

Comments
 (0)