-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
261 additions
and
38 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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
const preset = name => | ||
name | ||
? import(`lighthouse/core/config/${name}-config.js`) | ||
.then(mod => mod.default) | ||
.catch(() => undefined) | ||
: undefined | ||
|
||
module.exports = async ({ preset: presetName, ...settings } = {}) => { | ||
const config = (await preset(presetName)) || { extends: 'lighthouse:default' } | ||
if (Object.keys(settings).length > 0) config.settings = { ...config.settings, ...settings } | ||
return config | ||
} |
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
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,45 @@ | ||
'use strict' | ||
|
||
const { generateConfig } = require('lighthouse') | ||
const { readdirSync } = require('fs') | ||
const path = require('path') | ||
const test = require('ava') | ||
|
||
const { getConfig } = require('..') | ||
const getConfig = require('../src/get-config') | ||
|
||
const defaultConfig = generateConfig() | ||
const configDir = path.resolve(__dirname, '../node_modules/lighthouse/lighthouse-core/config') | ||
const configDir = path.resolve(__dirname, '../node_modules/lighthouse/core/config') | ||
const files = readdirSync(configDir) | ||
|
||
const excludesFiles = [ | ||
'budget.js', | ||
'config-helpers.js', | ||
'config-plugin.js', | ||
'config.js', | ||
'constants.js', | ||
'metrics-to-audits.js' | ||
] | ||
|
||
const configs = files | ||
.filter(n => !excludesFiles.includes(n)) | ||
.filter(n => n.endsWith('-config.js')) | ||
.map(n => n.replace('.js', '').replace('-config', '')) | ||
|
||
test('load default by default', t => { | ||
const config = generateConfig(getConfig()) | ||
t.deepEqual(JSON.stringify(config), JSON.stringify(defaultConfig)) | ||
test('load default by default', async t => { | ||
const config = await getConfig() | ||
t.snapshot(config) | ||
}) | ||
|
||
configs.forEach(preset => { | ||
test(`preset \`${preset}\``, t => { | ||
const config = generateConfig(getConfig({ preset })) | ||
const configPath = `lighthouse/lighthouse-core/config/${preset}-config.js` | ||
const baseConfig = generateConfig(require(configPath)) | ||
test('invalid preset', async t => { | ||
const config = await getConfig({ preset: 'notexist' }) | ||
t.snapshot(config) | ||
}) | ||
|
||
t.deepEqual(JSON.stringify(config), JSON.stringify(baseConfig)) | ||
test('invalid preset with settings', async t => { | ||
const config = await getConfig({ | ||
preset: 'notexist', | ||
skipAudits: ['uses-http2', 'bf-cache'] | ||
}) | ||
t.snapshot(config) | ||
}) | ||
|
||
configs.forEach(preset => { | ||
test(`preset \`${preset}\``, async t => { | ||
const configPath = path.resolve(configDir, `${preset}-config.js`) | ||
const config = await import(configPath).then(mod => mod.default) | ||
t.deepEqual(await getConfig({ preset }), config) | ||
}) | ||
}) | ||
|
||
test('preset with settings', async t => { | ||
const config = await getConfig({ preset: 'lr-desktop', skipAudits: ['uses-http2'] }) | ||
t.deepEqual(config.settings.skipAudits, ['uses-http2']) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Snapshot report for `test/get-config.js` | ||
|
||
The actual snapshot is saved in `get-config.js.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## load default by default | ||
|
||
> Snapshot 1 | ||
{ | ||
extends: 'lighthouse:default', | ||
} | ||
|
||
## invalid preset | ||
|
||
> Snapshot 1 | ||
{ | ||
extends: 'lighthouse:default', | ||
} | ||
|
||
## invalid preset with settings | ||
|
||
> Snapshot 1 | ||
{ | ||
extends: 'lighthouse:default', | ||
settings: { | ||
skipAudits: [ | ||
'uses-http2', | ||
'bf-cache', | ||
], | ||
}, | ||
} |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,166 @@ | ||
# Snapshot report for `test/index.js` | ||
|
||
The actual snapshot is saved in `index.js.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## specifying custom different configuration | ||
|
||
> Snapshot 1 | ||
{ | ||
additionalTraceCategories: null, | ||
auditMode: false, | ||
blankPage: 'about:blank', | ||
blockedUrlPatterns: null, | ||
budgets: null, | ||
channel: 'node', | ||
cpuQuietThresholdMs: 1000, | ||
debugNavigation: false, | ||
disableFullPageScreenshot: false, | ||
disableStorageReset: true, | ||
emulatedUserAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36', | ||
extraHeaders: null, | ||
formFactor: 'desktop', | ||
gatherMode: false, | ||
locale: 'en-US', | ||
maxWaitForFcp: 15000, | ||
maxWaitForLoad: 35000, | ||
networkQuietThresholdMs: 1000, | ||
onlyAudits: null, | ||
onlyCategories: null, | ||
output: 'json', | ||
pauseAfterFcpMs: 1000, | ||
pauseAfterLoadMs: 1000, | ||
precomputedLanternData: null, | ||
screenEmulation: { | ||
deviceScaleFactor: 1, | ||
disabled: false, | ||
height: 940, | ||
mobile: false, | ||
width: 1350, | ||
}, | ||
skipAboutBlank: false, | ||
skipAudits: [ | ||
'uses-http2', | ||
'bf-cache', | ||
], | ||
throttling: { | ||
cpuSlowdownMultiplier: 1, | ||
downloadThroughputKbps: 0, | ||
requestLatencyMs: 0, | ||
rttMs: 40, | ||
throughputKbps: 10240, | ||
uploadThroughputKbps: 0, | ||
}, | ||
throttlingMethod: 'simulate', | ||
usePassiveGathering: false, | ||
} | ||
|
||
## default configuration | ||
|
||
> Snapshot 1 | ||
{ | ||
additionalTraceCategories: null, | ||
auditMode: false, | ||
blankPage: 'about:blank', | ||
blockedUrlPatterns: null, | ||
budgets: null, | ||
channel: 'node', | ||
cpuQuietThresholdMs: 1000, | ||
debugNavigation: false, | ||
disableFullPageScreenshot: false, | ||
disableStorageReset: true, | ||
emulatedUserAgent: 'Mozilla/5.0 (Linux; Android 11; moto g power (2022)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Mobile Safari/537.36', | ||
extraHeaders: null, | ||
formFactor: 'mobile', | ||
gatherMode: false, | ||
locale: 'en-US', | ||
maxWaitForFcp: 30000, | ||
maxWaitForLoad: 45000, | ||
networkQuietThresholdMs: 1000, | ||
onlyAudits: null, | ||
onlyCategories: null, | ||
output: 'json', | ||
pauseAfterFcpMs: 1000, | ||
pauseAfterLoadMs: 1000, | ||
precomputedLanternData: null, | ||
screenEmulation: { | ||
deviceScaleFactor: 1.75, | ||
disabled: false, | ||
height: 823, | ||
mobile: true, | ||
width: 412, | ||
}, | ||
skipAboutBlank: false, | ||
skipAudits: null, | ||
throttling: { | ||
cpuSlowdownMultiplier: 4, | ||
downloadThroughputKbps: 1474.5600000000002, | ||
requestLatencyMs: 562.5, | ||
rttMs: 150, | ||
throughputKbps: 1638.4, | ||
uploadThroughputKbps: 675, | ||
}, | ||
throttlingMethod: 'simulate', | ||
usePassiveGathering: false, | ||
} | ||
|
||
## customize default configuration | ||
|
||
> Snapshot 1 | ||
{ | ||
additionalTraceCategories: null, | ||
auditMode: false, | ||
blankPage: 'about:blank', | ||
blockedUrlPatterns: null, | ||
budgets: null, | ||
channel: 'node', | ||
cpuQuietThresholdMs: 1000, | ||
debugNavigation: false, | ||
disableFullPageScreenshot: false, | ||
disableStorageReset: true, | ||
emulatedUserAgent: 'Mozilla/5.0 (Linux; Android 11; moto g power (2022)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Mobile Safari/537.36', | ||
extraHeaders: null, | ||
formFactor: 'mobile', | ||
gatherMode: false, | ||
locale: 'en-US', | ||
maxWaitForFcp: 30000, | ||
maxWaitForLoad: 45000, | ||
networkQuietThresholdMs: 1000, | ||
onlyAudits: [ | ||
'accessibility', | ||
], | ||
onlyCategories: null, | ||
output: 'json', | ||
pauseAfterFcpMs: 1000, | ||
pauseAfterLoadMs: 1000, | ||
precomputedLanternData: null, | ||
screenEmulation: { | ||
deviceScaleFactor: 1.75, | ||
disabled: false, | ||
height: 823, | ||
mobile: true, | ||
width: 412, | ||
}, | ||
skipAboutBlank: false, | ||
skipAudits: null, | ||
throttling: { | ||
cpuSlowdownMultiplier: 4, | ||
downloadThroughputKbps: 1474.5600000000002, | ||
requestLatencyMs: 562.5, | ||
rttMs: 150, | ||
throughputKbps: 1638.4, | ||
uploadThroughputKbps: 675, | ||
}, | ||
throttlingMethod: 'simulate', | ||
usePassiveGathering: false, | ||
} | ||
|
||
## passing a different serializer | ||
|
||
> Snapshot 1 | ||
undefined |
Binary file not shown.