From df568f01a84c5643dbcccca0149f1431a73e0449 Mon Sep 17 00:00:00 2001 From: Ben Sterling <25365573+ben-styling@users.noreply.github.com> Date: Tue, 12 Jul 2022 16:47:26 +0100 Subject: [PATCH] fix tests --- __tests__/installer.test.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 3d44c158..3b019e8c 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -109,7 +109,7 @@ describe('setup-node', () => { // @actions/exec getExecOutputSpy = jest.spyOn(exec, 'getExecOutput'); - getExecOutputSpy.mockImplementation(() => 'v16.15.0'); + getExecOutputSpy.mockImplementation(() => ({stdout: 'v12.16.1'})); }); afterEach(() => { @@ -205,24 +205,32 @@ describe('setup-node', () => { expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); }); - it('finds incorrect version in cache and adds it to the path', async () => { + it('finds incorrect version in cache, and adds correct version the path', async () => { + os.platform = 'linux'; + os.arch = 'x64'; + inputs['token'] = 'faketoken'; + let versionSpec = '12.16.2'; inputs['node-version'] = versionSpec; - inSpy.mockImplementation(name => inputs[name]); - getExecOutputSpy.mockImplementation(() => 'v12.0.0'); + let toolPath = path.normalize('/cache/node/12.16.2/x64'); + let expPath = path.join(toolPath, 'bin'); + + inSpy.mockImplementation(name => inputs[name]); + cacheSpy.mockImplementation(async () => toolPath); + getExecOutputSpy.mockReturnValueOnce({stdout: `v14.0.0`}); + findSpy.mockImplementationOnce(() => toolPath); + findSpy.mockImplementationOnce(() => ''); - let toolPath = path.normalize('/cache/node/12.16.1/x64'); - findSpy.mockImplementation(() => toolPath); await main.run(); - let expPath = path.join(toolPath, 'bin'); expect(logSpy).toHaveBeenCalledWith( - `Found v12.0.0 in cache @ ${toolPath} but it does not satisfy the requested version (${versionSpec})` + `Found v14.0.0 in cache @ ${toolPath} but it does not satisfy the requested version (12.16.2)` ); expect(logSpy).toHaveBeenCalledWith( `Attempting to download ${versionSpec}...` ); + expect(logSpy).toHaveBeenCalledWith(`Adding to the cache ...`); expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); }); @@ -716,6 +724,7 @@ describe('setup-node', () => { inputs['node-version'] = `lts/${lts}`; const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); + getExecOutputSpy.mockReturnValueOnce({stdout: `v${expectedVersion}`}); findSpy.mockReturnValue(toolPath); // act