webpipe-js 2.0.14 → 2.0.15

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 CHANGED
@@ -879,7 +879,20 @@ var Parser = class {
879
879
  this.skipInlineSpaces();
880
880
  const field = this.consumeWhile((c) => c !== " " && c !== "\n" && c !== "`");
881
881
  this.skipInlineSpaces();
882
- const jqExpr = this.tryParse(() => this.parseBacktickString());
882
+ let headerName;
883
+ if (field === "header") {
884
+ const h1 = this.tryParse(() => this.parseBacktickString());
885
+ if (h1 !== null) {
886
+ headerName = h1;
887
+ } else {
888
+ const h2 = this.tryParse(() => this.parseQuotedString());
889
+ if (h2 !== null) {
890
+ headerName = h2;
891
+ }
892
+ }
893
+ this.skipInlineSpaces();
894
+ }
895
+ const jqExpr = headerName === void 0 ? this.tryParse(() => this.parseBacktickString()) : null;
883
896
  this.skipInlineSpaces();
884
897
  const comparison = this.consumeWhile((c) => c !== " " && c !== "\n");
885
898
  this.skipInlineSpaces();
@@ -890,7 +903,7 @@ var Parser = class {
890
903
  if (v2 !== null) return v2;
891
904
  return this.consumeWhile((c) => c !== "\n");
892
905
  })();
893
- return { conditionType: ct, field, jqExpr: jqExpr ?? void 0, comparison, value };
906
+ return { conditionType: ct, field, headerName: headerName ?? void 0, jqExpr: jqExpr ?? void 0, comparison, value };
894
907
  }
895
908
  parseMockHead(prefixWord) {
896
909
  this.skipSpaces();
@@ -939,6 +952,33 @@ var Parser = class {
939
952
  this.skipSpaces();
940
953
  return v;
941
954
  }) ?? void 0;
955
+ const body = this.tryParse(() => {
956
+ this.expect("with");
957
+ this.skipInlineSpaces();
958
+ this.expect("body");
959
+ this.skipInlineSpaces();
960
+ const v = this.parseBacktickString();
961
+ this.skipSpaces();
962
+ return v;
963
+ }) ?? void 0;
964
+ const headers = this.tryParse(() => {
965
+ this.expect("with");
966
+ this.skipInlineSpaces();
967
+ this.expect("headers");
968
+ this.skipInlineSpaces();
969
+ const v = this.parseBacktickString();
970
+ this.skipSpaces();
971
+ return v;
972
+ }) ?? void 0;
973
+ const cookies = this.tryParse(() => {
974
+ this.expect("with");
975
+ this.skipInlineSpaces();
976
+ this.expect("cookies");
977
+ this.skipInlineSpaces();
978
+ const v = this.parseBacktickString();
979
+ this.skipSpaces();
980
+ return v;
981
+ }) ?? void 0;
942
982
  const extraMocks = [];
943
983
  while (true) {
944
984
  const m = this.tryParse(() => this.parseAndMock());
@@ -952,7 +992,7 @@ var Parser = class {
952
992
  if (!c) break;
953
993
  conditions.push(c);
954
994
  }
955
- return { name, mocks: [...mocks, ...extraMocks], when, input, conditions };
995
+ return { name, mocks: [...mocks, ...extraMocks], when, input, body, headers, cookies, conditions };
956
996
  }
