Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
apply prettier
  • Loading branch information
panticmilos committed May 4, 2022
commit 9d287779163e0be81bedb4f6e6a88d98c555b893
57 changes: 29 additions & 28 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,42 +911,43 @@ 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';
it.each(['latest', 'current', 'node'])(
'download the %s version if alias is provided',
async inputVersion => {
// Arrange
inputs['node-version'] = inputVersion;

const expectedVersion = nodeTestDist[0];
os.platform = 'darwin';
os.arch = 'x64';

let expectedUrl = `https://nodejs.org/dist/${expectedVersion.version}/node-${expectedVersion.version}-${os.platform}-${os.arch}.tar.gz`;
const expectedVersion = nodeTestDist[0];

findSpy.mockImplementation(() => '');
getManifestSpy.mockImplementation(() => {
throw new Error('Unable to download manifest');
});
let expectedUrl = `https://nodejs.org/dist/${expectedVersion.version}/node-${expectedVersion.version}-${os.platform}-${os.arch}.tar.gz`;

// Act
await main.run();
findSpy.mockImplementation(() => '');
getManifestSpy.mockImplementation(() => {
throw new Error('Unable to download manifest');
});

// Assert
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download ${inputVersion}...`
);
// Act
await main.run();

expect(logSpy).toHaveBeenCalledWith(
'Unable to download manifest'
);
// Assert
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download ${inputVersion}...`
);

expect(logSpy).toHaveBeenCalledWith(
'getting latest node version...'
);
expect(logSpy).toHaveBeenCalledWith('Unable to download manifest');

expect(logSpy).toHaveBeenCalledWith(
`Acquiring ${expectedVersion.version.substring(1, expectedVersion.version.length)} - ${os.arch} from ${expectedUrl}`
);
expect(logSpy).toHaveBeenCalledWith('getting latest node version...');

});
expect(logSpy).toHaveBeenCalledWith(
`Acquiring ${expectedVersion.version.substring(
1,
expectedVersion.version.length
)} - ${os.arch} from ${expectedUrl}`
);
}
);
});
});
6 changes: 5 additions & 1 deletion src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,11 @@ async function queryDistForMatch(
let versions: string[] = [];
let nodeVersions = await installer.getVersionsFromDist();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we omit the import statement above, we can omit that also:

Suggested change
let nodeVersions = await installer.getVersionsFromDist();
let nodeVersions = await getVersionsFromDist();


if (versionSpec === 'current' || versionSpec === 'latest' || versionSpec === 'node') {
if (
versionSpec === 'current' ||
versionSpec === 'latest' ||
versionSpec === 'node'
) {
core.info(`getting latest node version...`);
return nodeVersions[0].version;
}
Expand Down