mirror of
				https://github.com/actions/setup-node.git
				synced 2025-11-03 02:23:35 +00:00 
			
		
		
		
	Add unit tests
This commit is contained in:
		
							parent
							
								
									928eb4967d
								
							
						
					
					
						commit
						339630e034
					
				@ -4,6 +4,8 @@ import * as path from 'path';
 | 
			
		||||
import * as core from '@actions/core';
 | 
			
		||||
import * as io from '@actions/io';
 | 
			
		||||
import * as auth from '../src/authutil';
 | 
			
		||||
import * as cacheUtils from '../src/cache-utils';
 | 
			
		||||
import {getCacheDirectoryPath} from '../src/cache-utils';
 | 
			
		||||
 | 
			
		||||
let rcFile: string;
 | 
			
		||||
 | 
			
		||||
@ -209,4 +211,66 @@ describe('authutil tests', () => {
 | 
			
		||||
      `@otherscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
 | 
			
		||||
    );
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('getPackageManagerWorkingDir should return null for not yarn', async () => {
 | 
			
		||||
    process.env['INPUT_CACHE'] = 'some';
 | 
			
		||||
    delete process.env['INPUT_CACHE-DEPENDENCY-PATH'];
 | 
			
		||||
    const dir = cacheUtils.getPackageManagerWorkingDir();
 | 
			
		||||
    expect(dir).toBeNull();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('getPackageManagerWorkingDir should return null for not yarn with cache-dependency-path', async () => {
 | 
			
		||||
    process.env['INPUT_CACHE'] = 'some';
 | 
			
		||||
    process.env['INPUT_CACHE-DEPENDENCY-PATH'] = '/foo/bar';
 | 
			
		||||
    const dir = cacheUtils.getPackageManagerWorkingDir();
 | 
			
		||||
    expect(dir).toBeNull();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('getPackageManagerWorkingDir should return null for yarn but without cache-dependency-path', async () => {
 | 
			
		||||
    process.env['INPUT_CACHE'] = 'yarn';
 | 
			
		||||
    delete process.env['INPUT_CACHE-DEPENDENCY-PATH'];
 | 
			
		||||
    const dir = cacheUtils.getPackageManagerWorkingDir();
 | 
			
		||||
    expect(dir).toBeNull();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('getPackageManagerWorkingDir should return path for yarn with cache-dependency-path', async () => {
 | 
			
		||||
    process.env['INPUT_CACHE'] = 'yarn';
 | 
			
		||||
    const cachePath = '/foo/bar';
 | 
			
		||||
    process.env['INPUT_CACHE-DEPENDENCY-PATH'] = cachePath;
 | 
			
		||||
    const dir = cacheUtils.getPackageManagerWorkingDir();
 | 
			
		||||
    expect(dir).toEqual(path.dirname(cachePath));
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('getCommandOutput(getPackageManagerVersion) should be called from  with getPackageManagerWorkingDir result', async () => {
 | 
			
		||||
    process.env['INPUT_CACHE'] = 'yarn';
 | 
			
		||||
    const cachePath = '/foo/bar';
 | 
			
		||||
    process.env['INPUT_CACHE-DEPENDENCY-PATH'] = cachePath;
 | 
			
		||||
    const getCommandOutputSpy = jest
 | 
			
		||||
      .spyOn(cacheUtils, 'getCommandOutput')
 | 
			
		||||
      .mockReturnValue(Promise.resolve('baz'));
 | 
			
		||||
 | 
			
		||||
    const version = await cacheUtils.getPackageManagerVersion('foo', 'bar');
 | 
			
		||||
    expect(getCommandOutputSpy).toHaveBeenCalledWith(
 | 
			
		||||
      `foo bar`,
 | 
			
		||||
      path.dirname(cachePath)
 | 
			
		||||
    );
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('getCommandOutput(getCacheDirectoryPath) should be called from  with getPackageManagerWorkingDir result', async () => {
 | 
			
		||||
    process.env['INPUT_CACHE'] = 'yarn';
 | 
			
		||||
    const cachePath = '/foo/bar';
 | 
			
		||||
    process.env['INPUT_CACHE-DEPENDENCY-PATH'] = cachePath;
 | 
			
		||||
    const getCommandOutputSpy = jest
 | 
			
		||||
      .spyOn(cacheUtils, 'getCommandOutput')
 | 
			
		||||
      .mockReturnValue(Promise.resolve('baz'));
 | 
			
		||||
 | 
			
		||||
    const version = await cacheUtils.getCacheDirectoryPath(
 | 
			
		||||
      {lockFilePatterns: [], getCacheFolderCommand: 'quz'},
 | 
			
		||||
      ''
 | 
			
		||||
    );
 | 
			
		||||
    expect(getCommandOutputSpy).toHaveBeenCalledWith(
 | 
			
		||||
      `quz`,
 | 
			
		||||
      path.dirname(cachePath)
 | 
			
		||||
    );
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										5
									
								
								dist/cache-save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								dist/cache-save/index.js
									
									
									
									
										vendored
									
									
								
							@ -59248,7 +59248,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.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getPackageManagerWorkingDir = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
 | 
			
		||||
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getPackageManagerVersion = exports.getPackageManagerWorkingDir = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
 | 
			
		||||
const core = __importStar(__nccwpck_require__(2186));
 | 
			
		||||
const exec = __importStar(__nccwpck_require__(1514));
 | 
			
		||||
const cache = __importStar(__nccwpck_require__(7799));
 | 
			
		||||
@ -59298,6 +59298,7 @@ const getPackageManagerVersion = (packageManager, command) => __awaiter(void 0,
 | 
			
		||||
    }
 | 
			
		||||
    return stdOut;
 | 
			
		||||
});
 | 
			
		||||
exports.getPackageManagerVersion = getPackageManagerVersion;
 | 
			
		||||
const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
 | 
			
		||||
    if (packageManager === 'npm') {
 | 
			
		||||
        return exports.supportedPackageManagers.npm;
 | 
			
		||||
@ -59306,7 +59307,7 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
 | 
			
		||||
        return exports.supportedPackageManagers.pnpm;
 | 
			
		||||
    }
 | 
			
		||||
    else if (packageManager === 'yarn') {
 | 
			
		||||
        const yarnVersion = yield getPackageManagerVersion('yarn', '--version');
 | 
			
		||||
        const yarnVersion = yield exports.getPackageManagerVersion('yarn', '--version');
 | 
			
		||||
        core.debug(`Consumed yarn version is ${yarnVersion}`);
 | 
			
		||||
        if (yarnVersion.startsWith('1.')) {
 | 
			
		||||
            return exports.supportedPackageManagers.yarn1;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										5
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							@ -71216,7 +71216,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.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getPackageManagerWorkingDir = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
 | 
			
		||||
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getPackageManagerVersion = exports.getPackageManagerWorkingDir = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
 | 
			
		||||
const core = __importStar(__nccwpck_require__(2186));
 | 
			
		||||
const exec = __importStar(__nccwpck_require__(1514));
 | 
			
		||||
const cache = __importStar(__nccwpck_require__(7799));
 | 
			
		||||
@ -71266,6 +71266,7 @@ const getPackageManagerVersion = (packageManager, command) => __awaiter(void 0,
 | 
			
		||||
    }
 | 
			
		||||
    return stdOut;
 | 
			
		||||
});
 | 
			
		||||
exports.getPackageManagerVersion = getPackageManagerVersion;
 | 
			
		||||
const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
 | 
			
		||||
    if (packageManager === 'npm') {
 | 
			
		||||
        return exports.supportedPackageManagers.npm;
 | 
			
		||||
@ -71274,7 +71275,7 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
 | 
			
		||||
        return exports.supportedPackageManagers.pnpm;
 | 
			
		||||
    }
 | 
			
		||||
    else if (packageManager === 'yarn') {
 | 
			
		||||
        const yarnVersion = yield getPackageManagerVersion('yarn', '--version');
 | 
			
		||||
        const yarnVersion = yield exports.getPackageManagerVersion('yarn', '--version');
 | 
			
		||||
        core.debug(`Consumed yarn version is ${yarnVersion}`);
 | 
			
		||||
        if (yarnVersion.startsWith('1.')) {
 | 
			
		||||
            return exports.supportedPackageManagers.yarn1;
 | 
			
		||||
 | 
			
		||||
@ -61,7 +61,7 @@ export const getPackageManagerWorkingDir = (): string | null => {
 | 
			
		||||
  return cacheDependencyPath ? path.dirname(cacheDependencyPath) : null;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const getPackageManagerVersion = async (
 | 
			
		||||
export const getPackageManagerVersion = async (
 | 
			
		||||
  packageManager: string,
 | 
			
		||||
  command: string
 | 
			
		||||
) => {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user