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