-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
core(fr): filter out manual-only categories #12367
Changes from 1 commit
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 |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
*/ | ||
'use strict'; | ||
|
||
const Audit = require('../../audits/audit.js'); | ||
|
||
/** | ||
* Filters an array of artifacts down to the set that supports the specified gather mode. | ||
* | ||
|
@@ -48,16 +50,32 @@ function filterCategoriesByAvailableAudits(categories, availableAudits) { | |
if (!categories) return categories; | ||
|
||
const availableAuditIds = new Set(availableAudits.map(audit => audit.implementation.meta.id)); | ||
const manualAuditIds = new Set( | ||
availableAudits | ||
.filter(audit => audit.implementation.meta.scoreDisplayMode === Audit.SCORING_MODES.MANUAL) | ||
.map(audit => audit.implementation.meta.id) | ||
); | ||
|
||
return Object.fromEntries( | ||
Object.entries(categories).map(([categoryId, category]) => { | ||
const categoryEntries = Object.entries(categories) | ||
.map(([categoryId, category]) => { | ||
const filteredCategory = { | ||
...category, | ||
auditRefs: category.auditRefs.filter(ref => availableAuditIds.has(ref.id)), | ||
}; | ||
|
||
const didFilter = filteredCategory.auditRefs.length < category.auditRefs.length; | ||
const hasOnlyManualAudits = filteredCategory.auditRefs.every(ref => | ||
manualAuditIds.has(ref.id) | ||
); | ||
|
||
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. that line is empty of course it's covered... go home codecov you're drunk 😆 (I'm assuming this is some source mapping issue because line 66 can't be covered, it's a make TS happy check that's impossible, EDIT: I take it back the line is obviously covered it's just the branch that can't. dunno what's going on) |
||
// If we filtered out audits and the only ones left are manual, remove them too. | ||
if (didFilter && hasOnlyManualAudits) filteredCategory.auditRefs = []; | ||
|
||
return [categoryId, filteredCategory]; | ||
}) | ||
); | ||
.filter(entry => typeof entry[1] === 'object' && entry[1].auditRefs.length); | ||
|
||
return Object.fromEntries(categoryEntries); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,14 @@ describe('Fraggle Rock Config Filtering', () => { | |
...auditMeta, | ||
}; | ||
} | ||
class ManualAudit extends BaseAudit { | ||
static meta = { | ||
id: 'manual', | ||
scoreDisplayMode: BaseAudit.SCORING_MODES.MANUAL, | ||
requiredArtifacts: /** @type {any} */ ([]), | ||
...auditMeta, | ||
}; | ||
} | ||
class TimespanAudit extends BaseAudit { | ||
static meta = { | ||
id: 'timespan', | ||
|
@@ -62,7 +70,7 @@ describe('Fraggle Rock Config Filtering', () => { | |
}; | ||
} | ||
|
||
const audits = [SnapshotAudit, TimespanAudit, NavigationAudit].map(audit => ({ | ||
const audits = [SnapshotAudit, TimespanAudit, NavigationAudit, ManualAudit].map(audit => ({ | ||
implementation: audit, | ||
options: {}, | ||
})); | ||
|
@@ -76,6 +84,7 @@ describe('Fraggle Rock Config Filtering', () => { | |
const partialArtifacts = [{id: 'Snapshot', gatherer: {instance: snapshotGatherer}}]; | ||
expect(filters.filterAuditsByAvailableArtifacts(audits, partialArtifacts)).toEqual([ | ||
{implementation: SnapshotAudit, options: {}}, | ||
{implementation: ManualAudit, options: {}}, | ||
]); | ||
}); | ||
|
||
|
@@ -89,6 +98,7 @@ describe('Fraggle Rock Config Filtering', () => { | |
snapshot: {title: 'Snapshot', auditRefs: [{id: 'snapshot', weight: 0}]}, | ||
timespan: {title: 'Timespan', auditRefs: [{id: 'timespan', weight: 0}]}, | ||
navigation: {title: 'Navigation', auditRefs: [{id: 'navigation', weight: 0}]}, | ||
manual: {title: 'Manual', auditRefs: [{id: 'manual', weight: 0}]}, | ||
mixed: { | ||
title: 'Mixed', | ||
auditRefs: [ | ||
|
@@ -106,12 +116,36 @@ describe('Fraggle Rock Config Filtering', () => { | |
|
||
it('should filter entire categories', () => { | ||
const partialAudits = [{implementation: SnapshotAudit, options: {}}]; | ||
expect(filters.filterCategoriesByAvailableAudits(categories, partialAudits)).toMatchObject({ | ||
const filtered = filters.filterCategoriesByAvailableAudits(categories, partialAudits); | ||
expect(filtered).not.toMatchObject({ | ||
timespan: {}, | ||
navigation: {}, | ||
}); | ||
Comment on lines
+120
to
+123
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. Nice way of enforcing this |
||
expect(filtered).toMatchObject({ | ||
snapshot: {}, | ||
mixed: {}, | ||
}); | ||
}); | ||
|
||
it('should filter entire categories when all remaining audits are manual', () => { | ||
const partialAudits = [ | ||
{implementation: SnapshotAudit, options: {}}, | ||
{implementation: ManualAudit, options: {}}, | ||
]; | ||
|
||
const filteredCategories = filters.filterCategoriesByAvailableAudits({ | ||
snapshot: categories.snapshot, | ||
timespanWithManual: { | ||
title: 'Timespan + Manual', | ||
auditRefs: [ | ||
{id: 'timespan', weight: 0}, | ||
{id: 'manual', weight: 0}, | ||
], | ||
}, | ||
}, partialAudits); | ||
expect(filteredCategories).not.toHaveProperty('timespanWithManual'); | ||
}); | ||
|
||
it('should filter audits within categories', () => { | ||
const partialAudits = [{implementation: SnapshotAudit, options: {}}]; | ||
const filtered = filters.filterCategoriesByAvailableAudits(categories, partialAudits); | ||
|
@@ -139,8 +173,12 @@ describe('Fraggle Rock Config Filtering', () => { | |
}; | ||
expect(filters.filterConfigByGatherMode(config, 'snapshot')).toMatchObject({ | ||
artifacts: [{id: 'Snapshot'}], | ||
audits: [{implementation: SnapshotAudit}], | ||
categories: {snapshot: {}, mixed: {auditRefs: [{id: 'snapshot'}]}}, | ||
audits: [{implementation: SnapshotAudit}, {implementation: ManualAudit}], | ||
categories: { | ||
snapshot: {}, | ||
manual: {}, | ||
mixed: {auditRefs: [{id: 'snapshot'}]}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
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: Would a single
auditIdToAuditMeta
map also work? I don't think you need to change anything unless you see us adding another filter in the future.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.
sure I'll refactor 👍