generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89fa56b
commit 101a5eb
Showing
6 changed files
with
105 additions
and
230 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
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,25 @@ | ||
/* | ||
* Copyright (c) 2021, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import got from 'got'; | ||
import { PLUGIN_INFO_GET_TIMEOUT } from '../constants'; | ||
|
||
export type DistTagJson = { | ||
latest: string; | ||
'latest-rc': string; | ||
}; | ||
|
||
export async function getDistTagVersion(url: string, distTag: string): Promise<string> { | ||
// TODO: Could use npm instead here. That way private cli repos could auth with .npmrc | ||
// -- could utilize this: https://github.com/salesforcecli/plugin-trust/blob/0393b906a30e8858816625517eda5db69377c178/src/lib/npmCommand.ts | ||
const options = { timeout: PLUGIN_INFO_GET_TIMEOUT }; | ||
|
||
const body = await got(url, options).json<DistTagJson>(); | ||
|
||
// We are only interested in latest and latest-rc, could update this if other tags are desired | ||
return distTag.includes('rc') ? body['latest-rc'] : body['latest']; | ||
} |
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,67 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import got from 'got'; | ||
import { expect, use as chaiUse } from 'chai'; | ||
import * as Sinon from 'sinon'; | ||
import * as SinonChai from 'sinon-chai'; | ||
import { stubMethod } from '@salesforce/ts-sinon'; | ||
import { getDistTagVersion, DistTagJson } from '../../src/shared/get-dist-tag-version'; | ||
|
||
chaiUse(SinonChai); | ||
|
||
describe('getReleaseNotes tests', () => { | ||
let sandbox: sinon.SinonSandbox; | ||
let gotStub: sinon.SinonStub; | ||
|
||
let url; | ||
let gotResponse: DistTagJson; | ||
|
||
beforeEach(() => { | ||
url = 'https://registry.npmjs.org/-/package/sfdx-cli/dist-tags'; | ||
gotResponse = { | ||
latest: '1.2.3', | ||
'latest-rc': '1.3.0', | ||
}; | ||
|
||
sandbox = Sinon.createSandbox(); | ||
|
||
gotStub = stubMethod(sandbox, got, 'default'); | ||
gotStub.returns({ | ||
json: () => gotResponse, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
gotStub.restore(); | ||
sandbox.restore(); | ||
}); | ||
|
||
it('calls got with correct args', async () => { | ||
await getDistTagVersion(url, 'latest'); | ||
|
||
expect(gotStub.args[0]).to.deep.equal([url, { timeout: 3000 }]); | ||
}); | ||
|
||
it('returns rc if version is "latest-rc"', async () => { | ||
const version = await getDistTagVersion(url, 'latest-rc'); | ||
|
||
expect(version).to.equal('1.3.0'); | ||
}); | ||
|
||
it('returns rc if version includes "rc"', async () => { | ||
const version = await getDistTagVersion(url, 'stable-rc'); | ||
|
||
expect(version).to.equal('1.3.0'); | ||
}); | ||
|
||
it('returns latest by default', async () => { | ||
const version = await getDistTagVersion(url, 'foobar'); | ||
|
||
expect(version).to.equal('1.2.3'); | ||
}); | ||
}); |
Oops, something went wrong.