957
997
  parseDescribe() {
958
998
  this.skipSpaces();
@@ -1089,9 +1129,9 @@ function printMock(mock, indent = " ") {
1089
1129
  }
1090
1130
  function printCondition(condition, indent = " ") {
1091
1131
  const condType = condition.conditionType.toLowerCase();
1092
- const jqPart = condition.jqExpr ? ` \`${condition.jqExpr}\`` : "";
1132
+ const fieldPart = condition.headerName ? `${condition.field} "${condition.headerName}"` : condition.jqExpr ? `${condition.field} \`${condition.jqExpr}\`` : condition.field;
1093
1133
  const value = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
1094
- return `${indent}${condType} ${condition.field}${jqPart} ${condition.comparison} ${value}`;
1134
+ return `${indent}${condType} ${fieldPart} ${condition.comparison} ${value}`;
1095
1135
  }
1096
1136
  function printTest(test) {
1097
1137
  const lines = [];
@@ -1103,6 +1143,15 @@ function printTest(test) {
1103
1143
  if (test.input) {
1104
1144
  lines.push(` with input \`${test.input}\``);
1105
1145
  }
1146
+ if (test.body) {
1147
+ lines.push(` with body \`${test.body}\``);
1148
+ }
1149
+ if (test.headers) {
1150
+ lines.push(` with headers \`${test.headers}\``);
1151
+ }
1152
+ if (test.cookies) {
1153
+ lines.push(` with cookies \`${test.cookies}\``);
1154
+ }
1106
1155
  test.conditions.forEach((condition) => {
1107
1156
  lines.push(printCondition(condition));
1108
1157
  });
package/dist/index.d.cts CHANGED
@@ -163,6 +163,9 @@ interface It {
163
163
  mocks: Mock[];
164
164
  when: When;
165
165
  input?: string;
166
+ body?: string;
167
+ headers?: string;
168
+ cookies?: string;
166
169
  conditions: Condition[];
167
170
  }
168
171
  type When = {
@@ -180,6 +183,7 @@ type When = {
180
183
  interface Condition {
181
184
  conditionType: 'Then' | 'And';
182
185
  field: string;
186
+ headerName?: string;
183
187
  jqExpr?: string;
184
188
  comparison: string;
185
189
  value: string;
package/dist/index.d.ts CHANGED
@@ -163,6 +163,9 @@ interface It {
163
163
  mocks: Mock[];
164
164
  when: When;
165
165
  input?: string;
166
+ body?: string;
167
+ headers?: string;
168
+ cookies?: string;
166
169
  conditions: Condition[];
167
170
  }
168
171
  type When = {
@@ -180,6 +183,7 @@ type When = {
180
183
  interface Condition {
181
184
  conditionType: 'Then' | 'And';
182
185
  field: string;
186
+ headerName?: string;
183
187
  jqExpr?: string;
184
188
  comparison: string;
185
189
  value: string;
package/dist/index.mjs CHANGED
@@ -829,7 +829,20 @@ var Parser = class {
829
829
  this.skipInlineSpaces();
830
830
  const field = this.consumeWhile((c) => c !== " " && c !== "\n" && c !== "`");
831
831
  this.skipInlineSpaces();
832
- const jqExpr = this.tryParse(() => this.parseBacktickString());
832
+ let headerName;
833
+ if (field === "header") {
834
+ const h1 = this.tryParse(() => this.parseBacktickString());
835
+ if (h1 !== null) {
836
+ headerName = h1;
837
+ } else {
838
+ const h2 = this.tryParse(() => this.parseQuotedString());
839
+ if (h2 !== null) {
840
+ headerName = h2;
841
+ }
842
+ }
843
+ this.skipInlineSpaces();
844
+ }
845
+ const jqExpr = headerName === void 0 ? this.tryParse(() => this.parseBacktickString()) : null;
833
846
  this.skipInlineSpaces();
834
847
  const comparison = this.consumeWhile((c) => c !== " " && c !== "\n");
835
848
  this.skipInlineSpaces();
@@ -840,7 +853,7 @@ var Parser = class {
840
853
  if (v2 !== null) return v2;
841
854
  return this.consumeWhile((c) => c !== "\n");
842
855
  })();
843
- return { conditionType: ct, field, jqExpr: jqExpr ?? void 0, comparison, value };
856
+ return { conditionType: ct, field, headerName: headerName ?? void 0, jqExpr: jqExpr ?? void 0, comparison, value };
844
857
  }
845
858
  parseMockHead(prefixWord) {
846
859
  this.skipSpaces();
@@ -889,6 +902,33 @@ var Parser = class {
889
902
  this.skipSpaces();
890
903
  return v;
891
904
  }) ?? void 0;
905
+ const body = this.tryParse(() => {
906
+ this.expect("with");
907
+ this.skipInlineSpaces();
908
+ this.expect("body");
909
+ this.skipInlineSpaces();
910
+ const v = this.parseBacktickString();
911
+ this.skipSpaces();
912
+ return v;
913
+ }) ?? void 0;
914
+ const headers = this.tryParse(() => {
915
+ this.expect("with");
916
+ this.skipInlineSpaces();
917
+ this.expect("headers");
918
+ this.skipInlineSpaces();
919
+ const v = this.parseBacktickString();
920
+ this.skipSpaces();
921
+ return v;
922
+ }) ?? void 0;
923
+ const cookies = this.tryParse(() => {
924
+ this.expect("with");
925
+ this.skipInlineSpaces();
926
+ this.expect("cookies");
927
+ this.skipInlineSpaces();
928
+ const v = this.parseBacktickString();
929
+ this.skipSpaces();
930
+ return v;
931
+ }) ?? void 0;
892
932
  const extraMocks = [];
893
933
  while (true) {
894
934
  const m = this.tryParse(() => this.parseAndMock());
@@ -902,7 +942,7 @@ var Parser = class {
902
942
  if (!c) break;
903
943
  conditions.push(c);
904
944
  }
905
- return { name, mocks: [...mocks, ...extraMocks], when, input, conditions };
945
+ return { name, mocks: [...mocks, ...extraMocks], when, input, body, headers, cookies, conditions };
906
946
  }
907
947
  parseDescribe() {
908
948
  this.skipSpaces();
@@ -1039,9 +1079,9 @@ function printMock(mock, indent = " ") {
1039
1079
  }
1040
1080
  function printCondition(condition, indent = " ") {
1041
1081
  const condType = condition.conditionType.toLowerCase();
1042
- const jqPart = condition.jqExpr ? ` \`${condition.jqExpr}\`` : "";
1082
+ const fieldPart = condition.headerName ? `${condition.field} "${condition.headerName}"` : condition.jqExpr ? `${condition.field} \`${condition.jqExpr}\`` : condition.field;
1043
1083
  const value = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
1044
- return `${indent}${condType} ${condition.field}${jqPart} ${condition.comparison} ${value}`;
1084
+ return `${indent}${condType} ${fieldPart} ${condition.comparison} ${value}`;
1045
1085
  }
1046
1086
  function printTest(test) {
1047
1087
  const lines = [];
@@ -1053,6 +1093,15 @@ function printTest(test) {
1053
1093
  if (test.input) {
1054
1094
  lines.push(` with input \`${test.input}\``);
1055
1095
  }
1096
+ if (test.body) {
1097
+ lines.push(` with body \`${test.body}\``);
1098
+ }
1099
+ if (test.headers) {
1100
+ lines.push(` with headers \`${test.headers}\``);
1101
+ }
1102
+ if (test.cookies) {
1103
+ lines.push(` with cookies \`${test.cookies}\``);
1104
+ }
1056
1105
  test.conditions.forEach((condition) => {
1057
1106
  lines.push(printCondition(condition));
1058
1107
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.14",
3
+ "version": "2.0.15",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",