[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:
Spencer 2020-05-27 13:49:47 -07:00 committed by GitHub
parent 9349f32f0e
commit 6b22503c88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 17 deletions

View file

@ -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 {

View file

@ -208,8 +208,8 @@ it('emits "bundle not cached" event when optimizerCacheKey is outdated, includes
"diff": "- Expected
+ Received
- old
+ optimizerCacheKey",
- \\"old\\"
+ \\"optimizerCacheKey\\"",
"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": "- Expected
+ Received
- old
+ new",
- \\"old\\"
+ \\"new\\"",
"reason": "cache key mismatch",
"type": "bundle not cached",
},

View file

@ -100,7 +100,6 @@ describe('getOptimizerCacheKey()', () => {
},
"workerConfig": Object {
"browserslistEnv": "dev",
"cache": true,
"dist": false,
"optimizerCacheKey": "♻",
"repoRoot": <absolute path>,
@ -134,13 +133,13 @@ describe('diffCacheKey()', () => {
"- Expected
+ Received
 Array [
 [
 \\"1\\",
 \\"2\\",
 Object {
- \\"a\\": \\"b\\",
+ \\"b\\": \\"a\\",
 },
 {
- \\"a\\": \\"b\\"
+ \\"b\\": \\"a\\"
 }
 ]"
`);
expect(
@ -158,11 +157,11 @@ describe('diffCacheKey()', () => {
"- Expected
+ Received
 Object {
 {
- \\"a\\": \\"1\\",
- \\"b\\": \\"1\\",
- \\"b\\": \\"1\\"
+ \\"a\\": \\"2\\",
+ \\"b\\": \\"2\\",
+ \\"b\\": \\"2\\"
 }"
`);
});

View file

@ -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);