diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 7dd90f705..8b852b080 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -53,7 +53,6 @@ describe('cache-restore', () => { let getCommandOutputSpy: jest.SpyInstance; let restoreCacheSpy: jest.SpyInstance; let hashFilesSpy: jest.SpyInstance; - let inSpy: jest.SpyInstance; beforeEach(() => { // core @@ -70,8 +69,6 @@ describe('cache-restore', () => { saveStateSpy.mockImplementation(() => undefined); inputs = {}; - inSpy = jest.spyOn(core, 'getInput'); - inSpy.mockImplementation(name => inputs[name]); // glob hashFilesSpy = jest.spyOn(glob, 'hashFiles'); @@ -137,12 +134,11 @@ 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-vABC-${fileHash}` + `Cache restored from key: node-cache-${platform}-${packageManager}-${fileHash}` ); expect(infoSpy).not.toHaveBeenCalledWith( `${packageManager} cache is not found` diff --git a/__tests__/cache-utils.test.ts b/__tests__/cache-utils.test.ts index e1851d947..39f376f21 100644 --- a/__tests__/cache-utils.test.ts +++ b/__tests__/cache-utils.test.ts @@ -6,7 +6,8 @@ import { PackageManagerInfo, isCacheFeatureAvailable, supportedPackageManagers, - getCommandOutput + getCommandOutput, + resetProjectDirectoriesMemoized } from '../src/cache-utils'; import fs from 'fs'; import * as cacheUtils from '../src/cache-utils'; @@ -104,9 +105,7 @@ describe('cache-utils', () => { MockGlobber.create(['/foo', '/bar']) ); - Object.keys(expandedPatternsMemoized).forEach( - key => delete expandedPatternsMemoized[key] - ); + resetProjectDirectoriesMemoized(); }); afterEach(() => { diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 90047eabf..4f0a1b625 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -60434,7 +60434,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.isCacheFeatureAvailable = exports.isGhes = exports.repoHasYarn3ManagedCache = exports.getCacheDirectories = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0; +exports.isCacheFeatureAvailable = exports.isGhes = exports.repoHasYarn3ManagedCache = exports.getCacheDirectories = exports.resetProjectDirectoriesMemoized = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0; const core = __importStar(__nccwpck_require__(2186)); const exec = __importStar(__nccwpck_require__(1514)); const cache = __importStar(__nccwpck_require__(7799)); @@ -60511,6 +60511,11 @@ exports.getPackageManagerInfo = getPackageManagerInfo; * it contains expensive IO operation and thus should be memoized */ let projectDirectoriesMemoized = null; +/** + * unit test must reset memoized variables + */ +const resetProjectDirectoriesMemoized = () => (projectDirectoriesMemoized = null); +exports.resetProjectDirectoriesMemoized = resetProjectDirectoriesMemoized; /** * Expands (converts) the string input `cache-dependency-path` to list of directories that * may be project roots diff --git a/dist/setup/index.js b/dist/setup/index.js index bdc32041f..fb63a8078 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -71220,7 +71220,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.isCacheFeatureAvailable = exports.isGhes = exports.repoHasYarn3ManagedCache = exports.getCacheDirectories = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0; +exports.isCacheFeatureAvailable = exports.isGhes = exports.repoHasYarn3ManagedCache = exports.getCacheDirectories = exports.resetProjectDirectoriesMemoized = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0; const core = __importStar(__nccwpck_require__(2186)); const exec = __importStar(__nccwpck_require__(1514)); const cache = __importStar(__nccwpck_require__(7799)); @@ -71297,6 +71297,11 @@ exports.getPackageManagerInfo = getPackageManagerInfo; * it contains expensive IO operation and thus should be memoized */ let projectDirectoriesMemoized = null; +/** + * unit test must reset memoized variables + */ +const resetProjectDirectoriesMemoized = () => (projectDirectoriesMemoized = null); +exports.resetProjectDirectoriesMemoized = resetProjectDirectoriesMemoized; /** * Expands (converts) the string input `cache-dependency-path` to list of directories that * may be project roots diff --git a/src/cache-utils.ts b/src/cache-utils.ts index dfcaea254..c2466f3b2 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -119,6 +119,11 @@ export const getPackageManagerInfo = async (packageManager: string) => { */ let projectDirectoriesMemoized: string[] | null = null; +/** + * unit test must reset memoized variables + */ +export const resetProjectDirectoriesMemoized = () => + (projectDirectoriesMemoized = null); /** * Expands (converts) the string input `cache-dependency-path` to list of directories that * may be project roots