Skip to content

Commit

Permalink
Adding unit test for checking cache inconsistency
Browse files Browse the repository at this point in the history
  • Loading branch information
deepampriyadarshi committed Feb 24, 2023
1 parent 0520a8d commit 7209ed5
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/app-cli/tests/MdToHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,41 @@ describe('MdToHtml', () => {
);
}
}));

test('should not make cache inconsistent', (async () => {

const codeTheme = 'atom-one-light.css';

const mdToHtml = newTestMdToHtml({
codeTheme: codeTheme,
theme: themeStyle(1),
externalAssetsOnly: false,
});

async function renderCall(inputText: string) {
const result = await mdToHtml.render(inputText, themeStyle(1), {
bodyOnly: false,
plainResourceRendering: true,
splitted: true,
externalAssetsOnly: true,
contentMaxWidth: 0,
});
return { ...result, pluginAssets: result.pluginAssets.slice() };
}

const cacheKey = themeStyle(1).cacheKey + codeTheme;

const firstRender = await renderCall('# First render call');
const firstCacheRetrieval = { ...mdToHtml['allProcessedAssets_'][cacheKey], pluginAssets: mdToHtml['allProcessedAssets_'][cacheKey].pluginAssets.slice() };

const secondRender = await renderCall('# Second render call');
const secondCacheRetrieval = { ...mdToHtml['allProcessedAssets_'][cacheKey], pluginAssets: mdToHtml['allProcessedAssets_'][cacheKey].pluginAssets.slice() };

expect(firstCacheRetrieval).toStrictEqual(secondCacheRetrieval);
expect(firstRender.cssStrings).toBeUndefined();
expect(secondRender.cssStrings).toBeUndefined();
expect(firstRender.pluginAssets).toStrictEqual(secondRender.pluginAssets);
expect(firstRender.pluginAssets).not.toEqual(firstCacheRetrieval.pluginAssets);
expect(secondRender.pluginAssets).not.toEqual(secondCacheRetrieval.pluginAssets);
}));
});

0 comments on commit 7209ed5

Please sign in to comment.