@metlo/testing
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -131,2 +131,24 @@ "use strict"; | ||
}; | ||
const addQueryParamsToRequest = (gen, ctx) => { | ||
const endpoint = ctx.endpoint; | ||
const dataFields = endpoint.dataFields.filter(e => e.dataSection == enums_2.DataSection.REQUEST_QUERY); | ||
if (dataFields.length == 0) { | ||
return gen; | ||
} | ||
const pre = ctx.prefix; | ||
let queryParams = []; | ||
let env = []; | ||
dataFields.forEach(e => { | ||
const name = e.dataPath; | ||
env.push({ | ||
name: `${pre}${name}`, | ||
value: `<<${pre}${name}>>`, | ||
}); | ||
queryParams.push({ | ||
name: e.dataPath, | ||
value: `{{${pre}${name}}}`, | ||
}); | ||
}); | ||
return Object.assign(Object.assign({}, gen), { env: gen.env.concat(env), req: Object.assign(Object.assign({}, gen.req), { query: (gen.req.query || []).concat(queryParams) }) }); | ||
}; | ||
const makeSampleRequestNoAuth = (endpoint, name) => { | ||
@@ -152,2 +174,3 @@ const prefix = name ? name + "_" : ""; | ||
const ctx = { endpoint, prefix }; | ||
gen = addQueryParamsToRequest(gen, ctx); | ||
gen = addBodyToRequest(gen, ctx); | ||
@@ -154,0 +177,0 @@ return gen; |
@@ -7,3 +7,3 @@ import { FailedAssertion, FailedRequest, TestConfig, TestResult } from "./types/test"; | ||
export declare const AssertionType: import("zod").Values<["EQ", "REGEXP", "JS"]>; | ||
export declare const ExtractorType: import("zod").Values<["VALUE", "JS"]>; | ||
export declare const ExtractorType: import("zod").Values<["VALUE", "JS", "HTML"]>; | ||
export { KeyValType, TestConfig, TestRequest, TestResult, TestConfigSchema, FailedAssertion, FailedRequest, } from "./types/test"; | ||
@@ -10,0 +10,0 @@ export { GenTestEndpoint, GenTestContext, GeneratedTestRequest, GenTestEndpointDataField, } from "./generate/types"; |
@@ -10,2 +10,4 @@ "use strict"; | ||
const test_1 = require("./types/test"); | ||
const STEP_KEYS = ["request", "extract", "assert"]; | ||
const REQUEST_KEYS = ["method", "url", "query", "headers", "form", "data"]; | ||
const dumpTestConfig = (config) => { | ||
@@ -26,3 +28,17 @@ const parts = [ | ||
} | ||
return parts.map(e => js_yaml_1.default.dump(e)).join("\n"); | ||
return parts | ||
.map(e => js_yaml_1.default.dump(e, { | ||
sortKeys: (a, b) => { | ||
if (STEP_KEYS.includes(a) && STEP_KEYS.includes(b)) { | ||
return (STEP_KEYS.findIndex(e => e == a) - | ||
STEP_KEYS.findIndex(e => e == b)); | ||
} | ||
if (REQUEST_KEYS.includes(a) && REQUEST_KEYS.includes(b)) { | ||
return (REQUEST_KEYS.findIndex(e => e == a) - | ||
REQUEST_KEYS.findIndex(e => e == b)); | ||
} | ||
return a - b; | ||
}, | ||
})) | ||
.join("\n"); | ||
}; | ||
@@ -29,0 +45,0 @@ exports.dumpTestConfig = dumpTestConfig; |
@@ -13,5 +13,8 @@ "use strict"; | ||
} | ||
else { | ||
else if (extractor.type == enums_1.ExtractorType.enum.JS) { | ||
ctx.envVars[extractor.name] = (0, utils_2.executeScript)(extractorVal, response, ctx); | ||
} | ||
else if (extractor.type == enums_1.ExtractorType.enum.HTML) { | ||
ctx.envVars[extractor.name] = (0, utils_2.extractFromHTML)(extractorVal, response, ctx); | ||
} | ||
return ctx; | ||
@@ -18,0 +21,0 @@ }; |
@@ -5,2 +5,2 @@ import { z } from "zod"; | ||
export declare const AssertionType: z.ZodEnum<["EQ", "REGEXP", "JS"]>; | ||
export declare const ExtractorType: z.ZodEnum<["VALUE", "JS"]>; | ||
export declare const ExtractorType: z.ZodEnum<["VALUE", "JS", "HTML"]>; |
@@ -18,3 +18,3 @@ "use strict"; | ||
exports.AssertionType = zod_1.z.enum(["EQ", "REGEXP", "JS"]); | ||
exports.ExtractorType = zod_1.z.enum(["VALUE", "JS"]); | ||
exports.ExtractorType = zod_1.z.enum(["VALUE", "JS", "HTML"]); | ||
//# sourceMappingURL=enums.js.map |
@@ -96,10 +96,10 @@ import { z } from "zod"; | ||
name: z.ZodString; | ||
type: z.ZodDefault<z.ZodEnum<["VALUE", "JS"]>>; | ||
type: z.ZodDefault<z.ZodEnum<["VALUE", "JS", "HTML"]>>; | ||
value: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
type: "JS" | "VALUE"; | ||
type: "JS" | "VALUE" | "HTML"; | ||
value: string; | ||
name: string; | ||
}, { | ||
type?: "JS" | "VALUE" | undefined; | ||
type?: "JS" | "VALUE" | "HTML" | undefined; | ||
value: string; | ||
@@ -191,10 +191,10 @@ name: string; | ||
name: z.ZodString; | ||
type: z.ZodDefault<z.ZodEnum<["VALUE", "JS"]>>; | ||
type: z.ZodDefault<z.ZodEnum<["VALUE", "JS", "HTML"]>>; | ||
value: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
type: "JS" | "VALUE"; | ||
type: "JS" | "VALUE" | "HTML"; | ||
value: string; | ||
name: string; | ||
}, { | ||
type?: "JS" | "VALUE" | undefined; | ||
type?: "JS" | "VALUE" | "HTML" | undefined; | ||
value: string; | ||
@@ -218,3 +218,3 @@ name: string; | ||
extract?: { | ||
type: "JS" | "VALUE"; | ||
type: "JS" | "VALUE" | "HTML"; | ||
value: string; | ||
@@ -247,3 +247,3 @@ name: string; | ||
extract?: { | ||
type?: "JS" | "VALUE" | undefined; | ||
type?: "JS" | "VALUE" | "HTML" | undefined; | ||
value: string; | ||
@@ -370,10 +370,10 @@ name: string; | ||
name: z.ZodString; | ||
type: z.ZodDefault<z.ZodEnum<["VALUE", "JS"]>>; | ||
type: z.ZodDefault<z.ZodEnum<["VALUE", "JS", "HTML"]>>; | ||
value: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
type: "JS" | "VALUE"; | ||
type: "JS" | "VALUE" | "HTML"; | ||
value: string; | ||
name: string; | ||
}, { | ||
type?: "JS" | "VALUE" | undefined; | ||
type?: "JS" | "VALUE" | "HTML" | undefined; | ||
value: string; | ||
@@ -397,3 +397,3 @@ name: string; | ||
extract?: { | ||
type: "JS" | "VALUE"; | ||
type: "JS" | "VALUE" | "HTML"; | ||
value: string; | ||
@@ -426,3 +426,3 @@ name: string; | ||
extract?: { | ||
type?: "JS" | "VALUE" | undefined; | ||
type?: "JS" | "VALUE" | "HTML" | undefined; | ||
value: string; | ||
@@ -467,3 +467,3 @@ name: string; | ||
extract?: { | ||
type: "JS" | "VALUE"; | ||
type: "JS" | "VALUE" | "HTML"; | ||
value: string; | ||
@@ -508,3 +508,3 @@ name: string; | ||
extract?: { | ||
type?: "JS" | "VALUE" | undefined; | ||
type?: "JS" | "VALUE" | "HTML" | undefined; | ||
value: string; | ||
@@ -511,0 +511,0 @@ name: string; |
@@ -6,2 +6,3 @@ import { AxiosResponse } from "axios"; | ||
export declare const executeScript: (script: string, resp: AxiosResponse, ctx: Context) => any; | ||
export declare const extractFromHTML: (querySelectorKey: string, resp: AxiosResponse, ctx: Context) => any; | ||
export declare const stringReplacement: (string: string, envVars: Context["envVars"]) => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringReplacement = exports.executeScript = exports.processEnvVars = exports.ALLOWED_DATA_TYPES = void 0; | ||
exports.stringReplacement = exports.extractFromHTML = exports.executeScript = exports.processEnvVars = exports.ALLOWED_DATA_TYPES = void 0; | ||
const tslib_1 = require("tslib"); | ||
const vm2_1 = tslib_1.__importDefault(require("vm2")); | ||
const Handlebars = tslib_1.__importStar(require("handlebars")); | ||
const jsdom_1 = tslib_1.__importDefault(require("jsdom")); | ||
const SCRIPT_DEFAULT_TIMEOUT = 1000; | ||
@@ -35,2 +36,14 @@ exports.ALLOWED_DATA_TYPES = ["string", "bigint", "number", "boolean", "undefined", "null"]; | ||
exports.executeScript = executeScript; | ||
const extractFromHTML = (querySelectorKey, resp, ctx) => { | ||
const vm = createVM(resp, ctx); | ||
vm.freeze(jsdom_1.default.JSDOM.fragment, "jsdom"); | ||
const dom = jsdom_1.default.JSDOM.fragment(resp.data); | ||
vm.freeze(resp.data, "body"); | ||
const execResponse = vm.run(` | ||
const dom = jsdom(body); | ||
dom.querySelector("${querySelectorKey}") | ||
`); | ||
return execResponse; | ||
}; | ||
exports.extractFromHTML = extractFromHTML; | ||
const stringReplacement = (string, envVars) => { | ||
@@ -37,0 +50,0 @@ const template = Handlebars.compile(string); |
{ | ||
"name": "@metlo/testing", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"license": "MIT", | ||
@@ -17,2 +17,3 @@ "main": "dist/index.js", | ||
"@types/js-yaml": "^4.0.5", | ||
"@types/jsdom": "^20.0.1", | ||
"@types/lodash.get": "^4.4.7", | ||
@@ -31,2 +32,3 @@ "@types/uuid": "^9.0.0", | ||
"js-yaml": "^4.1.0", | ||
"jsdom": "^20.0.3", | ||
"lodash.get": "^4.4.2", | ||
@@ -33,0 +35,0 @@ "uuid": "^9.0.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
95971
1671
10
10
+ Addedjsdom@^20.0.3
+ Added@tootallnate/once@2.0.0(transitive)
+ Addedabab@2.0.6(transitive)
+ Addedacorn-globals@7.0.1(transitive)
+ Addedagent-base@6.0.2(transitive)
+ Addedcssom@0.3.80.5.0(transitive)
+ Addedcssstyle@2.3.0(transitive)
+ Addeddata-urls@3.0.2(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addeddecimal.js@10.4.3(transitive)
+ Addeddomexception@4.0.0(transitive)
+ Addedentities@4.5.0(transitive)
+ Addedescodegen@2.1.0(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedestraverse@5.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedhtml-encoding-sniffer@3.0.0(transitive)
+ Addedhttp-proxy-agent@5.0.0(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedis-potential-custom-element-name@1.0.1(transitive)
+ Addedjsdom@20.0.3(transitive)
+ Addedms@2.1.3(transitive)
+ Addednwsapi@2.2.13(transitive)
+ Addedparse5@7.2.1(transitive)
+ Addedpsl@1.13.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedquerystringify@2.2.0(transitive)
+ Addedrequires-port@1.0.0(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsaxes@6.0.0(transitive)
+ Addedsymbol-tree@3.2.4(transitive)
+ Addedtough-cookie@4.1.4(transitive)
+ Addedtr46@3.0.0(transitive)
+ Addeduniversalify@0.2.0(transitive)
+ Addedurl-parse@1.5.10(transitive)
+ Addedw3c-xmlserializer@4.0.0(transitive)
+ Addedwebidl-conversions@7.0.0(transitive)
+ Addedwhatwg-encoding@2.0.0(transitive)
+ Addedwhatwg-mimetype@3.0.0(transitive)
+ Addedwhatwg-url@11.0.0(transitive)
+ Addedws@8.18.0(transitive)
+ Addedxml-name-validator@4.0.0(transitive)
+ Addedxmlchars@2.2.0(transitive)