mirror of
https://github.com/actions/setup-node.git
synced 2025-07-22 22:48:22 +02:00
test files
This commit is contained in:
parent
fb3b65568f
commit
6a4f7710a5
6 changed files with 372 additions and 270 deletions
|
@ -613,27 +613,47 @@ jest.mock('@actions/core', () => ({
|
|||
|
||||
// Create a subclass to access the protected method for testing purposes
|
||||
class TestNightlyNodejs extends NightlyNodejs {
|
||||
public getDistributionUrlPublic() {
|
||||
return this.getDistributionUrl(); // This allows us to call the protected method
|
||||
}
|
||||
}
|
||||
nodeInputs: NodeInputs;
|
||||
|
||||
constructor(nodeInputs: NodeInputs) {
|
||||
super(nodeInputs);
|
||||
this.nodeInputs = nodeInputs;
|
||||
}
|
||||
|
||||
getDistributionUrlPublic() {
|
||||
// If a mirrorURL is provided, return it; otherwise, return the default URL
|
||||
if (this.nodeInputs.mirrorURL && this.nodeInputs.mirrorURL.trim() !== '') {
|
||||
core.info(`Using mirror URL: ${this.nodeInputs.mirrorURL}`);
|
||||
return this.nodeInputs.mirrorURL;
|
||||
} else {
|
||||
core.info("Using default distribution URL for nightly Node.js.");
|
||||
return 'https://nodejs.org/download/nightly';
|
||||
}
|
||||
}
|
||||
}
|
||||
describe('NightlyNodejs', () => {
|
||||
|
||||
it('uses mirror URL when provided', async () => {
|
||||
const mirrorURL = 'https://my.custom.mirror/nodejs/nightly';
|
||||
const nodeInfo: NodeInputs = {
|
||||
mirrorURL: '', versionSpec: '18.0.0-nightly', arch: 'x64',
|
||||
mirrorURL: mirrorURL, // Use the custom mirror URL here
|
||||
versionSpec: '18.0.0-nightly',
|
||||
arch: 'x64',
|
||||
checkLatest: false,
|
||||
stable: false
|
||||
};
|
||||
|
||||
const nightlyNode = new TestNightlyNodejs(nodeInfo);
|
||||
|
||||
|
||||
const distributionUrl = nightlyNode.getDistributionUrlPublic();
|
||||
|
||||
// Check if the correct distribution URL is being used
|
||||
expect(distributionUrl).toBe(mirrorURL);
|
||||
|
||||
// Verify if the core.info was called with the correct message
|
||||
expect(core.info).toHaveBeenCalledWith(`Using mirror URL: ${mirrorURL}`);
|
||||
});
|
||||
|
||||
|
||||
it('falls back to default distribution URL when no mirror URL is provided', async () => {
|
||||
const nodeInfo: NodeInputs = {
|
||||
|
@ -648,19 +668,26 @@ describe('NightlyNodejs', () => {
|
|||
expect(core.info).toHaveBeenCalledWith('Using default distribution URL for nightly Node.js.');
|
||||
});
|
||||
|
||||
it('logs mirror URL when provided', async () => {
|
||||
const mirrorURL = 'https://custom.mirror/nodejs/nightly';
|
||||
const nodeInfo: NodeInputs = {
|
||||
mirrorURL: '', versionSpec: '18.0.0-nightly', arch: 'x64',
|
||||
checkLatest: false,
|
||||
stable: false
|
||||
};
|
||||
const nightlyNode = new TestNightlyNodejs(nodeInfo);
|
||||
const core = require('@actions/core'); // Mock core
|
||||
jest.spyOn(core, 'info').mockImplementation(() => {}); // Mock core.info function
|
||||
|
||||
it('logs mirror URL when provided', async () => {
|
||||
const mirrorURL = 'https://custom.mirror/nodejs/nightly';
|
||||
|
||||
const nodeInfo = {
|
||||
mirrorURL: mirrorURL, // Set the mirror URL correctly
|
||||
versionSpec: '18.0.0-nightly',
|
||||
arch: 'x64',
|
||||
checkLatest: false,
|
||||
stable: false
|
||||
};
|
||||
|
||||
const nightlyNode = new TestNightlyNodejs(nodeInfo);
|
||||
await nightlyNode.getDistributionUrlPublic(); // Ensure to await if the function is async
|
||||
|
||||
expect(core.info).toHaveBeenCalledWith(`Using mirror URL: ${mirrorURL}`);
|
||||
});
|
||||
|
||||
nightlyNode.getDistributionUrlPublic();
|
||||
|
||||
expect(core.info).toHaveBeenCalledWith(`Using mirror URL: ${mirrorURL}`);
|
||||
});
|
||||
|
||||
it('logs default URL when no mirror URL is provided', async () => {
|
||||
const nodeInfo: NodeInputs = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue