webpipe-js 2.0.22 → 2.0.24
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 +65 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +65 -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");
|
|
@@ -1064,6 +1094,19 @@ var Parser = class {
|
|
|
1064
1094
|
if (!m) break;
|
|
1065
1095
|
mocks.push(m);
|
|
1066
1096
|
}
|
|
1097
|
+
const variables = [];
|
|
1098
|
+
while (true) {
|
|
1099
|
+
const letBinding = this.tryParse(() => {
|
|
1100
|
+
const binding = this.parseLetBinding();
|
|
1101
|
+
this.skipSpaces();
|
|
1102
|
+
return binding;
|
|
1103
|
+
});
|
|
1104
|
+
if (letBinding) {
|
|
1105
|
+
variables.push(letBinding);
|
|
1106
|
+
continue;
|
|
1107
|
+
}
|
|
1108
|
+
break;
|
|
1109
|
+
}
|
|
1067
1110
|
this.expect("when");
|
|
1068
1111
|
this.skipInlineSpaces();
|
|
1069
1112
|
const when = this.parseWhen();
|
|
@@ -1133,7 +1176,17 @@ var Parser = class {
|
|
|
1133
1176
|
if (!c) break;
|
|
1134
1177
|
conditions.push(c);
|
|
1135
1178
|
}
|
|
1136
|
-
return {
|
|
1179
|
+
return {
|
|
1180
|
+
name,
|
|
1181
|
+
mocks: [...mocks, ...extraMocks],
|
|
1182
|
+
when,
|
|
1183
|
+
variables: variables.length > 0 ? variables : void 0,
|
|
1184
|
+
input,
|
|
1185
|
+
body,
|
|
1186
|
+
headers,
|
|
1187
|
+
cookies,
|
|
1188
|
+
conditions
|
|
1189
|
+
};
|
|
1137
1190
|
}
|
|
1138
1191
|
parseDescribe() {
|
|
1139
1192
|
this.skipSpaces();
|
|
@@ -1307,6 +1360,17 @@ function printTest(test) {
|
|
|
1307
1360
|
lines.push(printMock(mock, " "));
|
|
1308
1361
|
});
|
|
1309
1362
|
lines.push(` when ${formatWhen(test.when)}`);
|
|
1363
|
+
if (test.variables) {
|
|
1364
|
+
test.variables.forEach(([name, value]) => {
|
|
1365
|
+
const formattedValue = (() => {
|
|
1366
|
+
if (value.startsWith("`") || value.startsWith('"')) return value;
|
|
1367
|
+
if (value === "true" || value === "false" || /^\d+$/.test(value)) return value;
|
|
1368
|
+
if (value.includes("{") || value.includes("[") || value.includes("\n")) return `\`${value}\``;
|
|
1369
|
+
return `"${value}"`;
|
|
1370
|
+
})();
|
|
1371
|
+
lines.push(` let ${name} = ${formattedValue}`);
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1310
1374
|
if (test.input) {
|
|
1311
1375
|
lines.push(` with input \`${test.input}\``);
|
|
1312
1376
|
}
|
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");
|
|
@@ -1014,6 +1044,19 @@ var Parser = class {
|
|
|
1014
1044
|
if (!m) break;
|
|
1015
1045
|
mocks.push(m);
|
|
1016
1046
|
}
|
|
1047
|
+
const variables = [];
|
|
1048
|
+
while (true) {
|
|
1049
|
+
const letBinding = this.tryParse(() => {
|
|
1050
|
+
const binding = this.parseLetBinding();
|
|
1051
|
+
this.skipSpaces();
|
|
1052
|
+
return binding;
|
|
1053
|
+
});
|
|
1054
|
+
if (letBinding) {
|
|
1055
|
+
variables.push(letBinding);
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
break;
|
|
1059
|
+
}
|
|
1017
1060
|
this.expect("when");
|
|
1018
1061
|
this.skipInlineSpaces();
|
|
1019
1062
|
const when = this.parseWhen();
|
|
@@ -1083,7 +1126,17 @@ var Parser = class {
|
|
|
1083
1126
|
if (!c) break;
|
|
1084
1127
|
conditions.push(c);
|
|
1085
1128
|
}
|
|
1086
|
-
return {
|
|
1129
|
+
return {
|
|
1130
|
+
name,
|
|
1131
|
+
mocks: [...mocks, ...extraMocks],
|
|
1132
|
+
when,
|
|
1133
|
+
variables: variables.length > 0 ? variables : void 0,
|
|
1134
|
+
input,
|
|
1135
|
+
body,
|
|
1136
|
+
headers,
|
|
1137
|
+
cookies,
|
|
1138
|
+
conditions
|
|
1139
|
+
};
|
|
1087
1140
|
}
|
|
1088
1141
|
parseDescribe() {
|
|
1089
1142
|
this.skipSpaces();
|
|
@@ -1257,6 +1310,17 @@ function printTest(test) {
|
|
|
1257
1310
|
lines.push(printMock(mock, " "));
|
|
1258
1311
|
});
|
|
1259
1312
|
lines.push(` when ${formatWhen(test.when)}`);
|
|
1313
|
+
if (test.variables) {
|
|
1314
|
+
test.variables.forEach(([name, value]) => {
|
|
1315
|
+
const formattedValue = (() => {
|
|
1316
|
+
if (value.startsWith("`") || value.startsWith('"')) return value;
|
|
1317
|
+
if (value === "true" || value === "false" || /^\d+$/.test(value)) return value;
|
|
1318
|
+
if (value.includes("{") || value.includes("[") || value.includes("\n")) return `\`${value}\``;
|
|
1319
|
+
return `"${value}"`;
|
|
1320
|
+
})();
|
|
1321
|
+
lines.push(` let ${name} = ${formattedValue}`);
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1260
1324
|
if (test.input) {
|
|
1261
1325
|
lines.push(` with input \`${test.input}\``);
|
|
1262
1326
|
}
|