-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add config path to collect (#168)
- Loading branch information
Showing
17 changed files
with
221 additions
and
22 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
21 changes: 21 additions & 0 deletions
21
packages/cli/src/lib/commands/collect/utils/config/index.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { readFile, writeFile } from '../../../../core/file'; | ||
import { logVerbose } from '../../../../core/loggin'; | ||
import { DEFAULT_COLLECT_CONFIG_PATH } from '../../options/configPath.constant'; | ||
import { LhConfigJson } from '../../../../hacky-things/lighthouse'; | ||
|
||
|
||
export function readConfig(configPath: string = DEFAULT_COLLECT_CONFIG_PATH): LhConfigJson { | ||
const configJson = JSON.parse(readFile(configPath) || '{}'); | ||
return configJson; | ||
} | ||
|
||
export function writeConfig(config: LhConfigJson, configPath: string = DEFAULT_COLLECT_CONFIG_PATH): void { | ||
logVerbose(`Update config under ${configPath}`); | ||
|
||
if (JSON.stringify(readConfig()) !== JSON.stringify(config)) { | ||
writeFile(configPath, JSON.stringify(config)); | ||
logVerbose(`New config ${JSON.stringify(config)}`); | ||
} else { | ||
logVerbose(`No updates for ${configPath} to save.`); | ||
} | ||
} |
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
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
78 changes: 78 additions & 0 deletions
78
packages/cli/tests/commands/collect/collect.configPath.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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { UserFlowCliProject, UserFlowCliProjectFactory } from '../../user-flow-cli-project/user-flow-cli'; | ||
import { STATIC_PRJ_CFG } from '../../fixtures/sandbox/static'; | ||
import { UserFlowProjectConfig } from '../../user-flow-cli-project/types'; | ||
import { STATIC_JSON_REPORT_NAME, STATIC_RC_JSON } from '../../fixtures/rc-files/static'; | ||
import { DEFAULT_RC_NAME } from '../../../src/lib/constants'; | ||
import { | ||
expectConfigPathUsageLog, | ||
expectNoConfigFileExistLog, | ||
expectResultsToIncludeConfig | ||
} from '../../user-flow-cli-project/expect'; | ||
import { LH_CONFIG, LH_CONFIG_NAME } from '../../fixtures/config/lh-config'; | ||
import { expectCollectCfgToContain } from '../../utils/cli-expectations'; | ||
|
||
let staticPrj: UserFlowCliProject; | ||
|
||
describe('$collect() sandbox+NO-assets with RC()', () => { | ||
beforeEach(async () => { | ||
if (!staticPrj) { | ||
staticPrj = await UserFlowCliProjectFactory.create(STATIC_PRJ_CFG); | ||
} | ||
await staticPrj.setup(); | ||
}); | ||
afterEach(async () => await staticPrj.teardown()); | ||
|
||
it('should NOT log configPath info', async () => { | ||
const { exitCode, stdout, stderr } = await staticPrj.$collect(); | ||
|
||
expect(stderr).toBe(''); | ||
expectNoConfigFileExistLog(stdout); | ||
expect(exitCode).toBe(0); | ||
|
||
}); | ||
|
||
}); | ||
|
||
let staticWConfigAssetsPrj: UserFlowCliProject; | ||
let staticWConfigPathPrjCfg: UserFlowProjectConfig = { | ||
...STATIC_PRJ_CFG, | ||
rcFile: { | ||
[DEFAULT_RC_NAME]: { | ||
...STATIC_RC_JSON, | ||
collect: { | ||
...STATIC_RC_JSON.collect, | ||
configPath: LH_CONFIG_NAME | ||
} | ||
} | ||
}, | ||
create: { | ||
...STATIC_PRJ_CFG.create, | ||
[LH_CONFIG_NAME]: LH_CONFIG | ||
}, | ||
delete: [LH_CONFIG_NAME].concat(STATIC_PRJ_CFG?.delete || []) | ||
}; | ||
|
||
describe('$collect() sandbox+assets with RC({configPath}))', () => { | ||
beforeEach(async () => { | ||
if (!staticWConfigAssetsPrj) { | ||
staticWConfigAssetsPrj = await UserFlowCliProjectFactory.create(staticWConfigPathPrjCfg); | ||
} | ||
await staticWConfigAssetsPrj.setup(); | ||
}); | ||
afterEach(async () => await staticWConfigAssetsPrj.teardown()); | ||
|
||
it('should load configPath from RC file', async () => { | ||
const { exitCode, stdout, stderr } = await staticWConfigAssetsPrj.$collect({ | ||
configPath: LH_CONFIG_NAME | ||
}); | ||
|
||
|
||
expect(stderr).toBe(''); | ||
expectCollectCfgToContain(stdout, {configPath: LH_CONFIG_NAME}) | ||
expectConfigPathUsageLog(stdout, LH_CONFIG_NAME); | ||
expectResultsToIncludeConfig(staticWConfigAssetsPrj, STATIC_JSON_REPORT_NAME.split('.json').pop()+''); | ||
expect(exitCode).toBe(0); | ||
|
||
}, 60_000); | ||
|
||
}); |
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,12 @@ | ||
import { LhConfigJson } from '../../../src/lib/hacky-things/lighthouse'; | ||
|
||
export const LH_CONFIG_NAME = 'config.json'; | ||
export const LH_CONFIG: LhConfigJson = { | ||
extends: 'lighthouse:default', | ||
settings: { | ||
/** If present, the run should only conduct this list of audits. */ | ||
onlyAudits: ['lcp-lazy-loaded'] | ||
/** If present, the run should only conduct this list of categories. */ | ||
//'only-categories': ['performance'] | ||
} | ||
}; |
Oops, something went wrong.