mirror of
https://github.com/actions/setup-node.git
synced 2025-07-01 23:23:47 +00:00
Allow reading 'package.json' as node-version-file
This commit is contained in:
parent
2fddd8803e
commit
7d279e1d70
3 changed files with 50 additions and 8 deletions
5
__tests__/data/package.json
Normal file
5
__tests__/data/package.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
}
|
||||
}
|
|
@ -591,6 +591,35 @@ describe('setup-node', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('reads package.json as node-version-file if provided', async () => {
|
||||
// Arrange
|
||||
const versionSpec = `{
|
||||
\"engines\": {
|
||||
\"node\": \">=14.0.0\"
|
||||
}
|
||||
}
|
||||
`;
|
||||
const versionFile = 'package.json';
|
||||
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)
|
||||
);
|
||||
// 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('both node-version-file and node-version are provided', async () => {
|
||||
inputs['node-version'] = '12';
|
||||
const versionSpec = 'v14';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue