Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mirror-url parameter to allow downloading Node.js from a custom URL #1232

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
test cases update
  • Loading branch information
aparnajyothi-y committed Feb 26, 2025
commit b903bc8693e1afe301d46d9e6da1b79271c2be62
76 changes: 74 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -173,7 +173,44 @@
});
});


describe('getNodeVersionFromFile', () => {

Check failure on line 176 in __tests__/main.test.ts

GitHub Actions / Basic validation / build (ubuntu-latest)

Describe block title is used multiple times in the same describe block

Check failure on line 176 in __tests__/main.test.ts

GitHub Actions / Basic validation / build (macos-latest)

Describe block title is used multiple times in the same describe block

Check failure on line 176 in __tests__/main.test.ts

GitHub Actions / Basic validation / build (windows-latest)

Describe block title is used multiple times in the same describe block
each`
contents | expected
${'12'} | ${'12'}
${'12.3'} | ${'12.3'}
${'12.3.4'} | ${'12.3.4'}
${'v12.3.4'} | ${'12.3.4'}
${'lts/erbium'} | ${'lts/erbium'}
${'lts/*'} | ${'lts/*'}
${'nodejs 12.3.4'} | ${'12.3.4'}
${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'}
${''} | ${''}
${'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}) => {
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);
});
});

describe('node-version-file flag', () => {
beforeEach(() => {
@@ -291,5 +328,40 @@
});
});


describe('mirror-url parameter', () => {
beforeEach(() => {
inputs['mirror-url'] = 'https://custom-mirror-url.com';

validateMirrorUrlSpy = jest.spyOn(main, 'run');
validateMirrorUrlSpy.mockImplementation(() => {});
});

afterEach(() => {
validateMirrorUrlSpy.mockRestore();
});

it('Read mirror-url if mirror-url is provided', async () => {
// Arrange
inputs['mirror-url'] = 'https://custom-mirror-url.com';

// Act
await main.run();

// Assert
expect(inputs['mirror-url']).toBeDefined();
});

it('should throw an error if mirror-url is empty', async () => {
// Arrange
inputs['mirror-url'] = ' ';

// Mock log and setFailed
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); // Mock the log function

// Act & Assert
expect(() => validateMirrorURL(inputs['mirror-url'])).toThrowError(

Check failure on line 362 in __tests__/main.test.ts

GitHub Actions / Basic validation / build (ubuntu-latest)

Replace toThrowError() with its canonical name of toThrow()

Check failure on line 362 in __tests__/main.test.ts

GitHub Actions / Basic validation / build (macos-latest)

Replace toThrowError() with its canonical name of toThrow()

Check failure on line 362 in __tests__/main.test.ts

GitHub Actions / Basic validation / build (windows-latest)

Replace toThrowError() with its canonical name of toThrow()
'Mirror URL is empty. Please provide a valid mirror URL.'
);
});
});
});
Loading
Oops, something went wrong.