-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-lighthouse): add only filters logic for categories (#515)
- Loading branch information
Showing
12 changed files
with
441 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 2 additions & 26 deletions
28
packages/plugin-lighthouse/src/lib/lighthouse-plugin.integration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,12 @@ | ||
import { expect } from 'vitest'; | ||
import { | ||
auditSchema, | ||
groupSchema, | ||
pluginConfigSchema, | ||
} from '@code-pushup/models'; | ||
import { AUDITS, GROUPS } from './constants'; | ||
import { pluginConfigSchema } from '@code-pushup/models'; | ||
import { lighthousePlugin } from './lighthouse-plugin'; | ||
|
||
describe('lighthousePlugin', () => { | ||
it('should create valid plugin config', () => { | ||
const pluginConfig = lighthousePlugin({ | ||
url: 'https://code-pushup-portal.com', | ||
}); | ||
const pluginConfig = lighthousePlugin('https://code-pushup-portal.com'); | ||
expect(() => pluginConfigSchema.parse(pluginConfig)).not.toThrow(); | ||
expect(pluginConfig.audits).toHaveLength(168); | ||
expect(pluginConfig.groups).toHaveLength(5); | ||
}); | ||
}); | ||
|
||
describe('generated-constants', () => { | ||
it.each(AUDITS.map(a => [a.slug, a]))( | ||
'should parse audit "%s" correctly', | ||
(_, audit) => { | ||
expect(() => auditSchema.parse(audit)).not.toThrow(); | ||
expect(audit.description).toEqual(expect.any(String)); | ||
}, | ||
); | ||
|
||
it.each(GROUPS.map(a => [a.slug, a]))( | ||
'should parse group "%s" correctly', | ||
(_, group) => { | ||
expect(() => groupSchema.parse(group)).not.toThrow(); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,28 @@ | ||
import { Audit, AuditOutputs, Group, PluginConfig } from '@code-pushup/models'; | ||
import { | ||
filterAuditsBySlug, | ||
filterGroupsByAuditSlug, | ||
} from '@code-pushup/utils'; | ||
type Config as LighthouseConfig, | ||
type CliFlags as LighthouseFlags, | ||
} from 'lighthouse'; | ||
import { PluginConfig } from '@code-pushup/models'; | ||
import { AUDITS, GROUPS, LIGHTHOUSE_PLUGIN_SLUG } from './constants'; | ||
import { validateOnlyAudits } from './utils'; | ||
|
||
export type LighthousePluginOptions = { | ||
url: string; | ||
outputPath?: string; | ||
onlyAudits?: string | string[]; | ||
verbose?: boolean; | ||
headless?: boolean; | ||
userDataDir?: string; | ||
}; | ||
import { filterAuditsAndGroupsByOnlyOptions } from './utils'; | ||
|
||
export function lighthousePlugin( | ||
options: LighthousePluginOptions, | ||
url: string, | ||
flags?: Partial<LighthouseFlags>, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
config?: Partial<LighthouseConfig>, | ||
): PluginConfig { | ||
const { onlyAudits = [] } = options; | ||
|
||
validateOnlyAudits(AUDITS, onlyAudits); | ||
const audits: Audit[] = filterAuditsBySlug(AUDITS, onlyAudits); | ||
const groups: Group[] = filterGroupsByAuditSlug(GROUPS, onlyAudits); | ||
|
||
const { audits, groups } = filterAuditsAndGroupsByOnlyOptions( | ||
AUDITS, | ||
GROUPS, | ||
flags, | ||
); | ||
return { | ||
slug: LIGHTHOUSE_PLUGIN_SLUG, | ||
title: 'Lighthouse', | ||
icon: 'lighthouse', | ||
audits, | ||
groups, | ||
runner: (): AuditOutputs => | ||
audits.map(audit => ({ | ||
...audit, | ||
score: 0, | ||
value: 0, | ||
})), | ||
runner: () => audits.map(({ slug }) => ({ slug, value: 0, score: 0 })), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.