Skip to content

Commit

Permalink
Merge pull request #49 from sebcaps/improveTest
Browse files Browse the repository at this point in the history
Improve test
  • Loading branch information
carlowahlstedt authored Dec 30, 2018
2 parents 8ab0706 + 7a4b5b5 commit ac1b969
Show file tree
Hide file tree
Showing 27 changed files with 1,253 additions and 448 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ bld/
*/dist/
node_modules
.vscode
*.vsix
*.vsix
*.map
*.js
NewmanPostman/npm-debug.log
.taskkey
137 changes: 0 additions & 137 deletions NewmanPostman/newmantask.js

This file was deleted.

88 changes: 56 additions & 32 deletions NewmanPostman/newmantask.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path = require('path');
import tl = require('vsts-task-lib/task');
import trm = require('vsts-task-lib/toolrunner');
import tl = require('azure-pipelines-task-lib/task');
import trm = require('azure-pipelines-task-lib/toolrunner');
import isurl = require('is-url');

function GetToolRunner(collectionToRun: string) {
let pathToNewman = tl.getInput('pathToNewman', false);
Expand Down Expand Up @@ -89,48 +90,71 @@ function GetToolRunner(collectionToRun: string) {
let exportCollection = tl.getPathInput('exportCollection');
newman.argIf(tl.filePathSupplied('exportCollection'), ['--export-collection', exportCollection]);

newman.arg(['-e', tl.getPathInput('environment', true, true)]);
let envType = tl.getInput('environmentSourceType');
if (envType == 'file') { //environment is a file
console.info("File used for environment");
newman.arg(['-e', tl.getPathInput('environmentFile', true, true)]);
} else if (envType == 'url') {
let envURl = tl.getInput('environmentUrl', true);
if (isurl(envURl)) {
console.info("URL used for environment");
newman.arg(['-e', envURl]);
} else {
tl.setResult(tl.TaskResult.Failed, 'Provided string "' + envURl + '" for environment is not a valid url');
}
} else {
//no environement used. Don't add argument, just log info.
console.info('No environment set, no need to add it in argument');
}
return newman;
}

async function run() {
try {
// tl.debug('executing newman')
tl.setResourcePath(path.join(__dirname, 'task.json'));

let collectionFileSource = tl.getPathInput('collectionFileSource', true, true);
var taskSuccess = true;
if (tl.stats(collectionFileSource).isDirectory()) {
let contents: string[] = tl.getDelimitedInput('Contents', '\n', true);
collectionFileSource = path.normalize(collectionFileSource);

let allPaths: string[] = tl.find(collectionFileSource);
let matchedPaths: string[] = tl.match(allPaths, contents, collectionFileSource);
let matchedFiles: string[] = matchedPaths.filter((itemPath: string) => !tl.stats(itemPath).isDirectory());

console.log("found %d files", matchedFiles.length);

if (matchedFiles.length > 0) {
matchedFiles.forEach((file: string) => {
var newman: trm.ToolRunner = GetToolRunner(file);
var execResponse = newman.execSync();
// tl.debug(execResponse.stdout);
if (execResponse.code === 1) {
console.log(execResponse);
taskSuccess = false;
}
});
if (tl.getInput('collectionSourceType', true) == 'file') {
let collectionFileSource = tl.getPathInput('collectionFileSource', true, true);
if (tl.stats(collectionFileSource).isDirectory()) {
let contents: string[] = tl.getDelimitedInput('Contents', '\n', true);
collectionFileSource = path.normalize(collectionFileSource);

let allPaths: string[] = tl.find(collectionFileSource);
let matchedPaths: string[] = tl.match(allPaths, contents, collectionFileSource);
let matchedFiles: string[] = matchedPaths.filter((itemPath: string) => !tl.stats(itemPath).isDirectory());

console.log("found %d files", matchedFiles.length);

if (matchedFiles.length > 0) {
matchedFiles.forEach((file: string) => {
var newman: trm.ToolRunner = GetToolRunner(file);
var execResponse = newman.execSync();
// tl.debug(execResponse.stdout);
if (execResponse.code === 1) {
console.log(execResponse);
taskSuccess = false;
}
});
}
else {
tl.error("Could not find any collection files in the path provided");
taskSuccess = false;
}
}
else {
console.log("Could not find any collection files in the path provided");
taskSuccess = false;
var newman: trm.ToolRunner = GetToolRunner(collectionFileSource);
await newman.exec();
}
} else {
let collectionFileUrl = tl.getInput('collectionURL', true);
if (isurl(collectionFileUrl)) {
var newman: trm.ToolRunner = GetToolRunner(collectionFileUrl);
await newman.exec();
} else {
tl.setResult(tl.TaskResult.Failed, 'Provided string "' + collectionFileUrl + '" for collection is not a valid url');
}
}
else {
var newman: trm.ToolRunner = GetToolRunner(collectionFileSource);
await newman.exec();
}

if (taskSuccess) {
tl.setResult(tl.TaskResult.Succeeded, "Success");
}
Expand Down
58 changes: 32 additions & 26 deletions NewmanPostman/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions NewmanPostman/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"vsts-task-lib": "^2.0.5",
"azure-pipelines-task-lib": "^2.7.7",
"reflect-metadata": "^0.1.12",
"tslib": "^1.9.3"
},
"devDependencies": {
"@types/node": "^8.0.7",
"@types/q": "1.0.2"
"@types/q": "1.0.2",
"is-url": "^1.2.4"
}
}
Loading

0 comments on commit ac1b969

Please sign in to comment.