forked from actions/setup-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'actions:main' into main
- Loading branch information
Showing
10 changed files
with
197 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"volta": { | ||
"extends": "./package-volta.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"engines": { | ||
"node": "^14.0.0" | ||
}, | ||
"volta": { | ||
"node": "16.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
{ | ||
"engines": { | ||
"node": "^14.0.0" | ||
}, | ||
"volta": { | ||
"node": "16.0.0" | ||
} | ||
} | ||
This comment has been minimized.
Sorry, something went wrong. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,11 +24,9 @@ describe('main tests', () => { | |
let startGroupSpy: jest.SpyInstance; | ||
let endGroupSpy: jest.SpyInstance; | ||
|
||
let existsSpy: jest.SpyInstance; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
drvarunpant
|
||
|
||
let getExecOutputSpy: jest.SpyInstance; | ||
|
||
This comment has been minimized.
Sorry, something went wrong. |
||
let parseNodeVersionSpy: jest.SpyInstance; | ||
let getNodeVersionFromFileSpy: jest.SpyInstance; | ||
let cnSpy: jest.SpyInstance; | ||
let findSpy: jest.SpyInstance; | ||
let isCacheActionAvailable: jest.SpyInstance; | ||
|
@@ -41,6 +39,7 @@ describe('main tests', () => { | |
// node | ||
os = {}; | ||
console.log('::stop-commands::stoptoken'); | ||
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data'); | ||
process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out | ||
process.env['GITHUB_OUTPUT'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out | ||
infoSpy = jest.spyOn(core, 'info'); | ||
|
@@ -62,12 +61,10 @@ describe('main tests', () => { | |
|
||
isCacheActionAvailable = jest.spyOn(cache, 'isFeatureAvailable'); | ||
|
||
existsSpy = jest.spyOn(fs, 'existsSync'); | ||
|
||
cnSpy = jest.spyOn(process.stdout, 'write'); | ||
cnSpy.mockImplementation(line => { | ||
// uncomment to debug | ||
// process.stderr.write('write:' + line + '\n'); | ||
process.stderr.write('write:' + line + '\n'); | ||
}); | ||
|
||
setupNodeJsSpy = jest.spyOn(OfficialBuilds.prototype, 'setupNodeJs'); | ||
|
@@ -85,7 +82,7 @@ describe('main tests', () => { | |
jest.restoreAllMocks(); | ||
}, 100000); | ||
|
||
describe('parseNodeVersionFile', () => { | ||
describe('getNodeVersionFromFile', () => { | ||
each` | ||
contents | expected | ||
${'12'} | ${'12'} | ||
|
@@ -100,10 +97,27 @@ describe('main tests', () => { | |
${'unknown format'} | ${'unknown format'} | ||
${' 14.1.0 '} | ${'14.1.0'} | ||
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'} | ||
${'{"volta": {"extends": "./package.json"}}'}| ${'18.0.0'} | ||
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'} | ||
${'{}'} | ${null} | ||
`.it('parses "$contents"', ({contents, expected}) => { | ||
expect(util.parseNodeVersionFile(contents)).toBe(expected); | ||
const existsSpy = jest.spyOn(fs, 'existsSync'); | ||
existsSpy.mockImplementation(() => true); | ||
|
||
const readFileSpy = jest.spyOn(fs, 'readFileSync'); | ||
readFileSpy.mockImplementation(filePath => { | ||
if ( | ||
typeof filePath === 'string' && | ||
path.basename(filePath) === 'package.json' | ||
) { | ||
// Special case for volta.extends | ||
return '{"volta": {"node": "18.0.0"}}'; | ||
} | ||
|
||
return contents; | ||
}); | ||
|
||
expect(util.getNodeVersionFromFile('file')).toBe(expected); | ||
}); | ||
}); | ||
|
||
|
@@ -142,118 +156,72 @@ describe('main tests', () => { | |
|
||
describe('node-version-file flag', () => { | ||
beforeEach(() => { | ||
parseNodeVersionSpy = jest.spyOn(util, 'parseNodeVersionFile'); | ||
delete inputs['node-version']; | ||
inputs['node-version-file'] = '.nvmrc'; | ||
|
||
getNodeVersionFromFileSpy = jest.spyOn(util, 'getNodeVersionFromFile'); | ||
}); | ||
|
||
afterEach(() => { | ||
getNodeVersionFromFileSpy.mockRestore(); | ||
}); | ||
|
||
it('not used if node-version is provided', async () => { | ||
it('does not read node-version-file if node-version is provided', async () => { | ||
// Arrange | ||
inputs['node-version'] = '12'; | ||
|
||
// Act | ||
await main.run(); | ||
|
||
// Assert | ||
expect(parseNodeVersionSpy).toHaveBeenCalledTimes(0); | ||
}, 10000); | ||
|
||
it('not used if node-version-file not provided', async () => { | ||
// Act | ||
await main.run(); | ||
|
||
// Assert | ||
expect(parseNodeVersionSpy).toHaveBeenCalledTimes(0); | ||
expect(inputs['node-version']).toBeDefined(); | ||
expect(inputs['node-version-file']).toBeDefined(); | ||
expect(getNodeVersionFromFileSpy).not.toHaveBeenCalled(); | ||
expect(warningSpy).toHaveBeenCalledWith( | ||
'Both node-version and node-version-file inputs are specified, only node-version will be used' | ||
); | ||
}); | ||
|
||
it('reads node-version-file if provided', async () => { | ||
it('does not read node-version-file if node-version-file is not provided', async () => { | ||
// Arrange | ||
const versionSpec = 'v14'; | ||
const versionFile = '.nvmrc'; | ||
const expectedVersionSpec = '14'; | ||
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) | ||
); | ||
delete inputs['node-version-file']; | ||
|
||
// Act | ||
await main.run(); | ||
|
||
// Assert | ||
expect(existsSpy).toHaveBeenCalledTimes(1); | ||
expect(existsSpy).toHaveReturnedWith(true); | ||
expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec); | ||
expect(infoSpy).toHaveBeenCalledWith( | ||
`Resolved ${versionFile} as ${expectedVersionSpec}` | ||
); | ||
}, 10000); | ||
expect(getNodeVersionFromFileSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('reads package.json as node-version-file if provided', async () => { | ||
it('reads node-version-file', async () => { | ||
// Arrange | ||
const versionSpec = fs.readFileSync( | ||
path.join(__dirname, 'data/package.json'), | ||
'utf-8' | ||
); | ||
const versionFile = 'package.json'; | ||
const expectedVersionSpec = '14'; | ||
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data'); | ||
inputs['node-version-file'] = versionFile; | ||
getNodeVersionFromFileSpy.mockImplementation(() => expectedVersionSpec); | ||
|
||
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(getNodeVersionFromFileSpy).toHaveBeenCalled(); | ||
expect(infoSpy).toHaveBeenCalledWith( | ||
`Resolved ${versionFile} as ${expectedVersionSpec}` | ||
`Resolved ${inputs['node-version-file']} as ${expectedVersionSpec}` | ||
); | ||
}, 10000); | ||
|
||
it('both node-version-file and node-version are provided', async () => { | ||
inputs['node-version'] = '12'; | ||
const versionSpec = 'v14'; | ||
const versionFile = '.nvmrc'; | ||
const expectedVersionSpec = '14'; | ||
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, '..'); | ||
inputs['node-version-file'] = versionFile; | ||
|
||
parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec); | ||
|
||
// Act | ||
await main.run(); | ||
|
||
// Assert | ||
expect(existsSpy).toHaveBeenCalledTimes(0); | ||
expect(parseNodeVersionSpy).not.toHaveBeenCalled(); | ||
expect(warningSpy).toHaveBeenCalledWith( | ||
'Both node-version and node-version-file inputs are specified, only node-version will be used' | ||
); | ||
}); | ||
|
||
it('should throw an error if node-version-file is not found', async () => { | ||
const versionFile = '.nvmrc'; | ||
const versionFilePath = path.join(__dirname, '..', versionFile); | ||
inputs['node-version-file'] = versionFile; | ||
|
||
inSpy.mockImplementation(name => inputs[name]); | ||
existsSpy.mockImplementationOnce( | ||
input => input === path.join(__dirname, 'data', versionFile) | ||
it('should throw an error if node-version-file is not accessible', async () => { | ||
// Arrange | ||
inputs['node-version-file'] = 'non-existing-file'; | ||
const versionFilePath = path.join( | ||
__dirname, | ||
'data', | ||
inputs['node-version-file'] | ||
); | ||
|
||
// Act | ||
await main.run(); | ||
|
||
// Assert | ||
expect(existsSpy).toHaveBeenCalled(); | ||
expect(existsSpy).toHaveReturnedWith(false); | ||
expect(parseNodeVersionSpy).not.toHaveBeenCalled(); | ||
expect(getNodeVersionFromFileSpy).toHaveBeenCalled(); | ||
expect(cnSpy).toHaveBeenCalledWith( | ||
`::error::The specified node version file at: ${versionFilePath} does not exist${osm.EOL}` | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Indentation error