Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@metlo/testing

Package Overview
Dependencies
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metlo/testing - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

23

dist/generate/sample-request.js

@@ -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;

2

dist/index.d.ts

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc