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 support for multiple service endpoints in npm task #4523

Merged
merged 1 commit into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Tasks/Npm/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ describe('Npm Task', function () {
});

// custom
it('custom command succeeds with single service endpoint', (done: MochaDone) => {
this.timeout(1000);
let tp = path.join(__dirname, 'custom-singleEndpoint.js');
let tr = new ttm.MockTestRunner(tp);

tr.run();

assert(tr.stdOutContained('npm custom successful'), 'npm custom command should have run');
assert(tr.stdOutContained('http://example.com/1/'), 'debug output should have contained endpoint');
assert(tr.succeeded, 'task should have succeeded');

done();
});

it('custom command should return npm version', (done: MochaDone) => {
this.timeout(1000);
let tp = path.join(__dirname, 'custom-version.js');
Expand Down Expand Up @@ -132,6 +146,21 @@ describe('Npm Task', function () {
done();
});

it('install using multiple endpoints', (done: MochaDone) => {
this.timeout(1000);
let tp = path.join(__dirname, 'install-multipleEndpoints.js');
let tr = new ttm.MockTestRunner(tp);

tr.run();

assert(tr.stdOutContained('npm install successful'), 'npm should have installed the package');
assert(tr.stdOutContained('http://example.com/1/'), 'debug output should have contained endpoint');
assert(tr.stdOutContained('http://example.com/2/'), 'debug output should have contained endpoint');
assert(tr.succeeded, 'task should have succeeded');

done();
});

// publish
it ('publish using feed', (done: MochaDone) => {
this.timeout(1000);
Expand Down
29 changes: 29 additions & 0 deletions Tasks/Npm/Tests/custom-singleEndpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as path from 'path';

import { TaskLibAnswerExecResult } from 'vsts-task-lib/mock-answer';
import * as tmrm from 'vsts-task-lib/mock-run';

import { NpmCommand, NpmTaskInput, RegistryLocation } from '../constants';
import { NpmMockHelper } from './NpmMockHelper';

let taskPath = path.join(__dirname, '..', 'npm.js');
let tmr = new NpmMockHelper(taskPath);

tmr.setInput(NpmTaskInput.Command, NpmCommand.Custom);
tmr.setInput(NpmTaskInput.CustomCommand, 'mockcmd');
tmr.setInput(NpmTaskInput.WorkingDir, '');
tmr.setInput(NpmTaskInput.CustomRegistry, RegistryLocation.Npmrc);
tmr.setInput(NpmTaskInput.CustomEndpoint, '1');
let auth = {
scheme: 'Token',
parameters: {
'apitoken': 'AUTHTOKEN'
}
};
tmr.mockServiceEndpoint('1', 'http://example.com/1/', auth);
tmr.mockNpmCommand('mockcmd', {
code: 0,
stdout: 'npm custom successful'
} as TaskLibAnswerExecResult);

tmr.run();
29 changes: 29 additions & 0 deletions Tasks/Npm/Tests/install-multipleEndpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as path from 'path';

import { TaskLibAnswerExecResult } from 'vsts-task-lib/mock-answer';
import * as tmrm from 'vsts-task-lib/mock-run';

import { NpmCommand, NpmTaskInput, RegistryLocation } from '../constants';
import { NpmMockHelper } from './NpmMockHelper';

let taskPath = path.join(__dirname, '..', 'npm.js');
let tmr = new NpmMockHelper(taskPath);

tmr.setInput(NpmTaskInput.Command, NpmCommand.Install);
tmr.setInput(NpmTaskInput.WorkingDir, '');
tmr.setInput(NpmTaskInput.CustomRegistry, RegistryLocation.Npmrc);
tmr.setInput(NpmTaskInput.CustomEndpoint, '1,2');
let auth = {
scheme: 'Token',
parameters: {
'apitoken': 'AUTHTOKEN'
}
};
tmr.mockServiceEndpoint('1', 'http://example.com/1/', auth);
tmr.mockServiceEndpoint('2', 'http://example.com/2/', auth);
tmr.mockNpmCommand('install', {
code: 0,
stdout: 'npm install successful'
} as TaskLibAnswerExecResult);

tmr.run();
7 changes: 4 additions & 3 deletions Tasks/Npm/npmcustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ export async function run(command?: string): Promise<void> {
break;
case RegistryLocation.Npmrc:
tl.debug(tl.loc('UseNpmrc'));
let endpointId = tl.getInput(NpmTaskInput.CustomEndpoint);
if (endpointId) {
npmRegistries.push(NpmRegistry.FromServiceEndpoint(endpointId, true));
let endpointIds = tl.getDelimitedInput(NpmTaskInput.CustomEndpoint, ',');
if (endpointIds && endpointIds.length > 0) {
let endpointRegistries = endpointIds.map(e => NpmRegistry.FromServiceEndpoint(e, true));
npmRegistries = npmRegistries.concat(endpointRegistries);
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion Tasks/Npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vsts-npm-task",
"version": "1.0.1",
"version": "1.0.2",
"description": "VSTS NPM Task",
"main": "npmtask.js",
"scripts": {
Expand Down
7 changes: 5 additions & 2 deletions Tasks/Npm/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 1
"Patch": 2
},
"runsOn": [
"Agent",
Expand Down Expand Up @@ -89,7 +89,10 @@
"label": "Credentials for registries outside this account/collection",
"helpMarkDown": "Credentials to use for external registries located in the project's .npmrc. For registries in this account/collection, leave this blank; the build’s credentials are used automatically.",
"type": "connectedService:externalnpmregistry",
"visibleRule": "customRegistry = useNpmrc"
"visibleRule": "customRegistry = useNpmrc",
"properties": {
"MultiSelectFlatList": "true"
}
},
{
"groupName": "publishRegistries",
Expand Down
7 changes: 5 additions & 2 deletions Tasks/Npm/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 1
"Patch": 2
},
"runsOn": [
"Agent",
Expand Down Expand Up @@ -89,7 +89,10 @@
"label": "ms-resource:loc.input.label.customEndpoint",
"helpMarkDown": "ms-resource:loc.input.help.customEndpoint",
"type": "connectedService:externalnpmregistry",
"visibleRule": "customRegistry = useNpmrc"
"visibleRule": "customRegistry = useNpmrc",
"properties": {
"MultiSelectFlatList": "true"
}
},
{
"groupName": "publishRegistries",
Expand Down
3 changes: 2 additions & 1 deletion Tasks/Npm/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export async function getPackagingCollectionUrl(): Promise<string> {
}

export function getTempNpmrcPath(): string {
let tempUserNpmrcPath: string = path.join(getTempPath(), `${tl.getVariable('Build.BuildId')}.npmrc`);
let id: string = tl.getVariable('Build.BuildId') || tl.getVariable('Release.ReleaseId');
let tempUserNpmrcPath: string = path.join(getTempPath(), `${id}.npmrc`);

return tempUserNpmrcPath;
}
Expand Down