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.6 to 0.2.7

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", "HTML"]>;
export declare const ExtractorType: import("zod").Values<["VALUE", "JS", "REGEXP", "HTML"]>;
export { KeyValType, TestConfig, TestRequest, TestResult, TestConfigSchema, FailedAssertion, FailedRequest, } from "./types/test";

@@ -10,0 +10,0 @@ export { GenTestEndpoint, GenTestContext, GeneratedTestRequest, GenTestEndpointDataField, } from "./generate/types";

@@ -8,2 +8,8 @@ "use strict";

const runAssertion = (assertion, response, ctx) => {
if (typeof assertion == "string") {
assertion = {
type: enums_1.AssertionType.enum.JS,
value: assertion,
};
}
if (assertion.type == enums_1.AssertionType.enum.JS) {

@@ -10,0 +16,0 @@ if ((typeof assertion.value).toLowerCase() === "string") {

@@ -19,2 +19,5 @@ "use strict";

}
else if (extractor.type == enums_1.ExtractorType.enum.REGEXP) {
ctx.envVars[extractor.name] = (0, utils_2.extractRegexp)(extractorVal, response, ctx);
}
return ctx;

@@ -21,0 +24,0 @@ };

@@ -0,3 +1,4 @@

import { AxiosRequestConfig } from "axios";
import { TestRequest } from "../types/test";
import { Context } from "../types/context";
export declare const makeRequest: (req: TestRequest, ctx: Context) => Promise<import("axios").AxiosResponse<any, any>>;
export declare const makeRequest: (req: TestRequest, ctx: Context) => AxiosRequestConfig<any>;

@@ -5,8 +5,6 @@ "use strict";

exports.makeRequest = void 0;
const tslib_1 = require("tslib");
const axios_1 = tslib_1.__importDefault(require("axios"));
const utils_1 = require("../utils");
const BLOCKED_HOSTS = new Set((_a = process.env.METLO_TEST_BLOCKED_HOSTS) === null || _a === void 0 ? void 0 : _a.split(","));
const makeRequest = (req, ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
var _b;
const makeRequest = (req, ctx) => {
var _a;
const currentUrl = (0, utils_1.stringReplacement)(req.url, ctx.envVars);

@@ -18,3 +16,3 @@ const urlObj = new URL(req.url);

const host = urlObj.host;
const queryParams = (_b = req.query) === null || _b === void 0 ? void 0 : _b.map(({ name, value }) => `${(0, utils_1.stringReplacement)(name, ctx.envVars)}=${(0, utils_1.stringReplacement)(value, ctx.envVars)}`).join("&");
const queryParams = (_a = req.query) === null || _a === void 0 ? void 0 : _a.map(({ name, value }) => `${(0, utils_1.stringReplacement)(name, ctx.envVars)}=${(0, utils_1.stringReplacement)(value, ctx.envVars)}`).join("&");
const currUrlCookies = ctx.cookies[host] || {};

@@ -49,3 +47,3 @@ const headers = Object.fromEntries((req.headers || []).map(({ name, value }) => [

}
return yield (0, axios_1.default)({
return {
url,

@@ -57,5 +55,5 @@ method: req.method,

validateStatus: () => true,
});
});
};
};
exports.makeRequest = makeRequest;
//# sourceMappingURL=request.js.map

@@ -5,2 +5,3 @@ "use strict";

const tslib_1 = require("tslib");
const axios_1 = tslib_1.__importDefault(require("axios"));
const request_1 = require("./request");

@@ -32,4 +33,11 @@ const assertions_1 = require("./assertions");

let errStack = undefined;
const reqConfig = (0, request_1.makeRequest)(step.request, ctx);
const stepRequest = {
url: reqConfig.url,
method: reqConfig.method,
headers: reqConfig.headers,
data: reqConfig.data,
};
try {
res = yield (0, request_1.makeRequest)(step.request, ctx);
res = yield (0, axios_1.default)(reqConfig);
}

@@ -60,2 +68,3 @@ catch (e) {

assertions,
req: stepRequest,
res: axiosRespToStepResponse(res),

@@ -71,2 +80,3 @@ };

err: err,
req: stepRequest,
errStack: errStack,

@@ -73,0 +83,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", "HTML"]>;
export declare const ExtractorType: z.ZodEnum<["VALUE", "JS", "REGEXP", "HTML"]>;

@@ -18,3 +18,3 @@ "use strict";

exports.AssertionType = zod_1.z.enum(["EQ", "REGEXP", "JS"]);
exports.ExtractorType = zod_1.z.enum(["VALUE", "JS", "HTML"]);
exports.ExtractorType = zod_1.z.enum(["VALUE", "JS", "REGEXP", "HTML"]);
//# sourceMappingURL=enums.js.map

@@ -96,14 +96,14 @@ import { z } from "zod";

name: z.ZodString;
type: z.ZodDefault<z.ZodEnum<["VALUE", "JS", "HTML"]>>;
type: z.ZodDefault<z.ZodEnum<["VALUE", "JS", "REGEXP", "HTML"]>>;
value: z.ZodString;
}, "strip", z.ZodTypeAny, {
type: "JS" | "VALUE" | "HTML";
type: "REGEXP" | "JS" | "VALUE" | "HTML";
value: string;
name: string;
}, {
type?: "JS" | "VALUE" | "HTML" | undefined;
type?: "REGEXP" | "JS" | "VALUE" | "HTML" | undefined;
value: string;
name: string;
}>;
export declare const AssertionSchema: z.ZodObject<{
export declare const AssertionSchema: z.ZodUnion<[z.ZodObject<{
type: z.ZodDefault<z.ZodEnum<["EQ", "REGEXP", "JS"]>>;

@@ -120,3 +120,3 @@ key: z.ZodOptional<z.ZodString>;

value: string | number | boolean | (string | number | boolean)[];
}>;
}>, z.ZodString]>;
export declare const TestStepSchema: z.ZodObject<{

@@ -192,14 +192,14 @@ request: z.ZodObject<{

name: z.ZodString;
type: z.ZodDefault<z.ZodEnum<["VALUE", "JS", "HTML"]>>;
type: z.ZodDefault<z.ZodEnum<["VALUE", "JS", "REGEXP", "HTML"]>>;
value: z.ZodString;
}, "strip", z.ZodTypeAny, {
type: "JS" | "VALUE" | "HTML";
type: "REGEXP" | "JS" | "VALUE" | "HTML";
value: string;
name: string;
}, {
type?: "JS" | "VALUE" | "HTML" | undefined;
type?: "REGEXP" | "JS" | "VALUE" | "HTML" | undefined;
value: string;
name: string;
}>, "many">>;
assert: z.ZodOptional<z.ZodArray<z.ZodObject<{
assert: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodObject<{
type: z.ZodDefault<z.ZodEnum<["EQ", "REGEXP", "JS"]>>;

@@ -216,14 +216,14 @@ key: z.ZodOptional<z.ZodString>;

value: string | number | boolean | (string | number | boolean)[];
}>, "many">>;
}>, z.ZodString]>, "many">>;
}, "strip", z.ZodTypeAny, {
extract?: {
type: "JS" | "VALUE" | "HTML";
type: "REGEXP" | "JS" | "VALUE" | "HTML";
value: string;
name: string;
}[] | undefined;
assert?: {
assert?: (string | {
key?: string | undefined;
type: "EQ" | "REGEXP" | "JS";
value: string | number | boolean | (string | number | boolean)[];
}[] | undefined;
})[] | undefined;
request: {

@@ -248,11 +248,11 @@ data?: string | undefined;

extract?: {
type?: "JS" | "VALUE" | "HTML" | undefined;
type?: "REGEXP" | "JS" | "VALUE" | "HTML" | undefined;
value: string;
name: string;
}[] | undefined;
assert?: {
assert?: (string | {
type?: "EQ" | "REGEXP" | "JS" | undefined;
key?: string | undefined;
value: string | number | boolean | (string | number | boolean)[];
}[] | undefined;
})[] | undefined;
request: {

@@ -371,14 +371,14 @@ data?: string | undefined;

name: z.ZodString;
type: z.ZodDefault<z.ZodEnum<["VALUE", "JS", "HTML"]>>;
type: z.ZodDefault<z.ZodEnum<["VALUE", "JS", "REGEXP", "HTML"]>>;
value: z.ZodString;
}, "strip", z.ZodTypeAny, {
type: "JS" | "VALUE" | "HTML";
type: "REGEXP" | "JS" | "VALUE" | "HTML";
value: string;
name: string;
}, {
type?: "JS" | "VALUE" | "HTML" | undefined;
type?: "REGEXP" | "JS" | "VALUE" | "HTML" | undefined;
value: string;
name: string;
}>, "many">>;
assert: z.ZodOptional<z.ZodArray<z.ZodObject<{
assert: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodObject<{
type: z.ZodDefault<z.ZodEnum<["EQ", "REGEXP", "JS"]>>;

@@ -395,14 +395,14 @@ key: z.ZodOptional<z.ZodString>;

value: string | number | boolean | (string | number | boolean)[];
}>, "many">>;
}>, z.ZodString]>, "many">>;
}, "strip", z.ZodTypeAny, {
extract?: {
type: "JS" | "VALUE" | "HTML";
type: "REGEXP" | "JS" | "VALUE" | "HTML";
value: string;
name: string;
}[] | undefined;
assert?: {
assert?: (string | {
key?: string | undefined;
type: "EQ" | "REGEXP" | "JS";
value: string | number | boolean | (string | number | boolean)[];
}[] | undefined;
})[] | undefined;
request: {

@@ -427,11 +427,11 @@ data?: string | undefined;

extract?: {
type?: "JS" | "VALUE" | "HTML" | undefined;
type?: "REGEXP" | "JS" | "VALUE" | "HTML" | undefined;
value: string;
name: string;
}[] | undefined;
assert?: {
assert?: (string | {
type?: "EQ" | "REGEXP" | "JS" | undefined;
key?: string | undefined;
value: string | number | boolean | (string | number | boolean)[];
}[] | undefined;
})[] | undefined;
request: {

@@ -468,11 +468,11 @@ data?: string | undefined;

extract?: {
type: "JS" | "VALUE" | "HTML";
type: "REGEXP" | "JS" | "VALUE" | "HTML";
value: string;
name: string;
}[] | undefined;
assert?: {
assert?: (string | {
key?: string | undefined;
type: "EQ" | "REGEXP" | "JS";
value: string | number | boolean | (string | number | boolean)[];
}[] | undefined;
})[] | undefined;
request: {

@@ -509,11 +509,11 @@ data?: string | undefined;

extract?: {
type?: "JS" | "VALUE" | "HTML" | undefined;
type?: "REGEXP" | "JS" | "VALUE" | "HTML" | undefined;
value: string;
name: string;
}[] | undefined;
assert?: {
assert?: (string | {
type?: "EQ" | "REGEXP" | "JS" | undefined;
key?: string | undefined;
value: string | number | boolean | (string | number | boolean)[];
}[] | undefined;
})[] | undefined;
request: {

@@ -545,2 +545,8 @@ data?: string | undefined;

export type TestConfig = z.infer<typeof TestConfigSchema>;
export interface StepRequest {
url: string;
method: string;
headers: Record<string, string>;
data?: string;
}
export interface StepResponse {

@@ -559,2 +565,3 @@ data: any;

assertions: boolean[];
req: StepRequest;
res?: StepResponse;

@@ -561,0 +568,0 @@ }

@@ -39,7 +39,10 @@ "use strict";

});
exports.AssertionSchema = zod_1.z.object({
type: enums_1.AssertionType.default(enums_1.AssertionType.enum.EQ),
key: zod_1.z.string().optional(),
value: zod_1.z.union([exports.PrimitiveValueSchema, exports.PrimitiveValueSchema.array()]),
});
exports.AssertionSchema = zod_1.z.union([
zod_1.z.object({
type: enums_1.AssertionType.default(enums_1.AssertionType.enum.EQ),
key: zod_1.z.string().optional(),
value: zod_1.z.union([exports.PrimitiveValueSchema, exports.PrimitiveValueSchema.array()]),
}),
zod_1.z.string(),
]);
exports.TestStepSchema = zod_1.z.object({

@@ -46,0 +49,0 @@ request: exports.RequestSchema,

@@ -7,2 +7,3 @@ import { AxiosResponse } from "axios";

export declare const extractFromHTML: (querySelectorKey: string, resp: AxiosResponse, ctx: Context) => any;
export declare const extractRegexp: (regexp: string, resp: AxiosResponse, ctx: Context) => string;
export declare const stringReplacement: (string: string, envVars: Context["envVars"]) => string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringReplacement = exports.extractFromHTML = exports.executeScript = exports.processEnvVars = exports.ALLOWED_DATA_TYPES = void 0;
exports.stringReplacement = exports.extractRegexp = exports.extractFromHTML = exports.executeScript = exports.processEnvVars = exports.ALLOWED_DATA_TYPES = void 0;
const tslib_1 = require("tslib");

@@ -9,3 +9,10 @@ const vm2_1 = tslib_1.__importDefault(require("vm2"));

const SCRIPT_DEFAULT_TIMEOUT = 1000;
exports.ALLOWED_DATA_TYPES = ["string", "bigint", "number", "boolean", "undefined", "null"];
exports.ALLOWED_DATA_TYPES = [
"string",
"bigint",
"number",
"boolean",
"undefined",
"null",
];
const processEnvVars = (base, envVars) => {

@@ -19,3 +26,8 @@ for (let [key, value] of Object.entries(envVars)) {

const createVM = (resp, ctx) => {
const vm = new vm2_1.default.VM({ timeout: SCRIPT_DEFAULT_TIMEOUT, allowAsync: false, eval: false, wasm: false, });
const vm = new vm2_1.default.VM({
timeout: SCRIPT_DEFAULT_TIMEOUT,
allowAsync: false,
eval: false,
wasm: false,
});
const sandboxItems = {};

@@ -50,5 +62,20 @@ Object.entries(ctx.envVars).forEach(([k, v]) => vm.freeze(v, k));

exports.extractFromHTML = extractFromHTML;
const extractRegexp = (regexp, resp, ctx) => {
let strData = "";
if (typeof resp.data == "string") {
strData = resp.data;
}
if (typeof resp.data == "object") {
strData = JSON.stringify(resp.data);
}
const match = strData.match(new RegExp(regexp));
if (match) {
return match[0];
}
return "";
};
exports.extractRegexp = extractRegexp;
const stringReplacement = (string, envVars) => {
const template = Handlebars.compile(string);
const templated = (template(envVars));
const templated = template(envVars);
return templated;

@@ -55,0 +82,0 @@ };

{
"name": "@metlo/testing",
"version": "0.2.6",
"version": "0.2.7",
"license": "MIT",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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

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