Comparing version 0.3.0 to 0.4.0
@@ -0,1 +1,2 @@ | ||
import './polyfills'; | ||
export = Loadmill; | ||
@@ -26,3 +27,5 @@ declare namespace Loadmill { | ||
runFunctionalFolder(folderPath: string, paramsOrCallback?: Loadmill.ParamsOrCallback, callback?: Loadmill.Callback): Promise<Loadmill.TestResult[]>; | ||
runFunctionalLocally(config: Loadmill.Configuration, paramsOrCallback?: Loadmill.ParamsOrCallback, callback?: Loadmill.Callback): Promise<Loadmill.TestResult>; | ||
runFunctionalFolderLocally(folderPath: string, paramsOrCallback?: Loadmill.ParamsOrCallback, callback?: Loadmill.Callback): Promise<Loadmill.TestResult[]>; | ||
runAsyncFunctional(config: Loadmill.Configuration, paramsOrCallback?: Loadmill.ParamsOrCallback, callback?: Loadmill.Callback): Promise<Loadmill.TestResult>; | ||
}; |
"use strict"; | ||
var tslib_1 = require("tslib"); | ||
require("./polyfills"); | ||
var fs = require("fs"); | ||
var superagent = require("superagent"); | ||
var utils_1 = require("./utils"); | ||
var loadmill_runner_1 = require("loadmill-runner"); | ||
var TYPE_LOAD = 'load'; | ||
@@ -103,2 +105,29 @@ var TYPE_FUNCTIONAL = 'functional'; | ||
} | ||
function _runFunctionalLocally(config, paramsOrCallback, callback) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
return tslib_1.__generator(this, function (_a) { | ||
return [2 /*return*/, wrap(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var trialRes; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
config = toConfig(config, paramsOrCallback); | ||
config['async'] = false; | ||
return [4 /*yield*/, loadmill_runner_1.runFunctionalOnLocalhost(config)]; | ||
case 1: | ||
trialRes = _a.sent(); | ||
if (!utils_1.isEmptyObj(trialRes.failures)) { | ||
console.error('\x1b[31m', 'Test failure response -', '\x1b[0m', "" + JSON.stringify(trialRes)); | ||
} | ||
return [2 /*return*/, { | ||
type: TYPE_FUNCTIONAL, | ||
passed: isFunctionalPassed(trialRes) | ||
}]; | ||
} | ||
}); | ||
}); }, callback || paramsOrCallback)]; | ||
}); | ||
}); | ||
} | ||
function _runFunctional(config, async, paramsOrCallback, callback) { | ||
@@ -191,2 +220,21 @@ return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
}, | ||
runFunctionalLocally: function (config, paramsOrCallback, callback) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
return [2 /*return*/, _runFunctionalLocally(config, paramsOrCallback, callback)]; | ||
}); | ||
}); | ||
}, | ||
runFunctionalFolderLocally: function (folderPath, paramsOrCallback, callback) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var listOfFiles; | ||
return tslib_1.__generator(this, function (_a) { | ||
listOfFiles = utils_1.getJSONFilesInFolderRecursively(folderPath); | ||
if (listOfFiles.length === 0) { | ||
console.log("No Loadmill test files were found at " + folderPath + " - exiting..."); | ||
} | ||
return [2 /*return*/, _runFolderSync(listOfFiles, _runFunctionalLocally, paramsOrCallback, callback)]; | ||
}); | ||
}); | ||
}, | ||
runAsyncFunctional: function (config, paramsOrCallback, callback) { | ||
@@ -193,0 +241,0 @@ return _runFunctional(config, true, paramsOrCallback, callback); |
@@ -21,2 +21,3 @@ "use strict"; | ||
.option("-v, --verbose", "Print out extra information for debugging.") | ||
.option("-c, --local", "Execute functional test synchronously on local machine. This flag trumps load-test and async options") | ||
.parse(process.argv); | ||
@@ -29,7 +30,7 @@ start()["catch"](function (err) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var wait, bail, async, quiet, token, verbose, loadTest, _a, fileOrFolder, rawParams, logger, parameters, loadmill, listOfFiles, _i, listOfFiles_1, file, res, id, method; | ||
var wait, bail, async, quiet, token, verbose, local, loadTest, _a, fileOrFolder, rawParams, logger, parameters, loadmill, listOfFiles, _i, listOfFiles_1, file, res, id, method; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
wait = program.wait, bail = program.bail, async = program.async, quiet = program.quiet, token = program.token, verbose = program.verbose, loadTest = program.loadTest, _a = program.args, fileOrFolder = _a[0], rawParams = _a.slice(1); | ||
wait = program.wait, bail = program.bail, async = program.async, quiet = program.quiet, token = program.token, verbose = program.verbose, local = program.local, loadTest = program.loadTest, _a = program.args, fileOrFolder = _a[0], rawParams = _a.slice(1); | ||
logger = new utils_1.Logger(verbose); | ||
@@ -66,26 +67,33 @@ if (!fileOrFolder) { | ||
case 1: | ||
if (!(_i < listOfFiles_1.length)) return [3 /*break*/, 9]; | ||
if (!(_i < listOfFiles_1.length)) return [3 /*break*/, 11]; | ||
file = listOfFiles_1[_i]; | ||
res = void 0, id = void 0; | ||
if (!loadTest) return [3 /*break*/, 3]; | ||
if (!local) return [3 /*break*/, 3]; | ||
logger.verbose("Running " + file + " as functional test locally"); | ||
return [4 /*yield*/, loadmill.runFunctionalLocally(file, parameters)]; | ||
case 2: | ||
res = _b.sent(); | ||
return [3 /*break*/, 7]; | ||
case 3: | ||
if (!loadTest) return [3 /*break*/, 5]; | ||
logger.verbose("Launching " + file + " as load test"); | ||
return [4 /*yield*/, loadmill.run(file, parameters)]; | ||
case 2: | ||
case 4: | ||
id = _b.sent(); | ||
return [3 /*break*/, 5]; | ||
case 3: | ||
return [3 /*break*/, 7]; | ||
case 5: | ||
logger.verbose("Running " + file + " as functional test"); | ||
method = async ? 'runAsyncFunctional' : 'runFunctional'; | ||
return [4 /*yield*/, loadmill[method](file, parameters)]; | ||
case 4: | ||
case 6: | ||
res = _b.sent(); | ||
_b.label = 5; | ||
case 5: | ||
if (!(wait && (loadTest || async))) return [3 /*break*/, 7]; | ||
_b.label = 7; | ||
case 7: | ||
if (!(wait && (loadTest || async))) return [3 /*break*/, 9]; | ||
logger.verbose("Waiting for test:", res ? res.id : id); | ||
return [4 /*yield*/, loadmill.wait(res || id)]; | ||
case 6: | ||
case 8: | ||
res = _b.sent(); | ||
_b.label = 7; | ||
case 7: | ||
_b.label = 9; | ||
case 9: | ||
if (!quiet) { | ||
@@ -100,7 +108,7 @@ logger.log(res || id); | ||
} | ||
_b.label = 8; | ||
case 8: | ||
_b.label = 10; | ||
case 10: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 9: return [2 /*return*/]; | ||
case 11: return [2 /*return*/]; | ||
} | ||
@@ -107,0 +115,0 @@ }); |
@@ -5,2 +5,3 @@ "use strict"; | ||
var path = require("path"); | ||
var isEmpty = require("lodash/isEmpty"); | ||
exports.getJSONFilesInFolderRecursively = function (fileOrFolder, filelist) { | ||
@@ -21,2 +22,3 @@ if (filelist === void 0) { filelist = []; } | ||
var endsWith = function (str, suffix) { return str.indexOf(suffix, str.length - suffix.length) !== -1; }; | ||
exports.isEmptyObj = function (obj) { return isEmpty(obj); }; | ||
var Logger = /** @class */ (function () { | ||
@@ -23,0 +25,0 @@ function Logger(verbose) { |
{ | ||
"name": "loadmill", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A node.js module for running load tests and functional tests on loadmill.com", | ||
@@ -21,8 +21,22 @@ "keywords": [ | ||
"scripts": { | ||
"prepare": "tsc && rm -f lib/loadmill.d.ts lib/utils.d.ts" | ||
"prepare": "tsc && rm -f lib/loadmill.d.ts lib/utils.d.ts lib/polyfills.d.ts" | ||
}, | ||
"dependencies": { | ||
"bluebird": "^3.4.7", | ||
"cancelable-awaiter": "^1.0.3", | ||
"cheerio": "^0.22.0", | ||
"commander": "^2.15.0", | ||
"country-list": "^2.1.0", | ||
"http-headers-validation": "^0.0.1", | ||
"jsonpath": "^1.0.0", | ||
"loadmill-runner": "^0.0.2", | ||
"lodash": "^4.17.2", | ||
"moment": "^2.17.0", | ||
"quickselect": "^2.0.0", | ||
"randomstring": "^1.1.5", | ||
"superagent": "^3.8.2", | ||
"tslib": "^1.9.0" | ||
"tslib": "^1.3.0", | ||
"urijs": "^1.18.1", | ||
"uuid": "^3.0.1", | ||
"validator": "^10.4.0" | ||
}, | ||
@@ -29,0 +43,0 @@ "devDependencies": { |
@@ -87,3 +87,8 @@ # Loadmill | ||
``` | ||
If you wish to execute the tests from your local machine (rather than our SaaS infrastructure) you can use: | ||
```js | ||
loadmill.runFunctionalLocally("./load-tests/api_test.json") | ||
// -> {type: 'functional', passed: boolean} | ||
.then(result => console.log(result)); | ||
``` | ||
If your functional test is supposed to, or may, take longer than 25 seconds, you can use `runAsyncFunctional` instead: | ||
@@ -109,6 +114,12 @@ ```js | ||
```js | ||
loadmill.runFunctionalFolder("./path/to/tests/folder") | ||
loadmill.runFunctionalFolder("/path/to/tests/folder") | ||
// -> [{id: string, type: 'functional', passed: boolean, url: string}] | ||
.then(result => console.log(result)); | ||
``` | ||
If you wish to execute all the tests in that folder from your local machine (rather than our SaaS infrastructure) you can use: | ||
```js | ||
loadmill.runFunctionalFolderLocally("/path/to/tests/folder") | ||
// -> [{type: 'functional', passed: boolean}] | ||
.then(result => console.log(result)); | ||
``` | ||
@@ -144,2 +155,11 @@ ### Parameters | ||
### Local Functional Tests | ||
You can also run *functional* tests from your local machine using the `-c` or `--local` flag | ||
``` | ||
loadmill local-test.json --local --token DW2rTlkNmE6A3ax5LVTSDxv2Jfw4virjQpmbOaLG | ||
``` | ||
Using the `-c` or `--local` option will override other options like `--load-test` etc... | ||
### Load Tests | ||
@@ -183,1 +203,2 @@ | ||
- `-v, --verbose` Print out extra information for debugging (trumps `-q`). | ||
- `-c, --local` Execute functional test synchronously on local machine. This flag overrides load-test and async options. |
@@ -0,4 +1,6 @@ | ||
import './polyfills' | ||
import * as fs from 'fs'; | ||
import * as superagent from 'superagent'; | ||
import {getJSONFilesInFolderRecursively} from './utils'; | ||
import {getJSONFilesInFolderRecursively, isEmptyObj} from './utils'; | ||
import {runFunctionalOnLocalhost} from 'loadmill-runner'; | ||
@@ -116,2 +118,26 @@ export = Loadmill; | ||
async function _runFunctionalLocally( | ||
config: Loadmill.Configuration, | ||
paramsOrCallback: Loadmill.ParamsOrCallback, | ||
callback: Loadmill.Callback) { | ||
return wrap( | ||
async () => { | ||
config = toConfig(config, paramsOrCallback); | ||
config['async'] = false; | ||
const trialRes = await runFunctionalOnLocalhost(config); | ||
if (!isEmptyObj(trialRes.failures)) { | ||
console.error('\x1b[31m', 'Test failure response -', '\x1b[0m', `${JSON.stringify(trialRes)}`); | ||
} | ||
return { | ||
type: TYPE_FUNCTIONAL, | ||
passed: isFunctionalPassed(trialRes), | ||
}; | ||
}, | ||
callback || paramsOrCallback | ||
); | ||
} | ||
async function _runFunctional( | ||
@@ -216,2 +242,21 @@ config: Loadmill.Configuration, | ||
async runFunctionalLocally(config: Loadmill.Configuration, | ||
paramsOrCallback?: Loadmill.ParamsOrCallback, | ||
callback?: Loadmill.Callback): Promise<Loadmill.TestResult> { | ||
return _runFunctionalLocally(config, paramsOrCallback, callback); | ||
}, | ||
async runFunctionalFolderLocally( | ||
folderPath: string, | ||
paramsOrCallback?: Loadmill.ParamsOrCallback, | ||
callback?: Loadmill.Callback): Promise<Array<Loadmill.TestResult>> { | ||
const listOfFiles = getJSONFilesInFolderRecursively(folderPath); | ||
if (listOfFiles.length === 0) { | ||
console.log(`No Loadmill test files were found at ${folderPath} - exiting...`); | ||
} | ||
return _runFolderSync(listOfFiles, _runFunctionalLocally, paramsOrCallback, callback); | ||
}, | ||
runAsyncFunctional( | ||
@@ -218,0 +263,0 @@ config: Loadmill.Configuration, |
@@ -21,2 +21,3 @@ import * as Loadmill from './index'; | ||
.option("-v, --verbose", "Print out extra information for debugging.") | ||
.option("-c, --local", "Execute functional test synchronously on local machine. This flag trumps load-test and async options") | ||
.parse(process.argv); | ||
@@ -39,2 +40,3 @@ | ||
verbose, | ||
local, | ||
loadTest, | ||
@@ -83,12 +85,15 @@ args: [fileOrFolder, ...rawParams] | ||
if (loadTest) { | ||
logger.verbose(`Launching ${file} as load test`); | ||
id = await loadmill.run(file, parameters); | ||
if(local) { | ||
logger.verbose(`Running ${file} as functional test locally`); | ||
res = await loadmill.runFunctionalLocally(file, parameters); | ||
} else { | ||
if (loadTest) { | ||
logger.verbose(`Launching ${file} as load test`); | ||
id = await loadmill.run(file, parameters); | ||
} else { | ||
logger.verbose(`Running ${file} as functional test`); | ||
const method = async ? 'runAsyncFunctional' : 'runFunctional'; | ||
res = await loadmill[method](file, parameters); | ||
} | ||
} | ||
else { | ||
logger.verbose(`Running ${file} as functional test`); | ||
const method = async ? 'runAsyncFunctional' : 'runFunctional'; | ||
res = await loadmill[method](file, parameters); | ||
} | ||
if (wait && (loadTest || async)) { | ||
@@ -95,0 +100,0 @@ logger.verbose("Waiting for test:", res ? res.id : id); |
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import isEmpty = require('lodash/isEmpty'); | ||
@@ -21,2 +22,4 @@ export const getJSONFilesInFolderRecursively = (fileOrFolder: string, filelist: string[] = []): string[] => { | ||
export const isEmptyObj = (obj) => isEmpty(obj); | ||
export class Logger { | ||
@@ -23,0 +26,0 @@ private readonly verb: boolean = false; |
@@ -12,2 +12,3 @@ { | ||
"noUnusedParameters": true, | ||
"allowSyntheticDefaultImports": true, | ||
"lib": [ | ||
@@ -20,4 +21,5 @@ "es5", | ||
"./src/index.ts", | ||
"./src/loadmill.ts" | ||
"./src/loadmill.ts", | ||
"./globals.d.ts" | ||
] | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
84593
16
956
201
0
17
+ Addedbluebird@^3.4.7
+ Addedcancelable-awaiter@^1.0.3
+ Addedcheerio@^0.22.0
+ Addedcountry-list@^2.1.0
+ Addedjsonpath@^1.0.0
+ Addedloadmill-runner@^0.0.2
+ Addedlodash@^4.17.2
+ Addedmoment@^2.17.0
+ Addedquickselect@^2.0.0
+ Addedrandomstring@^1.1.5
+ Addedurijs@^1.18.1
+ Addeduuid@^3.0.1
+ Addedvalidator@^10.4.0
+ Addedbluebird@3.7.2(transitive)
+ Addedboolbase@1.0.0(transitive)
+ Addedcancelable-awaiter@1.0.6(transitive)
+ Addedcheerio@0.22.0(transitive)
+ Addedcountry-list@2.3.0(transitive)
+ Addedcss-select@1.2.0(transitive)
+ Addedcss-what@2.1.3(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addeddom-serializer@0.1.1(transitive)
+ Addeddomelementtype@1.3.1(transitive)
+ Addeddomhandler@2.4.2(transitive)
+ Addeddomutils@1.5.1(transitive)
+ Addedentities@1.1.2(transitive)
+ Addedescodegen@1.14.3(transitive)
+ Addedesprima@1.2.24.0.1(transitive)
+ Addedestraverse@4.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedhtmlparser2@3.10.1(transitive)
+ Addedhttp-headers-validation@0.0.1(transitive)
+ Addedjsonpath@1.1.1(transitive)
+ Addedlevn@0.3.0(transitive)
+ Addedloadmill-runner@0.0.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.assignin@4.2.0(transitive)
+ Addedlodash.bind@4.2.1(transitive)
+ Addedlodash.defaults@4.2.0(transitive)
+ Addedlodash.filter@4.6.0(transitive)
+ Addedlodash.flatten@4.4.0(transitive)
+ Addedlodash.foreach@4.5.0(transitive)
+ Addedlodash.map@4.6.0(transitive)
+ Addedlodash.merge@4.6.2(transitive)
+ Addedlodash.pick@4.4.0(transitive)
+ Addedlodash.reduce@4.6.0(transitive)
+ Addedlodash.reject@4.6.0(transitive)
+ Addedlodash.some@4.6.0(transitive)
+ Addedmoment@2.30.1(transitive)
+ Addednth-check@1.0.2(transitive)
+ Addedoptionator@0.8.3(transitive)
+ Addedprelude-ls@1.1.2(transitive)
+ Addedquickselect@2.0.0(transitive)
+ Addedrandombytes@2.1.0(transitive)
+ Addedrandomstring@1.3.1(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedstatic-eval@2.0.2(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedtype-check@0.3.2(transitive)
+ Addedunderscore@1.12.1(transitive)
+ Addedurijs@1.19.11(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedvalidator@10.11.0(transitive)
+ Addedword-wrap@1.2.5(transitive)
Updatedtslib@^1.3.0