fix: pr review adjustments
parent
c871b9da45
commit
c73bf9098a
|
@ -11,6 +11,7 @@ import each from 'jest-each';
|
|||
|
||||
import * as main from '../src/main';
|
||||
import * as util from '../src/util';
|
||||
import * as cacheUtil from '../src/cache-utils';
|
||||
import OfficialBuilds from '../src/distributions/official_builds/official_builds';
|
||||
|
||||
describe('main tests', () => {
|
||||
|
@ -25,6 +26,7 @@ describe('main tests', () => {
|
|||
let endGroupSpy: jest.SpyInstance;
|
||||
|
||||
let getExecOutputSpy: jest.SpyInstance;
|
||||
let getCommandOutputSpy: jest.SpyInstance;
|
||||
|
||||
let getNodeVersionFromFileSpy: jest.SpyInstance;
|
||||
let cnSpy: jest.SpyInstance;
|
||||
|
@ -56,6 +58,7 @@ describe('main tests', () => {
|
|||
inSpy.mockImplementation(name => inputs[name]);
|
||||
|
||||
getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
|
||||
getCommandOutputSpy = jest.spyOn(cacheUtil, 'getCommandOutput');
|
||||
|
||||
findSpy = jest.spyOn(tc, 'find');
|
||||
|
||||
|
@ -274,50 +277,32 @@ describe('main tests', () => {
|
|||
it('should not enable corepack when no input', async () => {
|
||||
inputs['corepack'] = '';
|
||||
await main.run();
|
||||
expect(getExecOutputSpy).not.toHaveBeenCalledWith(
|
||||
'corepack',
|
||||
expect.anything(),
|
||||
expect.anything()
|
||||
);
|
||||
expect(getCommandOutputSpy).not.toHaveBeenCalledWith('corepack');
|
||||
});
|
||||
|
||||
it('should not enable corepack when input is "false"', async () => {
|
||||
inputs['corepack'] = 'false';
|
||||
await main.run();
|
||||
expect(getExecOutputSpy).not.toHaveBeenCalledWith(
|
||||
'corepack',
|
||||
expect.anything(),
|
||||
expect.anything()
|
||||
);
|
||||
expect(getCommandOutputSpy).not.toHaveBeenCalledWith('corepack');
|
||||
});
|
||||
|
||||
it('should enable corepack when input is "true"', async () => {
|
||||
inputs['corepack'] = 'true';
|
||||
await main.run();
|
||||
expect(getExecOutputSpy).toHaveBeenCalledWith(
|
||||
'corepack',
|
||||
['enable'],
|
||||
expect.anything()
|
||||
);
|
||||
expect(getCommandOutputSpy).toHaveBeenCalledWith('corepack enable');
|
||||
});
|
||||
|
||||
it('should enable corepack with a single package manager', async () => {
|
||||
inputs['corepack'] = 'npm';
|
||||
await main.run();
|
||||
expect(getExecOutputSpy).toHaveBeenCalledWith(
|
||||
'corepack',
|
||||
['enable', 'npm'],
|
||||
expect.anything()
|
||||
);
|
||||
expect(getCommandOutputSpy).toHaveBeenCalledWith('corepack enable npm');
|
||||
});
|
||||
|
||||
it('should enable corepack with multiple package managers', async () => {
|
||||
inputs['corepack'] = 'npm yarn';
|
||||
await main.run();
|
||||
expect(getExecOutputSpy).toHaveBeenCalledWith(
|
||||
'corepack',
|
||||
['enable', 'npm', 'yarn'],
|
||||
expect.anything()
|
||||
expect(getCommandOutputSpy).toHaveBeenCalledWith(
|
||||
'corepack enable npm yarn'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -83338,6 +83338,7 @@ const core = __importStar(__nccwpck_require__(2186));
|
|||
const exec = __importStar(__nccwpck_require__(1514));
|
||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||
const cache_utils_1 = __nccwpck_require__(1678);
|
||||
function getNodeVersionFromFile(versionFilePath) {
|
||||
var _a, _b, _c, _d, _e;
|
||||
if (!fs_1.default.existsSync(versionFilePath)) {
|
||||
|
@ -83431,15 +83432,13 @@ const unique = () => {
|
|||
exports.unique = unique;
|
||||
function enableCorepack(input) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const corepackArgs = ['enable'];
|
||||
if (input.length > 0 && input !== 'false') {
|
||||
if (input.length && input !== 'false') {
|
||||
const corepackArgs = ['enable'];
|
||||
if (input !== 'true') {
|
||||
const packageManagers = input.split(' ');
|
||||
corepackArgs.push(...packageManagers);
|
||||
}
|
||||
yield exec.getExecOutput('corepack', corepackArgs, {
|
||||
ignoreReturnCode: true
|
||||
});
|
||||
yield (0, cache_utils_1.getCommandOutput)(`corepack ${corepackArgs.join(' ')}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -93787,6 +93787,7 @@ const core = __importStar(__nccwpck_require__(2186));
|
|||
const exec = __importStar(__nccwpck_require__(1514));
|
||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||
const cache_utils_1 = __nccwpck_require__(1678);
|
||||
function getNodeVersionFromFile(versionFilePath) {
|
||||
var _a, _b, _c, _d, _e;
|
||||
if (!fs_1.default.existsSync(versionFilePath)) {
|
||||
|
@ -93880,15 +93881,13 @@ const unique = () => {
|
|||
exports.unique = unique;
|
||||
function enableCorepack(input) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const corepackArgs = ['enable'];
|
||||
if (input.length > 0 && input !== 'false') {
|
||||
if (input.length && input !== 'false') {
|
||||
const corepackArgs = ['enable'];
|
||||
if (input !== 'true') {
|
||||
const packageManagers = input.split(' ');
|
||||
corepackArgs.push(...packageManagers);
|
||||
}
|
||||
yield exec.getExecOutput('corepack', corepackArgs, {
|
||||
ignoreReturnCode: true
|
||||
});
|
||||
yield (0, cache_utils_1.getCommandOutput)(`corepack ${corepackArgs.join(' ')}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import * as exec from '@actions/exec';
|
|||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {getCommandOutput} from './cache-utils';
|
||||
|
||||
export function getNodeVersionFromFile(versionFilePath: string): string | null {
|
||||
if (!fs.existsSync(versionFilePath)) {
|
||||
|
@ -107,14 +108,12 @@ export const unique = () => {
|
|||
};
|
||||
|
||||
export async function enableCorepack(input: string): Promise<void> {
|
||||
const corepackArgs = ['enable'];
|
||||
if (input.length > 0 && input !== 'false') {
|
||||
if (input.length && input !== 'false') {
|
||||
const corepackArgs = ['enable'];
|
||||
if (input !== 'true') {
|
||||
const packageManagers = input.split(' ');
|
||||
corepackArgs.push(...packageManagers);
|
||||
}
|
||||
await exec.getExecOutput('corepack', corepackArgs, {
|
||||
ignoreReturnCode: true
|
||||
});
|
||||
await getCommandOutput(`corepack ${corepackArgs.join(' ')}`);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue