@zoroaster/mask
Version:
The Code For Zoroaster Mask Testing.
853 lines (850 loc) • 25.2 kB
JavaScript
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const os = require('os');
const readline = require('readline');
const stream = require('stream');
const child_process = require('child_process');
/*
diff package https://github.com/kpdecker/jsdiff
BSD License
Copyright (c) 2009-2015, Kevin Decker <kpdecker@gmail.com>
*/
function E(a, b, c) {
let g = a[a.length - 1];
g && g.g === b && g.i === c ? a[a.length - 1] = {count:g.count + 1, g:b, i:c} : a.push({count:1, g:b, i:c});
}
function F(a, b, c, g, f) {
let h = c.length, e = g.length, d = b.f;
f = d - f;
let k = 0;
for (; d + 1 < h && f + 1 < e && a.equals(c[d + 1], g[f + 1]);) {
d++, f++, k++;
}
k && b.h.push({count:k});
b.f = d;
return f;
}
function G(a) {
let b = [];
for (let c = 0; c < a.length; c++) {
a[c] && b.push(a[c]);
}
return b;
}
function aa(a, b) {
var c = new ba;
a = G(a.split(""));
b = G(b.split(""));
let g = b.length, f = a.length, h = 1, e = g + f, d = [{f:-1, h:[]}];
var k = F(c, d[0], b, a, 0);
if (d[0].f + 1 >= g && k + 1 >= f) {
return [{value:c.join(b), count:b.length}];
}
for (; h <= e;) {
a: {
for (k = -1 * h; k <= h; k += 2) {
var l = void 0;
l = d[k - 1];
let q = d[k + 1];
var n = (q ? q.f : 0) - k;
l && (d[k - 1] = void 0);
let r = l && l.f + 1 < g;
n = q && 0 <= n && n < f;
if (r || n) {
!r || n && l.f < q.f ? (l = {f:q.f, h:q.h.slice(0)}, E(l.h, void 0, !0)) : (l.f++, E(l.h, !0, void 0));
n = F(c, l, b, a, k);
if (l.f + 1 >= g && n + 1 >= f) {
k = ca(c, l.h, b, a);
break a;
}
d[k] = l;
} else {
d[k] = void 0;
}
}
h++;
k = void 0;
}
if (k) {
return k;
}
}
}
class ba {
equals(a, b) {
return a === b;
}
join(a) {
return a.join("");
}
}
function ca(a, b, c, g) {
let f = 0, h = b.length, e = 0, d = 0;
for (; f < h; f++) {
var k = b[f];
if (k.i) {
k.value = a.join(g.slice(d, d + k.count)), d += k.count, f && b[f - 1].g && (k = b[f - 1], b[f - 1] = b[f], b[f] = k);
} else {
if (k.g) {
k.value = a.join(c.slice(e, e + k.count));
} else {
let l = c.slice(e, e + k.count);
l = l.map(function(n, q) {
q = g[d + q];
return q.length > n.length ? q : n;
});
k.value = a.join(l);
}
e += k.count;
k.g || (d += k.count);
}
}
c = b[h - 1];
1 < h && "string" === typeof c.value && (c.g || c.i) && a.equals("", c.value) && (b[h - 2].value += c.value, b.pop());
return b;
}
;const da = {black:30, red:31, green:32, yellow:33, blue:34, magenta:35, cyan:36, white:37, grey:90}, ea = {black:40, red:41, green:42, yellow:43, blue:44, magenta:45, cyan:46, white:47}, J = {reset:0, bold:1, underline:4, slow_blink:5, A:6, reverse:7, conceal:8, crossed_out:9, primary_font:10}, K = a => {
Array.isArray(a) && (a = a.join(";"));
return `\x1b[${a}m`;
};
function L(a, b) {
b = [da[b], ...Object.keys({}).map(g => J[g.toLowerCase()])].filter(Boolean);
if (!b.length) {
return a;
}
b = K(b);
const c = K(J.reset);
return `${b}${a}${c}`;
}
function M(a) {
a = [ea[a], ...Object.keys({}).map(c => J[c])].filter(Boolean);
if (!a.length) {
return " ";
}
a = K(a);
const b = K(J.reset);
return `${a}${" "}${b}`;
}
function N(a, b) {
return aa(a, b).map(({g:c, i:g, value:f}) => {
let h;
const e = f.split(" ");
if (c || g) {
h = e.map(d => d.replace(/(\r?\n)$/mg, "\u23ce$1").replace(/(\r+)([^\n]|$)/g, (k, l, n) => "<CR>".repeat(l.length) + n));
}
c ? h = h.map(d => L(d, "green")).join(M("green")) : g ? h = h.map(d => L(d, "red")).join(M("red")) : h = L(f, "grey");
return h;
}).join("");
}
;const O = fs.lstatSync, fa = fs.readFileSync, P = fs.readdirSync, ha = fs.writeFileSync;
const Q = path.basename, ia = path.dirname, R = path.join, ja = path.normalize;
const ka = assert.deepStrictEqual, la = assert.equal, ma = assert.strictEqual;
function oa(a, b, c, g = !1) {
const f = [];
b.replace(a, (h, ...e) => {
h = e[e.length - 2];
h = g ? {position:h} : {};
e = e.slice(0, e.length - 2).reduce((d, k, l) => {
l = c[l];
if (!l || void 0 === k) {
return d;
}
d[l] = k;
return d;
}, h);
f.push(e);
});
return f;
}
;const pa = readline.createInterface;
function qa(a, b, c) {
return setTimeout(() => {
const g = Error(`${a ? a : "Promise"} has timed out after ${b}ms`);
g.stack = `Error: ${g.message}`;
c(g);
}, b);
}
function ra(a, b) {
let c;
const g = new Promise((f, h) => {
c = qa(a, b, h);
});
return {timeout:c, promise:g};
}
async function sa(a, b, c) {
if (!(a instanceof Promise)) {
throw Error("Promise expected");
}
if (!b) {
throw Error("Timeout must be a number");
}
if (0 > b) {
throw Error("Timeout cannot be negative");
}
const {promise:g, timeout:f} = ra(c, b);
try {
return await Promise.race([a, g]);
} finally {
clearTimeout(f);
}
}
;function ta(a, b = {}) {
const {timeout:c, password:g = !1, output:f = process.stdout, input:h = process.stdin, ...e} = b, d = pa({input:h, output:f, ...e});
if (g) {
const k = d.output;
d._writeToOutput = l => {
if (["\r\n", "\n", "\r"].includes(l)) {
return k.write(l);
}
l = l.split(a);
"2" == l.length ? (k.write(a), k.write("*".repeat(l[1].length))) : k.write("*");
};
}
b = new Promise(k => {
d.question(a, k);
});
b = c ? sa(b, c, `reloquent: ${a}`) : b;
d.promise = ua(b, d);
return d;
}
const ua = async(a, b) => {
try {
return await a;
} finally {
b.close();
}
};
async function va(a, b) {
if ("object" != typeof a) {
throw Error("Please give an object with questions");
}
return await Object.keys(a).reduce(async(c, g) => {
c = await c;
var f = a[g];
switch(typeof f) {
case "object":
f = {...f};
break;
case "string":
f = {text:f};
break;
default:
throw Error("A question must be a string or an object.");
}
f.text = `${f.text}${f.text.endsWith("?") ? "" : ":"} `;
var h;
if (f.defaultValue) {
var e = f.defaultValue;
}
f.getDefault && (h = await f.getDefault());
let d = e || "";
e && h && e != h ? d = `\x1b[90m${e}\x1b[0m` : e && e == h && (d = "");
e = h || "";
({promise:e} = ta(`${f.text}${d ? `[${d}] ` : ""}${e ? `[${e}] ` : ""}`, {timeout:b, password:f.password, ...f}));
h = await e || h || f.defaultValue;
"function" == typeof f.validation && f.validation(h);
"function" == typeof f.postProcess && (h = await f.postProcess(h));
return {...c, [g]:h};
}, {});
}
;async function wa(a) {
({question:a} = await va({question:a}, void 0));
return a;
}
async function xa() {
const {defaultYes:a = !0, timeout:b} = {};
var c = {text:"Update the result"};
const g = c.text, f = g.endsWith("?");
({question:c} = await va({question:{defaultValue:a ? "y" : "n", ...c, text:`${f ? g.replace(/\?$/, "") : g} (y/n)${f ? "?" : ""}`}}, b));
return "y" == c;
}
;const ya = (a, b) => {
let c = [];
a.replace(b, (g, f) => {
c.push({position:f, separator:g});
});
c = [{position:0, separator:""}, ...c];
return c.reduce((g, {position:f, separator:h}, e, d) => {
var k = h.length;
e = d[e + 1];
if (!e) {
return k = a.slice(f + k), g.push({position:f, separator:h, match:k}), g;
}
k = a.slice(f + k, e.position);
g.push({position:f, separator:h, match:k});
return g;
}, []);
}, za = (a, b, c) => Object.keys(a).reduce((g, f) => {
let h;
const e = a[f];
if (b.includes(f)) {
try {
h = JSON.parse(e);
} catch (d) {
throw Error(`Could not parse JSON property "${f}": ${d.message}.`);
}
} else {
if (c.includes(f)) {
try {
h = eval(`(${e})`);
} catch (d) {
throw Error(`Could not evaluate JS property "${f}": ${d.message}.`);
}
} else {
h = e;
}
}
g[f] = h;
return g;
}, {});
const S = os.EOL, Aa = os.homedir;
const Da = a => {
const {path:b, propStartRe:c = /\/\*/, propEndRe:g = /\/\*\*\//} = a;
let {splitRe:f, jsonProps:h} = a;
f || (f = b.endsWith(".md") ? /^## /gm : /^\/\/ /gm);
let e = fa(b, "utf8");
const d = f.exec(e);
if (!d) {
throw Error(`${b} does not contain tests.`);
}
const k = e.slice(0, d.index).replace(/\r?\n\r?\n$/, "");
a = e.slice(d.index);
f.lastIndex = 0;
a = ya(a, f).filter(({match:r}) => r).map(({match:r, position:p, separator:m}) => {
const [w, y] = Ba(r), [B, t] = Ca(y, new RegExp(`\\r?\\n${c.source}`)), A = r.indexOf(t);
r = B.replace(/\r?\n$/, "");
const v = d.index + A + p + m.length, z = {};
p = oa(new RegExp(`(${c.source} +(.+) +\\*\\/(\\r?\\n)?)([\\s\\S]*?)\\r?\\n${g.source}`, "g"), t, ["preValue", "key", "newLine", "value"], !0).reduce((u, {preValue:x, key:C, newLine:D, value:H, position:I}) => {
z[C] = {start:v + I + x.length, length:H.length};
return {...u, [C]:!H && D ? D : H};
}, {});
return {name:w, input:r, v:z, ...k ? {preamble:k} : {}, ...p};
});
const l = e.split(S);
let n = 0;
const q = async(r, p, m) => {
const w = new RegExp(`${f.source}${r}\r?$`), y = l.reduce((t, A, v) => t ? t : w.test(A) ? v + 1 : t, null), B = Error(m.message);
B.stack = `Error: ${m.message}${S} at ${r} (${b}:${y}:1)`;
if (m.property && m.actual) {
const {property:t, actual:A, expected:v} = m;
B.handleUpdate = async({stdin:z} = {}) => {
const u = p[t];
if (!u) {
return !1;
}
var x = u.start + n, C = e.slice(0, x);
0 == u.length && (C += S);
var D = e.slice(x + u.length);
x = h.includes(t) ? JSON.stringify(A, null, 2) : A;
C = `${C}${x}${D}`;
console.error('Result does not match property "%s"', t);
console.error(" at %s (%s:%s:1)", L(r, "blue"), b, y);
D = !1;
z = await wa({text:"Show more (d), skip (s), or update (u): [u]", input:z});
"d" == z ? (console.log(L("Actual: ", "blue")), console.log(A), console.log(L("Expected: ", "blue")), console.log(v), D = await xa()) : z && "u" != z || (D = !0);
if (!D) {
return !1;
}
n += x.length - u.length;
ha(b, C);
console.log("updated file", b);
e = C;
return !0;
};
}
throw B;
};
return a.map(({name:r, v:p, ...m}) => {
p = q.bind(null, r, p);
return {...m, name:r, u:p};
});
}, Ca = (a, b) => {
const c = a.search(b);
if (0 > c) {
throw Error(`Could not process "${a}": propStart re ${b} returned -1`);
}
return [a.substr(0, c), a.substr(c + 1)];
}, Ba = a => {
const b = a.indexOf(S);
return [a.substr(0, b), a.substr(b + S.length)];
}, Ea = (a, b, c = console.log) => {
try {
la(a, b);
} catch (g) {
throw a = N(b, a), c(a), g.property = "expected", g;
}
};
const Fa = stream.PassThrough, Ga = stream.Writable;
const Ha = (a, b = 0, c = !1) => {
if (0 === b && !c) {
return a;
}
a = a.split("\n", c ? b + 1 : void 0);
return c ? a[a.length - 1] : a.slice(b).join("\n");
}, Ia = (a, b = !1) => Ha(a, 2 + (b ? 1 : 0)), Ja = a => {
({callee:{caller:a}} = a);
return a;
};
const Ka = /\s+at.*(?:\(|\s)(.*)\)?/, La = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:IGNORED_MODULES)\/.*)?\w+)\.js:\d+:\d+)|native)/, Ma = a => {
const {pretty:b = !1, ignoredModules:c = ["pirates", "@artdeco/pirates"]} = {}, g = c.join("|"), f = new RegExp(La.source.replace("IGNORED_MODULES", g));
return a.replace(/\\/g, "/").split("\n").filter(h => {
h = h.match(Ka);
if (null === h || !h[1]) {
return !0;
}
h = h[1];
return h.includes(".app/Contents/Resources/electron.asar") || h.includes(".app/Contents/Resources/default_app.asar") ? !1 : !f.test(h);
}).filter(h => h.trim()).map(h => {
if (b) {
const e = Aa().replace(/\\/g, "/");
return h.replace(/\s+at.*(?:\(|\s)(.*)\)?/, (d, k) => d.replace(k, k.replace(e, "~")));
}
return h;
}).join("\n");
};
function Na(a, b, c = !1) {
return function(g) {
var f = Ja(arguments), {stack:h} = Error();
const e = Ha(h, 2, !0), d = (h = g instanceof Error) ? g.message : g;
f = [`Error: ${d}`, ...null !== f && a === f || c ? [b] : [e, b]].join("\n");
f = Ma(f);
return Object.assign(h ? g : Error(), {message:d, stack:f});
};
}
;function T(a) {
var {stack:b} = Error();
const c = Ja(arguments);
b = Ia(b, a);
return Na(c, b, a);
}
;const Oa = (a, b) => {
b.once("error", c => {
a.emit("error", c);
});
return b;
};
class U extends Ga {
constructor(a) {
const {binary:b = !1, rs:c = null, ...g} = a || {}, {s:f = T(!0), proxyError:h} = a || {}, e = (d, k) => f(k);
super(g);
this.j = [];
this.o = new Promise((d, k) => {
this.on("finish", () => {
let l;
b ? l = Buffer.concat(this.j) : l = this.j.join("");
d(l);
this.j = [];
});
this.once("error", l => {
if (-1 == l.stack.indexOf("\n")) {
e`${l}`;
} else {
const n = Ma(l.stack);
l.stack = n;
h && e`${l}`;
}
k(l);
});
c && Oa(this, c).pipe(this);
});
}
_write(a, b, c) {
this.j.push(a);
c();
}
get promise() {
return this.o;
}
}
const V = async a => {
({promise:a} = new U({rs:a, s:T(!0)}));
return await a;
};
const Pa = async(a, b) => {
await b(a);
}, Qa = async(a, b) => {
if (b instanceof RegExp) {
if (!b.test(a)) {
throw Error(`${a} does not match regular expression ${b}`);
}
} else {
if ("function" == typeof b) {
await Pa(a, b);
} else {
if (b && a != b) {
const c = N(`${a}`, `${b}`);
throw Error(`${c}${S}${`${a} != ${b}`}`);
}
}
}
};
async function Ra(a) {
if (!a) {
throw Error("Config expected.");
}
const b = T(!0), {fn:c, args:g = [], context:f, error:h, ...e} = a;
if ("function" != typeof c) {
throw Error("Function expected.");
}
a = Array.isArray(g) ? g : [g];
try {
return await Sa(c, f, a, h, e);
} catch (d) {
throw b(d);
}
}
const Sa = async(a, b, c, g, f) => {
const h = Error();
try {
throw b ? await a.call(b, ...c) : await a(...c), h;
} catch (e) {
if (e === h) {
throw Error(`Function ${a.name && "fn" !== a.name ? `${a.name} ` : ""}should have thrown.`);
}
if (g && g !== e) {
throw Error(`${e} is not strict equal to ${g}.`);
}
await Object.keys(f).reduce(async(d, k) => {
await d;
await Qa(e[k], f[k]);
}, {});
return e;
}
};
const W = (...a) => {
let b = -1;
return "%s%s".replace(/%s/g, () => {
b++;
return a[b];
});
};
function Ta(a, b) {
let c = 0;
const g = (e, d) => {
const k = " ".repeat(2 * c);
d = void 0 !== d ? L("+ " + X(d), "green") : null;
e = void 0 !== e ? L("- " + X(e), "red") : null;
const l = [];
e && l.push(W(k, e));
d && l.push(W(k, d));
return l.join("\n");
}, f = e => {
const d = " ".repeat(2 * c);
return W(d, e);
}, h = (e, d) => {
if (e instanceof Date && d instanceof Date) {
var k = e.getTime() != d.getTime() ? !1 : void 0;
return k ? "" : g(e, d);
}
if (e instanceof Date && !(d instanceof Date) || !(e instanceof Date) && d instanceof Date || Array.isArray(e) && !Array.isArray(d) || !Array.isArray(e) && Array.isArray(d)) {
return g(e, d);
}
if (Y(e) && Y(d) || !Y(e) && Y(d) || Y(e) && !Y(d)) {
return e != d ? g(e, d) : "";
}
if (e.constructor && !d.constructor) {
return g(e.constructor.name, d);
}
if (!e.constructor && d.constructor) {
return g(e, d.constructor.name);
}
if (e.constructor && d.constructor) {
if (e.constructor.name != d.constructor.name) {
return g(e.constructor.name, d.constructor.name);
}
k = e.valueOf();
var l = d.valueOf();
if (Y(k) && Y(l) && k != l) {
return g(k, l);
}
}
if (Array.isArray(e) && Array.isArray(d)) {
let n;
k = e.map((q, r) => {
n = r;
(q = h(q, d[r])) && (q = `${f(`[${r}]`)}\n${q}`);
return q;
}).filter(Boolean);
l = d.slice(n + 1).map((q, r) => `${f(`[${n + r + 1}]`)}\n${g(void 0, q)}`);
return [...k, ...l].join("\n");
}
if ("object" == typeof e && "object" == typeof d) {
const n = [], q = [], r = [];
Object.keys(e).forEach(m => {
m in d ? r.push(m) : q.push(m);
});
Object.keys(d).forEach(m => {
m in e || n.push(m);
});
k = q.map(m => g(`${m}${`: ${X(e[m])}`}`));
l = n.map(m => g(void 0, `${m}: ${X(d[m])}`));
const p = r.map(m => {
c++;
const w = h(e[m], d[m]);
let y = "";
w && (y += f(Array.isArray(e[m]) && Array.isArray(d[m]) ? `${m}.Array` : m), y += "\n" + w);
c--;
return y;
}).filter(Boolean);
return [...k, ...l, ...p].join("\n");
}
console.error("Could not compare two values: %s %s. Please file a bug with differently.", e, d);
};
return h(a, b);
}
const Y = a => null === a ? !0 : "string number boolean symbol null undefined".split(" ").includes(typeof a), X = a => Array.isArray(a) ? `Array[${a.toString()}]` : a && a.toString ? a.toString() : `${a}`;
function Ua(a, b) {
try {
ka(a, b, void 0);
} catch (c) {
throw a = Ta(b, a), c.message = ["deepStrictEqual failed:", a].filter(Boolean).join(S), c;
}
}
;const Va = child_process.fork;
const Wa = async a => {
const [b, c, g] = await Promise.all([new Promise((f, h) => {
a.on("error", h).on("exit", e => {
f(e);
});
}), a.stdout ? V(a.stdout) : void 0, a.stderr ? V(a.stderr) : void 0]);
return {code:b, stdout:c, stderr:g};
};
const Xa = (a, b, c = [], g = null) => {
if (g) {
a.on("data", d => g.write(d));
}
let [f, ...h] = c;
if (f) {
var e = d => {
const [k, l] = f;
k.test(d) && (d = `${l}\n`, g && g.write(d), b.write(d), [f, ...h] = h, f || a.removeListener("data", e));
};
a.on("data", e);
}
};
const Ya = async(a, b = [], c = [], g = {}) => {
const f = {stdio:"pipe", execArgv:[]};
if ("string" == typeof a) {
return {m:a, args:b, options:f};
}
const h = a.module;
var e = a.getArgs;
const d = a.options;
a = a.getOptions;
b = e ? await e.call(g, b, ...c) : b;
e = f;
d ? e = {...f, ...d} : a && (c = await a.call(g, ...c), e = {...f, ...c});
return {m:h, args:b, options:e};
}, Za = (a, b, c) => {
try {
if ("string" == typeof b) {
try {
ma(a, b);
} catch (g) {
const f = N(b, a);
console.log(f);
throw g;
}
} else {
if (b) {
const g = JSON.parse(a);
Ua(g, b);
}
}
} catch (g) {
throw c && (g.property = c), g;
}
};
const $a = a => oa(/(['"])?([\s\S]+?)\1(\s+|$)/g, a, ["q", "a"]).map(({a:b}) => b);
const cb = async a => {
const {forkConfig:b, input:c, props:g = {}, contexts:f = []} = a;
a = c ? $a(c) : [];
const {m:h, args:e, options:d} = await Ya(b, a, f, {...g, input:c});
if (!h) {
throw Error("Please specify a module to fork");
}
a = Va(h, e, d);
var k = Wa(a);
a.promise = k;
a.spawnCommand = a.spawnargs.join(" ");
const {promise:l, stdout:n, stdin:q, stderr:r} = a, {includeAnswers:p = !0, log:m, stripAnsi:w = !0, preprocess:y, normaliseOutputs:B = !1} = b;
let {inputs:t, stderrInputs:A} = b;
var v = new Fa;
const z = new Fa;
!0 === m ? (v.pipe(process.stdout), z.pipe(process.stderr)) : m && (m.stdout && v.pipe(m.stdout), m.stderr && z.pipe(m.stderr));
k = p && t;
a = p && A;
var u, x;
k && (u = new U({rs:v}));
a && (x = new U({rs:z}));
t = ab(t);
A = ab(A);
Xa(n, q, t, v);
Xa(r, q, A, z);
v = await l;
k && (u.end(), u = await u.promise, Object.assign(v, {stdout:u}));
a && (x.end(), x = await x.promise, Object.assign(v, {stderr:x}));
bb(v, g, w, y, B);
return v;
}, ab = a => {
a && (a = a.map(([b, c]) => {
void 0 === c && (c = "");
return [b, c];
}));
return a;
}, bb = ({code:a, stdout:b, stderr:c}, g, f, h, e) => {
var d, k;
"object" == typeof h ? {stdout:d, stderr:k} = h : "function" == typeof h && (d = k = h);
b = b.replace(/\r?\n$/, "");
c = c.replace(/\r?\n$/, "");
b = f ? b.replace(/\033\[.*?m/g, "") : b;
c = f ? c.replace(/\033\[.*?m/g, "") : c;
f = e ? db(b) : b;
e = e ? db(c) : c;
d = d ? d(f) : f;
k = k ? k(e) : e;
Za(d, g.stdout, "stdout");
Za(k, g.stderr, "stderr");
if (g.code && a != g.code) {
throw a = Error(`Fork exited with code ${a} != ${g.code}`), a.w = "code", a;
}
};
function db(a) {
return "win32" != process.platform ? a : a.replace(/([^\r])\n/g, `$1${S}`);
}
;const hb = a => {
const b = a.input, c = a.error, g = a.expected, f = a.props, h = a.getThrowsConfig, e = a.getTransform, d = a.getResults, k = a.assertResults, l = a.mapActual, n = a.getReadable, q = a.fork, r = a.l;
return async(...p) => {
var m = {input:b, ...f};
if (c) {
if (!h) {
throw Error('No "getThrowsConfig" function is given.');
}
m = h.call(m, ...p);
await eb(m, c);
} else {
if (e) {
fb(g), p = await e.call(m, ...p), p.end(b), p = await V(p);
} else {
if (n) {
fb(g), p = await n.call(m, ...p), p = await V(p);
} else {
if (q) {
m.inputs && (q.inputs = gb(m.inputs));
var w = await cb({forkConfig:q, input:b, props:f, contexts:p});
p = d ? await d.call(m, ...p) : w;
} else {
if (d) {
p = await d.call(m, ...p);
} else {
throw Error("Nothing was tested.");
}
}
}
}
if (void 0 !== g) {
if (w = l(p), "string" != typeof g) {
try {
Ua(w, g);
} catch (y) {
throw y.property = "expected", y;
}
} else {
if ("string" != (typeof w).toLowerCase()) {
throw Error('The actual result is not an a string. Use "mapActual" function to map to a string result, or add "expected" to "jsonProps" or "jsProps".');
}
Ea(w, g, r);
}
}
k && await k.call(m, p, f);
}
};
}, fb = a => {
if (void 0 === a) {
throw Error("No expected output was given.");
}
}, gb = a => a.split(S).map(b => {
const [c, g] = b.split(/: +/);
return [new RegExp(c), g];
}), eb = async(a, b) => {
await Ra({...a, message:b});
};
function Z(a, b, c = null) {
if (Array.isArray(a)) {
return a.reduce((d, k) => {
const l = Q(k.replace(/\.\w+?$/, ""));
k = Z(k, b, c);
Object.assign(d, {[l]:k});
return d;
}, {});
}
let g;
const f = a.startsWith("!");
let h = f ? a.replace(/^!/, "") : a;
try {
g = O(h), h = ja(h);
} catch (d) {
if ("ENOENT" != d.code) {
throw d;
}
h = ib(h, c);
g = O(h);
}
let e;
if (g.isFile()) {
e = jb(h, b);
} else {
if (g.isDirectory()) {
const d = P(h);
e = d.reduce((k, l) => {
const n = R(h, l);
l = l.replace(/\.\w+?$/, "");
return {...k, [l]:Z(n, b, d)};
}, {});
}
}
return f ? {[a]:e} : e;
}
const ib = (a, b) => {
const c = ia(a);
b = (b || P(c)).filter(g => g.startsWith(`${Q(a)}.`));
if (1 < b.length) {
throw Error(`Could not resolve the result path ${a}, possible files: ${b.join(", ")}.`);
}
if (b.length) {
a = R(c, b[0]);
} else {
throw Error(`Could not resolve the result path ${a}.`);
}
return a;
}, jb = (a, b) => {
if (!b) {
throw Error('No configuration is given. A config should at least contain either a "getThrowsConfig", "getResults", "getTransform" or "getReadable" functions.');
}
const {context:c, persistentContext:g, getResults:f, getTransform:h, getReadable:e, getThrowsConfig:d, mapActual:k = B => B, assertResults:l, jsonProps:n = [], jsProps:q = [], splitRe:r, fork:p, propEndRe:m, propStartRe:w, l:y} = b;
return Da({path:a, splitRe:r, propEndRe:m, propStartRe:w, jsonProps:n}).reduce((B, {name:t, error:A, u:v, ...z}) => {
let u, x, C, D;
t in B && (u = `Repeated use of the test name "${t}".`);
try {
({expected:C, input:D, ...x} = za(z, n, q));
} catch ({message:I}) {
u = I;
}
let H;
u ? H = () => {
throw Error(u);
} : H = hb({input:D, error:A, getThrowsConfig:d, getTransform:h, getReadable:e, getResults:f, expected:C, assertResults:l, props:x, mapActual:k, fork:p, l:y});
B[t] = async(...I) => {
try {
await H(...I);
} catch (na) {
process.env.DEBUG && console.log(L(na.stack, "red")), await v(na);
}
};
return B;
}, {...c ? {context:c} : {}, ...g ? {persistentContext:g} : {}});
};
module.exports = Z;
//# sourceMappingURL=mask.js.map