Add unit-test

This commit is contained in:
IvanZosimov 2022-09-28 14:35:29 +02:00
parent b74b8e018a
commit 1d0f2c615d

View File

@ -21,9 +21,12 @@ if (IS_WINDOWS) {
const tempDir = path.join(__dirname, 'runner', 'temp2'); const tempDir = path.join(__dirname, 'runner', 'temp2');
describe('setup-dotnet tests', () => { describe('setup-dotnet tests', () => {
let getInputSpy = jest.spyOn(core, 'getInput');
let getMultilineInputSpy = jest.spyOn(core, 'getMultilineInput'); let getMultilineInputSpy = jest.spyOn(core, 'getMultilineInput');
let setOutputSpy = jest.spyOn(core, 'setOutput'); let setOutputSpy = jest.spyOn(core, 'setOutput');
let inputs = {} as any;
beforeAll(async () => { beforeAll(async () => {
process.env.RUNNER_TOOL_CACHE = toolDir; process.env.RUNNER_TOOL_CACHE = toolDir;
process.env.DOTNET_INSTALL_DIR = toolDir; process.env.DOTNET_INSTALL_DIR = toolDir;
@ -64,15 +67,32 @@ describe('setup-dotnet tests', () => {
} }
}, 400000); }, 400000);
it('Sets output with the latest installed by action version', async () => { it("Sets output with the latest installed by action version if global.json file isn't specified", async () => {
const versions = ['3.1.201', '6.0.401']; inputs['dotnet-version'] = ['3.1.201', '6.0.401'];
getMultilineInputSpy.mockImplementation(() => { getMultilineInputSpy.mockImplementation(input => inputs[input]);
return versions;
});
await setup.run(); await setup.run();
expect(setOutputSpy).toBeCalledWith('dotnet-version', '6.0.401'); expect(setOutputSpy).toBeCalledWith('dotnet-version', '6.0.401');
}, 400000); }, 400000);
it("Sets output with the version specified in global.json, if it's present", async () => {
const globalJsonPath = path.join(process.cwd(), 'global.json');
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.0.103"${os.EOL}}${os.EOL}}`;
if (!fs.existsSync(globalJsonPath)) {
fs.writeFileSync(globalJsonPath, jsonContents);
}
inputs['dotnet-version'] = ['3.1.201', '6.0.401'];
inputs['global-json-file'] = globalJsonPath;
getMultilineInputSpy.mockImplementation(input => inputs[input]);
getInputSpy.mockImplementation(input => inputs[input]);
await setup.run();
expect(setOutputSpy).toBeCalledWith('dotnet-version', '3.0.103');
}, 400000);
}); });