mirror of
https://github.com/actions/setup-node
synced 2024-12-22 13:12:43 +00:00
refactor: volta check
This commit is contained in:
parent
5a01179c35
commit
57cec77d94
3 changed files with 4 additions and 29 deletions
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14.0.0"
|
"node": ">=14.0.0"
|
||||||
|
},
|
||||||
|
"volta": {
|
||||||
|
"node": "14.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 () => {
|
it('reads package.json as node-version-file if provided', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const versionSpec = fs.readFileSync(
|
const versionSpec = fs.readFileSync(
|
||||||
|
|
|
@ -505,7 +505,7 @@ export function parseNodeVersionFile(contents: string): string {
|
||||||
// Try parsing the file as an NPM `package.json`
|
// Try parsing the file as an NPM `package.json`
|
||||||
// file.
|
// file.
|
||||||
nodeVersion = JSON.parse(contents).engines?.node;
|
nodeVersion = JSON.parse(contents).engines?.node;
|
||||||
|
if (!nodeVersion) JSON.parse(contents).volta?.node;
|
||||||
if (!nodeVersion) throw new Error();
|
if (!nodeVersion) throw new Error();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// In the case of an unknown format,
|
// In the case of an unknown format,
|
||||||
|
|
Loading…
Reference in a new issue