webpipe-js 2.0.13 → 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
@@ -509,17 +509,18 @@ var Parser = class {
509
509
  */
510
510
  parseStepCondition() {
511
511
  this.skipInlineSpaces();
512
- if (this.cur() !== "@") {
512
+ const ch = this.cur();
513
+ if (ch !== "@" && ch !== "(") {
513
514
  return void 0;
514
515
  }
515
516
  let expr = this.parseTagExpr();
516
517
  while (true) {
517
518
  this.skipInlineSpaces();
518
- const ch = this.cur();
519
- if (ch === "\n" || ch === "\r" || ch === "#" || this.text.startsWith("//", this.pos)) {
519
+ const ch2 = this.cur();
520
+ if (ch2 === "\n" || ch2 === "\r" || ch2 === "#" || this.text.startsWith("//", this.pos)) {
520
521
  break;
521
522
  }
522
- if (ch !== "@") {
523
+ if (ch2 !== "@") {
523
524
  break;
524
525
  }
525
526
  const nextTag = this.parseTag();
@@ -878,7 +879,20 @@ var Parser = class {
878
879
  this.skipInlineSpaces();
879
880
  const field = this.consumeWhile((c) => c !== " " && c !== "\n" && c !== "`");
880
881
  this.skipInlineSpaces();
881
- 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;
882
896
  this.skipInlineSpaces();
883
897
  const comparison = this.consumeWhile((c) => c !== " " && c !== "\n");
884
898
  this.skipInlineSpaces();
@@ -889,7 +903,7 @@ var Parser = class {
889
903
  if (v2 !== null) return v2;
890
904
  return this.consumeWhile((c) => c !== "\n");
891
905
  })();
892
- 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 };
893
907
  }
894
908
  parseMockHead(prefixWord) {
895
909
  this.skipSpaces();
@@ -938,6 +952,33 @@ var Parser = class {
938
952
  this.skipSpaces();
939
953
  return v;
940
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;
941
982
  const extraMocks = [];
942
983
  while (true) {
943
984
  const m = this.tryParse(() => this.parseAndMock());
@@ -951,7 +992,7 @@ var Parser = class {
951
992
  if (!c) break;
952
993
  conditions.push(c);
953
994
  }
954
- return { name, mocks: [...mocks, ...extraMocks], when, input, conditions };
995
+ return { name, mocks: [...mocks, ...extraMocks], when, input, body, headers, cookies, conditions };
955
996
  }
956
997
  parseDescribe() {
957
998
  this.skipSpaces();
@@ -1088,9 +1129,9 @@ function printMock(mock, indent = " ") {
1088
1129
  }
1089
1130
  function printCondition(condition, indent = " ") {
1090
1131
  const condType = condition.conditionType.toLowerCase();
1091
- const jqPart = condition.jqExpr ? ` \`${condition.jqExpr}\`` : "";
1132
+ const fieldPart = condition.headerName ? `${condition.field} "${condition.headerName}"` : condition.jqExpr ? `${condition.field} \`${condition.jqExpr}\`` : condition.field;
1092
1133
  const value = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
1093
- return `${indent}${condType} ${condition.field}${jqPart} ${condition.comparison} ${value}`;
1134
+ return `${indent}${condType} ${fieldPart} ${condition.comparison} ${value}`;
1094
1135
  }
1095
1136
  function printTest(test) {
1096
1137
  const lines = [];
@@ -1102,6 +1143,15 @@ function printTest(test) {
1102
1143
  if (test.input) {
1103
1144
  lines.push(` with input \`${test.input}\``);
1104
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
+ }
1105
1155
  test.conditions.forEach((condition) => {
1106
1156
  lines.push(printCondition(condition));
1107
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
@@ -459,17 +459,18 @@ var Parser = class {
459
459
  */
460
460
  parseStepCondition() {
461
461
  this.skipInlineSpaces();
462
- if (this.cur() !== "@") {
462
+ const ch = this.cur();
463
+ if (ch !== "@" && ch !== "(") {
463
464
  return void 0;
464
465
  }
465
466
  let expr = this.parseTagExpr();
466
467
  while (true) {
467
468
  this.skipInlineSpaces();
468
- const ch = this.cur();
469
- if (ch === "\n" || ch === "\r" || ch === "#" || this.text.startsWith("//", this.pos)) {
469
+ const ch2 = this.cur();
470
+ if (ch2 === "\n" || ch2 === "\r" || ch2 === "#" || this.text.startsWith("//", this.pos)) {
470
471
  break;
471
472
  }
472
- if (ch !== "@") {
473
+ if (ch2 !== "@") {
473
474
  break;
474
475
  }
475
476
  const nextTag = this.parseTag();
@@ -828,7 +829,20 @@ var Parser = class {
828
829
  this.skipInlineSpaces();
829
830
  const field = this.consumeWhile((c) => c !== " " && c !== "\n" && c !== "`");
830
831
  this.skipInlineSpaces();
831
- 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;
832
846
  this.skipInlineSpaces();
833
847
  const comparison = this.consumeWhile((c) => c !== " " && c !== "\n");
834
848
  this.skipInlineSpaces();
@@ -839,7 +853,7 @@ var Parser = class {
839
853
  if (v2 !== null) return v2;
840
854
  return this.consumeWhile((c) => c !== "\n");
841
855
  })();
842
- 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 };
843
857
  }
844
858
  parseMockHead(prefixWord) {
845
859
  this.skipSpaces();
@@ -888,6 +902,33 @@ var Parser = class {
888
902
  this.skipSpaces();
889
903
  return v;
890
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;
891
932
  const extraMocks = [];
892
933
  while (true) {
893
934
  const m = this.tryParse(() => this.parseAndMock());
@@ -901,7 +942,7 @@ var Parser = class {
901
942
  if (!c) break;
902
943
  conditions.push(c);
903
944
  }
904
- return { name, mocks: [...mocks, ...extraMocks], when, input, conditions };
945
+ return { name, mocks: [...mocks, ...extraMocks], when, input, body, headers, cookies, conditions };
905
946
  }
906
947
  parseDescribe() {
907
948
  this.skipSpaces();
@@ -1038,9 +1079,9 @@ function printMock(mock, indent = " ") {
1038
1079
  }
1039
1080
  function printCondition(condition, indent = " ") {
1040
1081
  const condType = condition.conditionType.toLowerCase();
1041
- const jqPart = condition.jqExpr ? ` \`${condition.jqExpr}\`` : "";
1082
+ const fieldPart = condition.headerName ? `${condition.field} "${condition.headerName}"` : condition.jqExpr ? `${condition.field} \`${condition.jqExpr}\`` : condition.field;
1042
1083
  const value = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
1043
- return `${indent}${condType} ${condition.field}${jqPart} ${condition.comparison} ${value}`;
1084
+ return `${indent}${condType} ${fieldPart} ${condition.comparison} ${value}`;
1044
1085
  }
1045
1086
  function printTest(test) {
1046
1087
  const lines = [];
@@ -1052,6 +1093,15 @@ function printTest(test) {
1052
1093
  if (test.input) {
1053
1094
  lines.push(` with input \`${test.input}\``);
1054
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
+ }
1055
1105
  test.conditions.forEach((condition) => {
1056
1106
  lines.push(printCondition(condition));
1057
1107
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.13",
3
+ "version": "2.0.15",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",