Skip to content

Commit

Permalink
Use keyprefix if a cache managed by yarn
Browse files Browse the repository at this point in the history
Yarn can remove obsolete dependencie so we can re-use the previous cache
without its infinitive growing
  • Loading branch information
dsame committed May 27, 2023
1 parent 3f3c964 commit 36844ba
Show file tree
Hide file tree
Showing 7 changed files with 5,380 additions and 5,235 deletions.
9 changes: 8 additions & 1 deletion __tests__/cache-restore.test.ts
Expand Up @@ -45,13 +45,15 @@ describe('cache-restore', () => {
}
}

let inputs = {} as any;
let saveStateSpy: jest.SpyInstance;
let infoSpy: jest.SpyInstance;
let debugSpy: jest.SpyInstance;
let setOutputSpy: jest.SpyInstance;
let getCommandOutputSpy: jest.SpyInstance;
let restoreCacheSpy: jest.SpyInstance;
let hashFilesSpy: jest.SpyInstance;
let inSpy: jest.SpyInstance;

beforeEach(() => {
// core
Expand All @@ -67,6 +69,10 @@ describe('cache-restore', () => {
saveStateSpy = jest.spyOn(core, 'saveState');
saveStateSpy.mockImplementation(() => undefined);

inputs = {};
inSpy = jest.spyOn(core, 'getInput');
inSpy.mockImplementation(name => inputs[name]);

// glob
hashFilesSpy = jest.spyOn(glob, 'hashFiles');
hashFilesSpy.mockImplementation((pattern: string) => {
Expand Down Expand Up @@ -131,11 +137,12 @@ describe('cache-restore', () => {
return findCacheFolder(command);
}
});
inputs['node-version'] = 'vABC';

await restoreCache(packageManager, '');
expect(hashFilesSpy).toHaveBeenCalled();
expect(infoSpy).toHaveBeenCalledWith(
`Cache restored from key: node-cache-${platform}-${packageManager}-v2-${fileHash}`
`Cache restored from key: node-cache-${platform}-${packageManager}-v2-vABC-${fileHash}`
);
expect(infoSpy).not.toHaveBeenCalledWith(
`${packageManager} cache is not found`
Expand Down

0 comments on commit 36844ba

Please sign in to comment.