Skip to content

Commit

Permalink
Test coverage for uknown and malformed aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordey Doronin committed Jun 17, 2021
1 parent c8889b2 commit fa68745
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,8 @@ describe('setup-node', () => {
await main.run();

// assert
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...');
expect(warningSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true')
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...');
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias 'erbium' for Node version 'lts/erbium'`)
expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '12.16.2' for Node version 'lts/erbium'`)
expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'");
Expand All @@ -577,8 +577,8 @@ describe('setup-node', () => {
await main.run();

// assert
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...');
expect(warningSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true')
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...');
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias 'erbium' for Node version 'lts/erbium'`)
expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '12.16.2' for Node version 'lts/erbium'`)
expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'");
Expand All @@ -604,8 +604,8 @@ describe('setup-node', () => {
await main.run();

// assert
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...');
expect(warningSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true')
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...');
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias '*' for Node version 'lts/*'`)
expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '14.0.0' for Node version 'lts/*'`)
expect(logSpy).toHaveBeenCalledWith("Resolved as '14.0.0'");
Expand All @@ -632,8 +632,8 @@ describe('setup-node', () => {
await main.run();

// assert
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...');
expect(warningSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true')
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...');
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias '*' for Node version 'lts/*'`)
expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '14.0.0' for Node version 'lts/*'`)
expect(logSpy).toHaveBeenCalledWith("Resolved as '14.0.0'");
Expand All @@ -643,5 +643,50 @@ describe('setup-node', () => {
expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...');
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${toolPath}/bin${osm.EOL}`);
})

it('fail with unexpected LTS alias (lts/)', async () => {
// arrange
os.platform = 'linux';
os.arch = 'x64';

inputs['node-version'] = 'lts/';
inputs.stable = 'true';

findSpy.mockImplementation(() => '');

// act
await main.run();

// assert
expect(warningSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true')
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...');
expect(logSpy).toHaveBeenCalledWith('Unable to resolve version from manifest...');
expect(dbgSpy).toHaveBeenCalledWith(`Unexpected LTS alias '' for Node version 'lts/'`)
expect(logSpy).toHaveBeenCalledWith('Failed to resolve version lts/ from manifest');
expect(cnSpy).toHaveBeenCalledWith(`::error::Unable to find Node version 'lts/' for platform linux and architecture x64.${osm.EOL}`);
});

it('fail to find LTS version (lts/unknown)', async () => {
// arrange
os.platform = 'linux';
os.arch = 'x64';

inputs['node-version'] = 'lts/unknown';
inputs.stable = 'true';

findSpy.mockImplementation(() => '');

// act
await main.run();

// assert
expect(warningSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true')
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...');
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias 'unknown' for Node version 'lts/unknown'`)
expect(logSpy).toHaveBeenCalledWith('Unable to resolve version from manifest...');
expect(dbgSpy).toHaveBeenCalledWith(`Unable to find LTS release 'unknown' for Node version 'lts/unknown'.`)
expect(logSpy).toHaveBeenCalledWith('Failed to resolve version lts/unknown from manifest');
expect(cnSpy).toHaveBeenCalledWith(`::error::Unable to find Node version 'lts/unknown' for platform linux and architecture x64.${osm.EOL}`);
});
})
});

0 comments on commit fa68745

Please sign in to comment.