From a03d9f05e4a9f94563f3a9adf502086290e91629 Mon Sep 17 00:00:00 2001 From: Jef LeCompte Date: Wed, 29 Jun 2022 12:28:21 -0700 Subject: [PATCH] test: add node-version-file test --- __tests__/data/package.json | 11 +++++++++++ __tests__/installer.test.ts | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 __tests__/data/package.json diff --git a/__tests__/data/package.json b/__tests__/data/package.json new file mode 100644 index 00000000..9fdc65e0 --- /dev/null +++ b/__tests__/data/package.json @@ -0,0 +1,11 @@ +{ + "name": "test", + "version": "1.0.0", + "private": true, + "scripts": { + "test": "echo test" + }, + "volta": { + "node": "16.15.1" + } +} diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 5a3ad553..5f72690d 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -584,6 +584,27 @@ describe('setup-node', () => { ); }); + it('reads node-version-file if provided with volta', async () => { + // Arrange + const expectedVersionSpec = '16.15.1'; + const versionFile = 'package.json'; + process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data'); + inputs['node-version-file'] = 'volta'; + + existsSpy.mockImplementationOnce( + input => input === path.join(__dirname, 'data', versionFile) + ); + // Act + await main.run(); + + // Assert + expect(existsSpy).toHaveBeenCalledTimes(1); + expect(existsSpy).toHaveReturnedWith(true); + expect(logSpy).toHaveBeenCalledWith( + `Resolved ${versionFile} as ${expectedVersionSpec}` + ); + }); + it('both node-version-file and node-version are provided', async () => { inputs['node-version'] = '12'; const versionSpec = 'v14';