From 57cec77d94c8910e67960b27121ac8f968c37ccc Mon Sep 17 00:00:00 2001 From: Jef LeCompte Date: Wed, 27 Jul 2022 14:25:39 -0700 Subject: [PATCH] refactor: volta check --- __tests__/data/package.json | 3 +++ __tests__/installer.test.ts | 28 ---------------------------- src/installer.ts | 2 +- 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/__tests__/data/package.json b/__tests__/data/package.json index e537e200..34063c3a 100644 --- a/__tests__/data/package.json +++ b/__tests__/data/package.json @@ -1,5 +1,8 @@ { "engines": { "node": ">=14.0.0" + }, + "volta": { + "node": "14.0.0" } } diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index cb6bdbe2..b21674f3 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -592,34 +592,6 @@ describe('setup-node', () => { ); }); - it('reads node-version-file if provided (package.json, volta)', async () => { - // Arrange - const versionFile = 'package.json'; - const versionSpec = fs.readFileSync( - path.join(__dirname, 'data', versionFile), - 'utf8' - ); - const expectedVersionSpec = '16.15.1'; - process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data'); - inputs['node-version-file'] = versionFile; - - parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec); - existsSpy.mockImplementationOnce( - input => input === path.join(__dirname, 'data', versionFile) - ); - - // Act - await main.run(); - - // Assert - expect(existsSpy).toHaveBeenCalledTimes(1); - expect(existsSpy).toHaveReturnedWith(true); - expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec); - expect(logSpy).toHaveBeenCalledWith( - `Resolved ${versionFile} as ${expectedVersionSpec}` - ); - }); - it('reads package.json as node-version-file if provided', async () => { // Arrange const versionSpec = fs.readFileSync( diff --git a/src/installer.ts b/src/installer.ts index 193ff16a..028ecb80 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -505,7 +505,7 @@ export function parseNodeVersionFile(contents: string): string { // Try parsing the file as an NPM `package.json` // file. nodeVersion = JSON.parse(contents).engines?.node; - + if (!nodeVersion) JSON.parse(contents).volta?.node; if (!nodeVersion) throw new Error(); } catch (err) { // In the case of an unknown format,