mirror of
				https://github.com/actions/setup-node.git
				synced 2025-11-04 01:33:33 +00:00 
			
		
		
		
	Test output
This commit is contained in:
		
							parent
							
								
									2a814b57e1
								
							
						
					
					
						commit
						8ba370a949
					
				@ -41,6 +41,7 @@ describe('setup-node', () => {
 | 
				
			|||||||
  let parseNodeVersionSpy: jest.SpyInstance;
 | 
					  let parseNodeVersionSpy: jest.SpyInstance;
 | 
				
			||||||
  let isCacheActionAvailable: jest.SpyInstance;
 | 
					  let isCacheActionAvailable: jest.SpyInstance;
 | 
				
			||||||
  let getExecOutputSpy: jest.SpyInstance;
 | 
					  let getExecOutputSpy: jest.SpyInstance;
 | 
				
			||||||
 | 
					  let execExecSpy: jest.SpyInstance;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  beforeEach(() => {
 | 
					  beforeEach(() => {
 | 
				
			||||||
    // @actions/core
 | 
					    // @actions/core
 | 
				
			||||||
@ -57,6 +58,7 @@ describe('setup-node', () => {
 | 
				
			|||||||
    archSpy = jest.spyOn(osm, 'arch');
 | 
					    archSpy = jest.spyOn(osm, 'arch');
 | 
				
			||||||
    archSpy.mockImplementation(() => os['arch']);
 | 
					    archSpy.mockImplementation(() => os['arch']);
 | 
				
			||||||
    execSpy = jest.spyOn(cp, 'execSync');
 | 
					    execSpy = jest.spyOn(cp, 'execSync');
 | 
				
			||||||
 | 
					    execExecSpy = jest.spyOn(exec, 'exec');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // @actions/tool-cache
 | 
					    // @actions/tool-cache
 | 
				
			||||||
    findSpy = jest.spyOn(tc, 'find');
 | 
					    findSpy = jest.spyOn(tc, 'find');
 | 
				
			||||||
@ -249,6 +251,10 @@ describe('setup-node', () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    let expPath = path.join(toolPath, 'bin');
 | 
					    let expPath = path.join(toolPath, 'bin');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    expect(execExecSpy).toHaveBeenCalledWith('node', ['--version']);
 | 
				
			||||||
 | 
					    expect(execExecSpy).toHaveBeenCalledWith('npm', ['--version'], expect.anything());
 | 
				
			||||||
 | 
					    expect(execExecSpy).toHaveBeenCalledWith('yarn', ['--version'], expect.anything());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    expect(dlSpy).toHaveBeenCalled();
 | 
					    expect(dlSpy).toHaveBeenCalled();
 | 
				
			||||||
    expect(exSpy).toHaveBeenCalled();
 | 
					    expect(exSpy).toHaveBeenCalled();
 | 
				
			||||||
    expect(logSpy).toHaveBeenCalledWith(
 | 
					    expect(logSpy).toHaveBeenCalledWith(
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										40
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								src/main.ts
									
									
									
									
									
								
							@ -6,6 +6,7 @@ import * as auth from './authutil';
 | 
				
			|||||||
import * as path from 'path';
 | 
					import * as path from 'path';
 | 
				
			||||||
import {restoreCache} from './cache-restore';
 | 
					import {restoreCache} from './cache-restore';
 | 
				
			||||||
import {isGhes, isCacheFeatureAvailable} from './cache-utils';
 | 
					import {isGhes, isCacheFeatureAvailable} from './cache-utils';
 | 
				
			||||||
 | 
					import { URL } from 'url';
 | 
				
			||||||
import os = require('os');
 | 
					import os = require('os');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export async function run() {
 | 
					export async function run() {
 | 
				
			||||||
@ -40,17 +41,7 @@ export async function run() {
 | 
				
			|||||||
      await installer.getNode(version, stable, checkLatest, auth, arch);
 | 
					      await installer.getNode(version, stable, checkLatest, auth, arch);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Output version of node is being used
 | 
					    await printEnvDetailsAndSetOutput();
 | 
				
			||||||
    try {
 | 
					 | 
				
			||||||
      const {stdout: installedVersion} = await exec.getExecOutput(
 | 
					 | 
				
			||||||
        'node',
 | 
					 | 
				
			||||||
        ['--version'],
 | 
					 | 
				
			||||||
        {ignoreReturnCode: true, silent: true}
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
      core.setOutput('node-version', installedVersion.trim());
 | 
					 | 
				
			||||||
    } catch (err) {
 | 
					 | 
				
			||||||
      core.setOutput('node-version', '');
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const registryUrl: string = core.getInput('registry-url');
 | 
					    const registryUrl: string = core.getInput('registry-url');
 | 
				
			||||||
    const alwaysAuth: string = core.getInput('always-auth');
 | 
					    const alwaysAuth: string = core.getInput('always-auth');
 | 
				
			||||||
@ -108,3 +99,30 @@ function resolveVersionInput(): string {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  return version;
 | 
					  return version;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async function printEnvDetailsAndSetOutput() {
 | 
				
			||||||
 | 
					  const groupName = "Environment details";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  core.startGroup(groupName);
 | 
				
			||||||
 | 
					  // Output version of node is being used
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    const {stdout: installedNodeVersion} = await exec.getExecOutput(
 | 
				
			||||||
 | 
					      'node',
 | 
				
			||||||
 | 
					      ['--version'],
 | 
				
			||||||
 | 
					      {ignoreReturnCode: true}
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    core.setOutput('node-version', installedNodeVersion.trim());
 | 
				
			||||||
 | 
					  } catch (err) {
 | 
				
			||||||
 | 
					    core.setOutput('node-version', '');
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  await exec.getExecOutput('npm', ['--version'], {
 | 
				
			||||||
 | 
					    ignoreReturnCode: true
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  await exec.getExecOutput('yarn', ['--version'], {
 | 
				
			||||||
 | 
					    ignoreReturnCode: true
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  core.endGroup(groupName);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user