add unit tests

This commit is contained in:
panticmilos 2022-04-27 17:28:52 +02:00
parent 983e751c52
commit fdd541042b
2 changed files with 48 additions and 6 deletions

View file

@ -909,4 +909,44 @@ describe('setup-node', () => {
);
});
});
describe('latest alias syntax', () => {
it.each(['latest', 'current', 'node'])('download the %s version if alias is provided', async (inputVersion) => {
// Arrange
inputs['node-version'] = inputVersion;
os.platform = 'darwin';
os.arch = 'x64';
const expectedVersion = nodeTestDist[0];
let expectedUrl = `https://nodejs.org/dist/${expectedVersion.version}/node-${expectedVersion.version}-${os.platform}-${os.arch}.tar.gz`;
findSpy.mockImplementation(() => '');
getManifestSpy.mockImplementation(() => {
throw new Error('Unable to download manifest');
});
// Act
await main.run();
// Assert
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download ${inputVersion}...`
);
expect(logSpy).toHaveBeenCalledWith(
'Unable to download manifest'
);
expect(logSpy).toHaveBeenCalledWith(
'getting latest node version...'
);
expect(logSpy).toHaveBeenCalledWith(
`Acquiring ${expectedVersion.version.substring(1, expectedVersion.version.length)} - ${os.arch} from ${expectedUrl}`
);
});
});
});