webpipe-js 2.0.22 → 2.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +62 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +62 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1050,6 +1050,36 @@ var Parser = class {
|
|
|
1050
1050
|
parseAndMock() {
|
|
1051
1051
|
return this.parseMockHead("and");
|
|
1052
1052
|
}
|
|
1053
|
+
parseLetBinding() {
|
|
1054
|
+
this.expect("let");
|
|
1055
|
+
this.skipInlineSpaces();
|
|
1056
|
+
const name = this.parseIdentifier();
|
|
1057
|
+
this.skipInlineSpaces();
|
|
1058
|
+
this.expect("=");
|
|
1059
|
+
this.skipInlineSpaces();
|
|
1060
|
+
const value = (() => {
|
|
1061
|
+
const bt = this.tryParse(() => this.parseBacktickString());
|
|
1062
|
+
if (bt !== null) return bt;
|
|
1063
|
+
const qt = this.tryParse(() => this.parseQuotedString());
|
|
1064
|
+
if (qt !== null) return qt;
|
|
1065
|
+
if (this.text.startsWith("true", this.pos)) {
|
|
1066
|
+
this.pos += 4;
|
|
1067
|
+
return "true";
|
|
1068
|
+
}
|
|
1069
|
+
if (this.text.startsWith("false", this.pos)) {
|
|
1070
|
+
this.pos += 5;
|
|
1071
|
+
return "false";
|
|
1072
|
+
}
|
|
1073
|
+
const num = this.tryParse(() => {
|
|
1074
|
+
const digits = this.consumeWhile((c) => /[0-9]/.test(c));
|
|
1075
|
+
if (digits.length === 0) throw new Error("number");
|
|
1076
|
+
return digits;
|
|
1077
|
+
});
|
|
1078
|
+
if (num !== null) return num;
|
|
1079
|
+
throw new Error("let value");
|
|
1080
|
+
})();
|
|
1081
|
+
return [name, value];
|
|
1082
|
+
}
|
|
1053
1083
|
parseIt() {
|
|
1054
1084
|
this.skipSpaces();
|
|
1055
1085
|
this.expect("it");
|
|
@@ -1068,12 +1098,22 @@ var Parser = class {
|
|
|
1068
1098
|
this.skipInlineSpaces();
|
|
1069
1099
|
const when = this.parseWhen();
|
|
1070
1100
|
this.skipSpaces();
|
|
1101
|
+
const variables = [];
|
|
1071
1102
|
let input;
|
|
1072
1103
|
let body;
|
|
1073
1104
|
let headers;
|
|
1074
1105
|
let cookies;
|
|
1075
1106
|
let firstWithClause = true;
|
|
1076
1107
|
while (true) {
|
|
1108
|
+
const letBinding = this.tryParse(() => {
|
|
1109
|
+
const binding = this.parseLetBinding();
|
|
1110
|
+
this.skipSpaces();
|
|
1111
|
+
return binding;
|
|
1112
|
+
});
|
|
1113
|
+
if (letBinding) {
|
|
1114
|
+
variables.push(letBinding);
|
|
1115
|
+
continue;
|
|
1116
|
+
}
|
|
1077
1117
|
const parsed = this.tryParse(() => {
|
|
1078
1118
|
if (firstWithClause) {
|
|
1079
1119
|
this.expect("with");
|
|
@@ -1133,7 +1173,17 @@ var Parser = class {
|
|
|
1133
1173
|
if (!c) break;
|
|
1134
1174
|
conditions.push(c);
|
|
1135
1175
|
}
|
|
1136
|
-
return {
|
|
1176
|
+
return {
|
|
1177
|
+
name,
|
|
1178
|
+
mocks: [...mocks, ...extraMocks],
|
|
1179
|
+
when,
|
|
1180
|
+
variables: variables.length > 0 ? variables : void 0,
|
|
1181
|
+
input,
|
|
1182
|
+
body,
|
|
1183
|
+
headers,
|
|
1184
|
+
cookies,
|
|
1185
|
+
conditions
|
|
1186
|
+
};
|
|
1137
1187
|
}
|
|
1138
1188
|
parseDescribe() {
|
|
1139
1189
|
this.skipSpaces();
|
|
@@ -1307,6 +1357,17 @@ function printTest(test) {
|
|
|
1307
1357
|
lines.push(printMock(mock, " "));
|
|
1308
1358
|
});
|
|
1309
1359
|
lines.push(` when ${formatWhen(test.when)}`);
|
|
1360
|
+
if (test.variables) {
|
|
1361
|
+
test.variables.forEach(([name, value]) => {
|
|
1362
|
+
const formattedValue = (() => {
|
|
1363
|
+
if (value.startsWith("`") || value.startsWith('"')) return value;
|
|
1364
|
+
if (value === "true" || value === "false" || /^\d+$/.test(value)) return value;
|
|
1365
|
+
if (value.includes("{") || value.includes("[") || value.includes("\n")) return `\`${value}\``;
|
|
1366
|
+
return `"${value}"`;
|
|
1367
|
+
})();
|
|
1368
|
+
lines.push(` let ${name} = ${formattedValue}`);
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1310
1371
|
if (test.input) {
|
|
1311
1372
|
lines.push(` with input \`${test.input}\``);
|
|
1312
1373
|
}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1000,6 +1000,36 @@ var Parser = class {
|
|
|
1000
1000
|
parseAndMock() {
|
|
1001
1001
|
return this.parseMockHead("and");
|
|
1002
1002
|
}
|
|
1003
|
+
parseLetBinding() {
|
|
1004
|
+
this.expect("let");
|
|
1005
|
+
this.skipInlineSpaces();
|
|
1006
|
+
const name = this.parseIdentifier();
|
|
1007
|
+
this.skipInlineSpaces();
|
|
1008
|
+
this.expect("=");
|
|
1009
|
+
this.skipInlineSpaces();
|
|
1010
|
+
const value = (() => {
|
|
1011
|
+
const bt = this.tryParse(() => this.parseBacktickString());
|
|
1012
|
+
if (bt !== null) return bt;
|
|
1013
|
+
const qt = this.tryParse(() => this.parseQuotedString());
|
|
1014
|
+
if (qt !== null) return qt;
|
|
1015
|
+
if (this.text.startsWith("true", this.pos)) {
|
|
1016
|
+
this.pos += 4;
|
|
1017
|
+
return "true";
|
|
1018
|
+
}
|
|
1019
|
+
if (this.text.startsWith("false", this.pos)) {
|
|
1020
|
+
this.pos += 5;
|
|
1021
|
+
return "false";
|
|
1022
|
+
}
|
|
1023
|
+
const num = this.tryParse(() => {
|
|
1024
|
+
const digits = this.consumeWhile((c) => /[0-9]/.test(c));
|
|
1025
|
+
if (digits.length === 0) throw new Error("number");
|
|
1026
|
+
return digits;
|
|
1027
|
+
});
|
|
1028
|
+
if (num !== null) return num;
|
|
1029
|
+
throw new Error("let value");
|
|
1030
|
+
})();
|
|
1031
|
+
return [name, value];
|
|
1032
|
+
}
|
|
1003
1033
|
parseIt() {
|
|
1004
1034
|
this.skipSpaces();
|
|
1005
1035
|
this.expect("it");
|
|
@@ -1018,12 +1048,22 @@ var Parser = class {
|
|
|
1018
1048
|
this.skipInlineSpaces();
|
|
1019
1049
|
const when = this.parseWhen();
|
|
1020
1050
|
this.skipSpaces();
|
|
1051
|
+
const variables = [];
|
|
1021
1052
|
let input;
|
|
1022
1053
|
let body;
|
|
1023
1054
|
let headers;
|
|
1024
1055
|
let cookies;
|
|
1025
1056
|
let firstWithClause = true;
|
|
1026
1057
|
while (true) {
|
|
1058
|
+
const letBinding = this.tryParse(() => {
|
|
1059
|
+
const binding = this.parseLetBinding();
|
|
1060
|
+
this.skipSpaces();
|
|
1061
|
+
return binding;
|
|
1062
|
+
});
|
|
1063
|
+
if (letBinding) {
|
|
1064
|
+
variables.push(letBinding);
|
|
1065
|
+
continue;
|
|
1066
|
+
}
|
|
1027
1067
|
const parsed = this.tryParse(() => {
|
|
1028
1068
|
if (firstWithClause) {
|
|
1029
1069
|
this.expect("with");
|
|
@@ -1083,7 +1123,17 @@ var Parser = class {
|
|
|
1083
1123
|
if (!c) break;
|
|
1084
1124
|
conditions.push(c);
|
|
1085
1125
|
}
|
|
1086
|
-
return {
|
|
1126
|
+
return {
|
|
1127
|
+
name,
|
|
1128
|
+
mocks: [...mocks, ...extraMocks],
|
|
1129
|
+
when,
|
|
1130
|
+
variables: variables.length > 0 ? variables : void 0,
|
|
1131
|
+
input,
|
|
1132
|
+
body,
|
|
1133
|
+
headers,
|
|
1134
|
+
cookies,
|
|
1135
|
+
conditions
|
|
1136
|
+
};
|
|
1087
1137
|
}
|
|
1088
1138
|
parseDescribe() {
|
|
1089
1139
|
this.skipSpaces();
|
|
@@ -1257,6 +1307,17 @@ function printTest(test) {
|
|
|
1257
1307
|
lines.push(printMock(mock, " "));
|
|
1258
1308
|
});
|
|
1259
1309
|
lines.push(` when ${formatWhen(test.when)}`);
|
|
1310
|
+
if (test.variables) {
|
|
1311
|
+
test.variables.forEach(([name, value]) => {
|
|
1312
|
+
const formattedValue = (() => {
|
|
1313
|
+
if (value.startsWith("`") || value.startsWith('"')) return value;
|
|
1314
|
+
if (value === "true" || value === "false" || /^\d+$/.test(value)) return value;
|
|
1315
|
+
if (value.includes("{") || value.includes("[") || value.includes("\n")) return `\`${value}\``;
|
|
1316
|
+
return `"${value}"`;
|
|
1317
|
+
})();
|
|
1318
|
+
lines.push(` let ${name} = ${formattedValue}`);
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1260
1321
|
if (test.input) {
|
|
1261
1322
|
lines.push(` with input \`${test.input}\``);
|
|
1262
1323
|
}
|