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 tests and more #47

Closed
wants to merge 9 commits into from
Closed
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
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
sebcaps marked this conversation as resolved.
Show resolved Hide resolved
NewmanPostman/npm-debug.log
.taskkey
sebcaps marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions .taskkey
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d924104f-083d-4a9b-aaa2-7cc364673a07
93 changes: 63 additions & 30 deletions NewmanPostman/newmantask.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const tl = require("vsts-task-lib");
const tl = require("azure-pipelines-task-lib/task");
const isurl = require("is-url");
function GetToolRunner(collectionToRun) {
tl.debug("in GetToolRunner");
let pathToNewman = tl.getInput('pathToNewman', false);
tl.debug("Path to newman is : " + pathToNewman);
if (pathToNewman.length == 0) {
if (typeof pathToNewman != 'undefined' && pathToNewman) {
console.info("Specific path to newman found");
}
else {
console.info("No specific path to newman, using default of 'newman'");
pathToNewman = "newman";
}
var newman = tl.tool(tl.which(pathToNewman, true));
Expand Down Expand Up @@ -85,42 +88,72 @@ function GetToolRunner(collectionToRun) {
newman.argIf(tl.filePathSupplied('exportGlobals'), ['--export-globals', exportGlobals]);
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') {
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;
}
function run() {
return __awaiter(this, void 0, void 0, function* () {
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 = tl.getDelimitedInput('Contents', '\n', true);
collectionFileSource = path.normalize(collectionFileSource);
let allPaths = tl.find(collectionFileSource);
let matchedPaths = tl.match(allPaths, contents, collectionFileSource);
let matchedFiles = matchedPaths.filter((itemPath) => !tl.stats(itemPath).isDirectory());
console.log("found %d files", matchedFiles.length);
if (matchedFiles.length > 0) {
matchedFiles.forEach((file) => {
var newman = GetToolRunner(file);
var execResponse = newman.execSync();
tl.debug(execResponse.stdout);
if (execResponse.code === 1) {
console.log(execResponse);
taskSuccess = false;
}
});
// tl.debug('executing newman')
tl.setResourcePath(path.join(__dirname, 'task.json'));
if (tl.getInput('collectionSourceType', true) == 'file') {
let collectionFileSource = tl.getPathInput('collectionFileSource', true, true);
var taskSuccess = true;
if (tl.stats(collectionFileSource).isDirectory()) {
let contents = tl.getDelimitedInput('Contents', '\n', true);
collectionFileSource = path.normalize(collectionFileSource);
let allPaths = tl.find(collectionFileSource);
let matchedPaths = tl.match(allPaths, contents, collectionFileSource);
let matchedFiles = matchedPaths.filter((itemPath) => !tl.stats(itemPath).isDirectory());
console.log("found %d files", matchedFiles.length);
if (matchedFiles.length > 0) {
matchedFiles.forEach((file) => {
var newman = GetToolRunner(file);
var execResponse = newman.execSync();
// tl.debug(execResponse.stdout);
if (execResponse.code === 1) {
console.log(execResponse);
taskSuccess = false;
}
});
}
else {
console.log("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 = GetToolRunner(collectionFileSource);
yield newman.exec();
}
}
else {
var newman = GetToolRunner(collectionFileSource);
yield newman.exec();
let collectionFileUrl = tl.getInput('collectionURL', true);
if (isurl(collectionFileUrl)) {
var newman = GetToolRunner(collectionFileUrl);
yield newman.exec();
}
else {
tl.setResult(tl.TaskResult.Failed, 'Provided string "' + collectionFileUrl + '" for collection is not a valid url');
}
}
if (taskSuccess) {
tl.setResult(tl.TaskResult.Succeeded, "Success");
Expand Down
89 changes: 57 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,7 +90,22 @@ 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;
}

Expand All @@ -98,39 +114,48 @@ async function run() {
// 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);
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;
}
});
}
else {
console.log("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
48 changes: 48 additions & 0 deletions NewmanPostman/npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
0 info it worked if it ends with ok
sebcaps marked this conversation as resolved.
Show resolved Hide resolved
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'test' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle [email protected]~pretest: [email protected]
6 silly lifecycle [email protected]~pretest: no script for pretest, continuing
7 info lifecycle [email protected]~test: [email protected]
8 verbose lifecycle [email protected]~test: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~test: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;F:\DocSéb\NewmanPostman_VSTS_Task\NewmanPostman\node_modules\.bin;C:\Python27\;C:\Python27\Scripts;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Java\jdk1.8.0_45\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;E:\wamp\bin\php\php5.5.12;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\;C:\WINDOWS\System32\OpenSSH\;E:\wamp\bin\php\php5.6.35;C:\ProgramData\ComposerSetup\bin;C:\Program Files\Microsoft VS Code\bin;C:\Applications\Atlassian\atlassian-plugin-sdk-6.1.0\bin;C:\Users\seb\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\Arduino\hardware\tools\avr\bin;C:\Users\seb\AppData\Roaming\npm;C:\Program Files\Microsoft VS Code\bin;C:\Users\seb\AppData\Roaming\Composer\vendor\bin;C:\SysGCC\esp8266\bin
10 verbose lifecycle [email protected]~test: CWD: F:\DocSéb\NewmanPostman_VSTS_Task\NewmanPostman
11 silly lifecycle [email protected]~test: Args: [ '/d /s /c', 'echo "Error: no test specified" && exit 1' ]
12 silly lifecycle [email protected]~test: Returned: code: 1 signal: null
13 info lifecycl e [email protected]~test: Failed to exec test script
14 verbose stack Error: [email protected] test: `echo "Error: no test specified" && exit 1`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:255:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:885:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid [email protected]
16 verbose cwd F:\DocSéb\NewmanPostman_VSTS_Task\NewmanPostman
17 error Windows_NT 10.0.17134
18 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
19 error node v7.2.1
20 error npm v3.10.10
21 error code ELIFECYCLE
22 error [email protected] test: `echo "Error: no test specified" && exit 1`
22 error Exit status 1
23 error Failed at the [email protected] test script 'echo "Error: no test specified" && exit 1'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the task package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error echo "Error: no test specified" && exit 1
23 error You can get information on how to open an issue for this project with:
23 error npm bugs task
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls task
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
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.

Loading