mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[7.x] [kbn/optimizer] exclude "cache" config from cache key, diff actually compared values (#67232) (#67542)
Co-authored-by: spalger <spalger@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
9349f32f0e
commit
6b22503c88
4 changed files with 23 additions and 17 deletions
|
@ -31,7 +31,7 @@ export interface WorkerConfig {
|
|||
readonly optimizerCacheKey: unknown;
|
||||
}
|
||||
|
||||
export type CacheableWorkerConfig = Omit<WorkerConfig, 'watch' | 'profileWebpack'>;
|
||||
export type CacheableWorkerConfig = Omit<WorkerConfig, 'watch' | 'profileWebpack' | 'cache'>;
|
||||
|
||||
export function parseWorkerConfig(json: string): WorkerConfig {
|
||||
try {
|
||||
|
|
|
@ -208,8 +208,8 @@ it('emits "bundle not cached" event when optimizerCacheKey is outdated, includes
|
|||
"diff": "[32m- Expected[39m
|
||||
[31m+ Received[39m
|
||||
|
||||
[32m- old[39m
|
||||
[31m+ optimizerCacheKey[39m",
|
||||
[32m- \\"old\\"[39m
|
||||
[31m+ \\"optimizerCacheKey\\"[39m",
|
||||
"reason": "optimizer cache key mismatch",
|
||||
"type": "bundle not cached",
|
||||
},
|
||||
|
@ -291,8 +291,8 @@ it('emits "bundle not cached" event when cacheKey is outdated', async () => {
|
|||
"diff": "[32m- Expected[39m
|
||||
[31m+ Received[39m
|
||||
|
||||
[32m- old[39m
|
||||
[31m+ new[39m",
|
||||
[32m- \\"old\\"[39m
|
||||
[31m+ \\"new\\"[39m",
|
||||
"reason": "cache key mismatch",
|
||||
"type": "bundle not cached",
|
||||
},
|
||||
|
|
|
@ -100,7 +100,6 @@ describe('getOptimizerCacheKey()', () => {
|
|||
},
|
||||
"workerConfig": Object {
|
||||
"browserslistEnv": "dev",
|
||||
"cache": true,
|
||||
"dist": false,
|
||||
"optimizerCacheKey": "♻",
|
||||
"repoRoot": <absolute path>,
|
||||
|
@ -134,13 +133,13 @@ describe('diffCacheKey()', () => {
|
|||
"[32m- Expected[39m
|
||||
[31m+ Received[39m
|
||||
|
||||
[2m Array [[22m
|
||||
[2m [[22m
|
||||
[2m \\"1\\",[22m
|
||||
[2m \\"2\\",[22m
|
||||
[2m Object {[22m
|
||||
[32m- \\"a\\": \\"b\\",[39m
|
||||
[31m+ \\"b\\": \\"a\\",[39m
|
||||
[2m },[22m
|
||||
[2m {[22m
|
||||
[32m- \\"a\\": \\"b\\"[39m
|
||||
[31m+ \\"b\\": \\"a\\"[39m
|
||||
[2m }[22m
|
||||
[2m ][22m"
|
||||
`);
|
||||
expect(
|
||||
|
@ -158,11 +157,11 @@ describe('diffCacheKey()', () => {
|
|||
"[32m- Expected[39m
|
||||
[31m+ Received[39m
|
||||
|
||||
[2m Object {[22m
|
||||
[2m {[22m
|
||||
[32m- \\"a\\": \\"1\\",[39m
|
||||
[32m- \\"b\\": \\"1\\",[39m
|
||||
[32m- \\"b\\": \\"1\\"[39m
|
||||
[31m+ \\"a\\": \\"2\\",[39m
|
||||
[31m+ \\"b\\": \\"2\\",[39m
|
||||
[31m+ \\"b\\": \\"2\\"[39m
|
||||
[2m }[22m"
|
||||
`);
|
||||
});
|
||||
|
|
|
@ -48,11 +48,18 @@ function omit<T, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {
|
|||
}
|
||||
|
||||
export function diffCacheKey(expected?: unknown, actual?: unknown) {
|
||||
if (jsonStable(expected) === jsonStable(actual)) {
|
||||
const expectedJson = jsonStable(expected, {
|
||||
space: ' ',
|
||||
});
|
||||
const actualJson = jsonStable(actual, {
|
||||
space: ' ',
|
||||
});
|
||||
|
||||
if (expectedJson === actualJson) {
|
||||
return;
|
||||
}
|
||||
|
||||
return reformatJestDiff(jestDiff(expected, actual));
|
||||
return reformatJestDiff(jestDiff(expectedJson, actualJson));
|
||||
}
|
||||
|
||||
export function reformatJestDiff(diff: string | null) {
|
||||
|
@ -178,7 +185,7 @@ export async function getOptimizerCacheKey(config: OptimizerConfig) {
|
|||
bootstrap,
|
||||
deletedPaths,
|
||||
modifiedTimes: {} as Record<string, number>,
|
||||
workerConfig: omit(config.getWorkerConfig('♻'), ['watch', 'profileWebpack']),
|
||||
workerConfig: omit(config.getWorkerConfig('♻'), ['watch', 'profileWebpack', 'cache']),
|
||||
};
|
||||
|
||||
const mtimes = await getMtimes(modifiedPaths);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue