webpipe-js 2.0.62 → 2.0.64
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 +113 -25
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.mjs +112 -25
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,7 @@ __export(index_exports, {
|
|
|
39
39
|
printCondition: () => printCondition,
|
|
40
40
|
printConfig: () => printConfig,
|
|
41
41
|
printDescribe: () => printDescribe,
|
|
42
|
+
printFeatureFlags: () => printFeatureFlags,
|
|
42
43
|
printGraphQLSchema: () => printGraphQLSchema,
|
|
43
44
|
printMock: () => printMock,
|
|
44
45
|
printMutationResolver: () => printMutationResolver,
|
|
@@ -131,7 +132,8 @@ var Parser = class {
|
|
|
131
132
|
type: "standalone",
|
|
132
133
|
text: restOfLine,
|
|
133
134
|
style: "#",
|
|
134
|
-
lineNumber: this.getLineNumber(start)
|
|
135
|
+
lineNumber: this.getLineNumber(start),
|
|
136
|
+
start
|
|
135
137
|
};
|
|
136
138
|
}
|
|
137
139
|
if (this.text.startsWith("//", this.pos)) {
|
|
@@ -141,7 +143,8 @@ var Parser = class {
|
|
|
141
143
|
type: "standalone",
|
|
142
144
|
text,
|
|
143
145
|
style: "//",
|
|
144
|
-
lineNumber: this.getLineNumber(start)
|
|
146
|
+
lineNumber: this.getLineNumber(start),
|
|
147
|
+
start
|
|
145
148
|
};
|
|
146
149
|
}
|
|
147
150
|
return null;
|
|
@@ -773,12 +776,12 @@ var Parser = class {
|
|
|
773
776
|
const condition = this.parseIfPipeline("then:");
|
|
774
777
|
this.skipSpaces();
|
|
775
778
|
this.expect("then:");
|
|
776
|
-
this.
|
|
779
|
+
this.skipWhitespaceOnly();
|
|
777
780
|
const thenBranch = this.parseIfPipeline("else:", "end");
|
|
778
781
|
this.skipSpaces();
|
|
779
782
|
const elseBranch = this.tryParse(() => {
|
|
780
783
|
this.expect("else:");
|
|
781
|
-
this.
|
|
784
|
+
this.skipWhitespaceOnly();
|
|
782
785
|
return this.parseIfPipeline("end");
|
|
783
786
|
});
|
|
784
787
|
this.skipSpaces();
|
|
@@ -908,8 +911,15 @@ var Parser = class {
|
|
|
908
911
|
break;
|
|
909
912
|
}
|
|
910
913
|
const hasFollowingStep = this.text.startsWith("|>", this.pos);
|
|
914
|
+
let hasStopKeyword = false;
|
|
915
|
+
for (const keyword of stopKeywords) {
|
|
916
|
+
if (this.text.startsWith(keyword, this.pos)) {
|
|
917
|
+
hasStopKeyword = true;
|
|
918
|
+
break;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
911
921
|
this.pos = lookAheadPos;
|
|
912
|
-
if (hasFollowingStep || steps.length === 0) {
|
|
922
|
+
if (hasFollowingStep || hasStopKeyword || steps.length === 0) {
|
|
913
923
|
comments.push(comment);
|
|
914
924
|
if (this.cur() === "\n") this.pos++;
|
|
915
925
|
continue;
|
|
@@ -1659,7 +1669,7 @@ function printPipeline(pipeline) {
|
|
|
1659
1669
|
items.push({ type: "step", item: step, position: step.start });
|
|
1660
1670
|
});
|
|
1661
1671
|
pipeline.pipeline.comments.forEach((comment) => {
|
|
1662
|
-
items.push({ type: "comment", item: comment, position: comment.
|
|
1672
|
+
items.push({ type: "comment", item: comment, position: comment.start || 0 });
|
|
1663
1673
|
});
|
|
1664
1674
|
items.sort((a, b) => a.position - b.position);
|
|
1665
1675
|
items.forEach((entry) => {
|
|
@@ -1721,6 +1731,26 @@ function printTypeResolver(resolver) {
|
|
|
1721
1731
|
});
|
|
1722
1732
|
return lines.join("\n");
|
|
1723
1733
|
}
|
|
1734
|
+
function printFeatureFlags(pipeline) {
|
|
1735
|
+
const lines = [];
|
|
1736
|
+
lines.push("featureFlags =");
|
|
1737
|
+
const items = [];
|
|
1738
|
+
pipeline.steps.forEach((step) => {
|
|
1739
|
+
items.push({ type: "step", item: step, position: step.start });
|
|
1740
|
+
});
|
|
1741
|
+
pipeline.comments.forEach((comment) => {
|
|
1742
|
+
items.push({ type: "comment", item: comment, position: comment.start || 0 });
|
|
1743
|
+
});
|
|
1744
|
+
items.sort((a, b) => a.position - b.position);
|
|
1745
|
+
items.forEach((entry) => {
|
|
1746
|
+
if (entry.type === "step") {
|
|
1747
|
+
lines.push(formatPipelineStep(entry.item));
|
|
1748
|
+
} else {
|
|
1749
|
+
lines.push(` ${printComment(entry.item)}`);
|
|
1750
|
+
}
|
|
1751
|
+
});
|
|
1752
|
+
return lines.join("\n");
|
|
1753
|
+
}
|
|
1724
1754
|
function printMock(mock, indent = " ") {
|
|
1725
1755
|
const target = mock.target.replace(/^(query|mutation)\.(.*)$/, "$1 $2");
|
|
1726
1756
|
return `${indent}with mock ${target} returning \`${mock.returnValue}\``;
|
|
@@ -1767,9 +1797,6 @@ function printCondition(condition, indent = " ") {
|
|
|
1767
1797
|
function printTest(test) {
|
|
1768
1798
|
const lines = [];
|
|
1769
1799
|
lines.push(` it "${test.name}"`);
|
|
1770
|
-
test.mocks.forEach((mock) => {
|
|
1771
|
-
lines.push(printMock(mock, " "));
|
|
1772
|
-
});
|
|
1773
1800
|
if (test.variables && test.variables.length > 0) {
|
|
1774
1801
|
test.variables.forEach((variable) => {
|
|
1775
1802
|
const formattedValue = variable.format === "quoted" ? `"${variable.value}"` : variable.format === "backtick" ? `\`${variable.value}\`` : variable.value;
|
|
@@ -1779,18 +1806,25 @@ function printTest(test) {
|
|
|
1779
1806
|
}
|
|
1780
1807
|
lines.push(` when ${formatWhen(test.when)}`);
|
|
1781
1808
|
let hasWithClause = false;
|
|
1782
|
-
if (test.
|
|
1783
|
-
lines.push(` with
|
|
1809
|
+
if (test.input) {
|
|
1810
|
+
lines.push(` with input \`${test.input}\``);
|
|
1784
1811
|
hasWithClause = true;
|
|
1785
1812
|
}
|
|
1786
|
-
|
|
1813
|
+
test.mocks.forEach((mock) => {
|
|
1814
|
+
const prefix = hasWithClause ? "and" : "with";
|
|
1815
|
+
const mockLine = printMock(mock, " ");
|
|
1816
|
+
const mockContent = mockLine.trim().replace(/^(with|and)\s+/, "");
|
|
1817
|
+
lines.push(` ${prefix} ${mockContent}`);
|
|
1818
|
+
hasWithClause = true;
|
|
1819
|
+
});
|
|
1820
|
+
if (test.headers) {
|
|
1787
1821
|
const prefix = hasWithClause ? "and with" : "with";
|
|
1788
|
-
lines.push(` ${prefix}
|
|
1822
|
+
lines.push(` ${prefix} headers \`${test.headers}\``);
|
|
1789
1823
|
hasWithClause = true;
|
|
1790
1824
|
}
|
|
1791
|
-
if (test.
|
|
1825
|
+
if (test.body) {
|
|
1792
1826
|
const prefix = hasWithClause ? "and with" : "with";
|
|
1793
|
-
lines.push(` ${prefix}
|
|
1827
|
+
lines.push(` ${prefix} body \`${test.body}\``);
|
|
1794
1828
|
hasWithClause = true;
|
|
1795
1829
|
}
|
|
1796
1830
|
if (test.cookies) {
|
|
@@ -1894,6 +1928,9 @@ function prettyPrint(program) {
|
|
|
1894
1928
|
program.variables.forEach((variable) => {
|
|
1895
1929
|
allItems.push({ type: "variable", item: variable, lineNumber: variable.lineNumber || 0 });
|
|
1896
1930
|
});
|
|
1931
|
+
if (program.featureFlags) {
|
|
1932
|
+
allItems.push({ type: "featureFlags", item: program.featureFlags, lineNumber: program.featureFlags.start || 0 });
|
|
1933
|
+
}
|
|
1897
1934
|
program.describes.forEach((describe) => {
|
|
1898
1935
|
allItems.push({ type: "describe", item: describe, lineNumber: describe.lineNumber || 0 });
|
|
1899
1936
|
});
|
|
@@ -1947,6 +1984,9 @@ function prettyPrint(program) {
|
|
|
1947
1984
|
case "variable":
|
|
1948
1985
|
lines.push(printVariable(entry.item));
|
|
1949
1986
|
break;
|
|
1987
|
+
case "featureFlags":
|
|
1988
|
+
lines.push(printFeatureFlags(entry.item));
|
|
1989
|
+
break;
|
|
1950
1990
|
case "describe":
|
|
1951
1991
|
lines.push(printDescribe(entry.item));
|
|
1952
1992
|
break;
|
|
@@ -1969,7 +2009,7 @@ function formatConfigValue(value) {
|
|
|
1969
2009
|
return value.value.toString();
|
|
1970
2010
|
}
|
|
1971
2011
|
}
|
|
1972
|
-
function formatPipelineStep(step, indent = " ") {
|
|
2012
|
+
function formatPipelineStep(step, indent = " ", isLastStep = false) {
|
|
1973
2013
|
if (step.kind === "Regular") {
|
|
1974
2014
|
const argsPart = step.args.length > 0 ? `(${step.args.join(", ")})` : "";
|
|
1975
2015
|
const configPart = formatStepConfig(step.config, step.configType);
|
|
@@ -1987,18 +2027,57 @@ function formatPipelineStep(step, indent = " ") {
|
|
|
1987
2027
|
return lines.join("\n");
|
|
1988
2028
|
} else if (step.kind === "If") {
|
|
1989
2029
|
const lines = [`${indent}|> if`];
|
|
1990
|
-
|
|
1991
|
-
|
|
2030
|
+
const conditionItems = [];
|
|
2031
|
+
step.condition.steps.forEach((s) => {
|
|
2032
|
+
conditionItems.push({ type: "step", item: s, position: s.start });
|
|
2033
|
+
});
|
|
2034
|
+
step.condition.comments.forEach((c) => {
|
|
2035
|
+
conditionItems.push({ type: "comment", item: c, position: c.start || 0 });
|
|
2036
|
+
});
|
|
2037
|
+
conditionItems.sort((a, b) => a.position - b.position);
|
|
2038
|
+
conditionItems.forEach((entry) => {
|
|
2039
|
+
if (entry.type === "step") {
|
|
2040
|
+
lines.push(formatPipelineStep(entry.item, indent + " "));
|
|
2041
|
+
} else {
|
|
2042
|
+
lines.push(`${indent} ${printComment(entry.item)}`);
|
|
2043
|
+
}
|
|
1992
2044
|
});
|
|
1993
2045
|
lines.push(`${indent} then:`);
|
|
1994
|
-
|
|
1995
|
-
|
|
2046
|
+
const thenItems = [];
|
|
2047
|
+
step.thenBranch.steps.forEach((s) => {
|
|
2048
|
+
thenItems.push({ type: "step", item: s, position: s.start });
|
|
2049
|
+
});
|
|
2050
|
+
step.thenBranch.comments.forEach((c) => {
|
|
2051
|
+
thenItems.push({ type: "comment", item: c, position: c.start || 0 });
|
|
2052
|
+
});
|
|
2053
|
+
thenItems.sort((a, b) => a.position - b.position);
|
|
2054
|
+
thenItems.forEach((entry) => {
|
|
2055
|
+
if (entry.type === "step") {
|
|
2056
|
+
lines.push(formatPipelineStep(entry.item, indent + " "));
|
|
2057
|
+
} else {
|
|
2058
|
+
lines.push(`${indent} ${printComment(entry.item)}`);
|
|
2059
|
+
}
|
|
1996
2060
|
});
|
|
1997
2061
|
if (step.elseBranch) {
|
|
1998
2062
|
lines.push(`${indent} else:`);
|
|
1999
|
-
|
|
2000
|
-
|
|
2063
|
+
const elseItems = [];
|
|
2064
|
+
step.elseBranch.steps.forEach((s) => {
|
|
2065
|
+
elseItems.push({ type: "step", item: s, position: s.start });
|
|
2066
|
+
});
|
|
2067
|
+
step.elseBranch.comments.forEach((c) => {
|
|
2068
|
+
elseItems.push({ type: "comment", item: c, position: c.start || 0 });
|
|
2001
2069
|
});
|
|
2070
|
+
elseItems.sort((a, b) => a.position - b.position);
|
|
2071
|
+
elseItems.forEach((entry) => {
|
|
2072
|
+
if (entry.type === "step") {
|
|
2073
|
+
lines.push(formatPipelineStep(entry.item, indent + " "));
|
|
2074
|
+
} else {
|
|
2075
|
+
lines.push(`${indent} ${printComment(entry.item)}`);
|
|
2076
|
+
}
|
|
2077
|
+
});
|
|
2078
|
+
}
|
|
2079
|
+
if (!isLastStep) {
|
|
2080
|
+
lines.push(`${indent}end`);
|
|
2002
2081
|
}
|
|
2003
2082
|
return lines.join("\n");
|
|
2004
2083
|
} else if (step.kind === "Dispatch") {
|
|
@@ -2078,12 +2157,20 @@ function formatPipelineRef(ref) {
|
|
|
2078
2157
|
items.push({ type: "step", item: step, position: step.start });
|
|
2079
2158
|
});
|
|
2080
2159
|
ref.pipeline.comments.forEach((comment) => {
|
|
2081
|
-
items.push({ type: "comment", item: comment, position: comment.
|
|
2160
|
+
items.push({ type: "comment", item: comment, position: comment.start || 0 });
|
|
2082
2161
|
});
|
|
2083
2162
|
items.sort((a, b) => a.position - b.position);
|
|
2084
|
-
|
|
2163
|
+
let lastStepIndex = -1;
|
|
2164
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
2165
|
+
if (items[i].type === "step") {
|
|
2166
|
+
lastStepIndex = i;
|
|
2167
|
+
break;
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
items.forEach((entry, index) => {
|
|
2085
2171
|
if (entry.type === "step") {
|
|
2086
|
-
|
|
2172
|
+
const isLastStep = index === lastStepIndex;
|
|
2173
|
+
lines.push(formatPipelineStep(entry.item, " ", isLastStep));
|
|
2087
2174
|
} else {
|
|
2088
2175
|
lines.push(` ${printComment(entry.item)}`);
|
|
2089
2176
|
}
|
|
@@ -2122,6 +2209,7 @@ function formatWhen(when) {
|
|
|
2122
2209
|
printCondition,
|
|
2123
2210
|
printConfig,
|
|
2124
2211
|
printDescribe,
|
|
2212
|
+
printFeatureFlags,
|
|
2125
2213
|
printGraphQLSchema,
|
|
2126
2214
|
printMock,
|
|
2127
2215
|
printMutationResolver,
|
package/dist/index.d.cts
CHANGED
|
@@ -16,6 +16,7 @@ interface Comment {
|
|
|
16
16
|
text: string;
|
|
17
17
|
style: '#' | '//';
|
|
18
18
|
lineNumber?: number;
|
|
19
|
+
start?: number;
|
|
19
20
|
}
|
|
20
21
|
interface Config {
|
|
21
22
|
name: string;
|
|
@@ -331,6 +332,7 @@ declare function printGraphQLSchema(schema: GraphQLSchema): string;
|
|
|
331
332
|
declare function printQueryResolver(query: QueryResolver): string;
|
|
332
333
|
declare function printMutationResolver(mutation: MutationResolver): string;
|
|
333
334
|
declare function printTypeResolver(resolver: TypeResolver): string;
|
|
335
|
+
declare function printFeatureFlags(pipeline: Pipeline): string;
|
|
334
336
|
declare function printMock(mock: Mock, indent?: string): string;
|
|
335
337
|
declare function printCondition(condition: Condition, indent?: string): string;
|
|
336
338
|
declare function printTest(test: It): string;
|
|
@@ -338,7 +340,7 @@ declare function printComment(comment: Comment): string;
|
|
|
338
340
|
declare function printDescribe(describe: Describe): string;
|
|
339
341
|
declare function prettyPrint(program: Program): string;
|
|
340
342
|
declare function formatConfigValue(value: ConfigValue): string;
|
|
341
|
-
declare function formatPipelineStep(step: PipelineStep, indent?: string): string;
|
|
343
|
+
declare function formatPipelineStep(step: PipelineStep, indent?: string, isLastStep?: boolean): string;
|
|
342
344
|
declare function formatStepConfig(config: string, configType: ConfigType): string;
|
|
343
345
|
declare function formatTags(tags: Tag[]): string;
|
|
344
346
|
declare function formatTag(tag: Tag): string;
|
|
@@ -346,4 +348,4 @@ declare function formatTagExpr(expr: TagExpr): string;
|
|
|
346
348
|
declare function formatPipelineRef(ref: PipelineRef): string[];
|
|
347
349
|
declare function formatWhen(when: When): string;
|
|
348
350
|
|
|
349
|
-
export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type It, type LetValueFormat, type LetVariable, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type TagExpr, type TestLetVariable, type TypeResolver, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTagExpr, formatTags, formatWhen, getPipelineRanges, getTestLetVariableRanges, getTestLetVariables, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printTypeResolver, printVariable };
|
|
351
|
+
export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type It, type LetValueFormat, type LetVariable, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type TagExpr, type TestLetVariable, type TypeResolver, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTagExpr, formatTags, formatWhen, getPipelineRanges, getTestLetVariableRanges, getTestLetVariables, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printFeatureFlags, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printTypeResolver, printVariable };
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ interface Comment {
|
|
|
16
16
|
text: string;
|
|
17
17
|
style: '#' | '//';
|
|
18
18
|
lineNumber?: number;
|
|
19
|
+
start?: number;
|
|
19
20
|
}
|
|
20
21
|
interface Config {
|
|
21
22
|
name: string;
|
|
@@ -331,6 +332,7 @@ declare function printGraphQLSchema(schema: GraphQLSchema): string;
|
|
|
331
332
|
declare function printQueryResolver(query: QueryResolver): string;
|
|
332
333
|
declare function printMutationResolver(mutation: MutationResolver): string;
|
|
333
334
|
declare function printTypeResolver(resolver: TypeResolver): string;
|
|
335
|
+
declare function printFeatureFlags(pipeline: Pipeline): string;
|
|
334
336
|
declare function printMock(mock: Mock, indent?: string): string;
|
|
335
337
|
declare function printCondition(condition: Condition, indent?: string): string;
|
|
336
338
|
declare function printTest(test: It): string;
|
|
@@ -338,7 +340,7 @@ declare function printComment(comment: Comment): string;
|
|
|
338
340
|
declare function printDescribe(describe: Describe): string;
|
|
339
341
|
declare function prettyPrint(program: Program): string;
|
|
340
342
|
declare function formatConfigValue(value: ConfigValue): string;
|
|
341
|
-
declare function formatPipelineStep(step: PipelineStep, indent?: string): string;
|
|
343
|
+
declare function formatPipelineStep(step: PipelineStep, indent?: string, isLastStep?: boolean): string;
|
|
342
344
|
declare function formatStepConfig(config: string, configType: ConfigType): string;
|
|
343
345
|
declare function formatTags(tags: Tag[]): string;
|
|
344
346
|
declare function formatTag(tag: Tag): string;
|
|
@@ -346,4 +348,4 @@ declare function formatTagExpr(expr: TagExpr): string;
|
|
|
346
348
|
declare function formatPipelineRef(ref: PipelineRef): string[];
|
|
347
349
|
declare function formatWhen(when: When): string;
|
|
348
350
|
|
|
349
|
-
export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type It, type LetValueFormat, type LetVariable, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type TagExpr, type TestLetVariable, type TypeResolver, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTagExpr, formatTags, formatWhen, getPipelineRanges, getTestLetVariableRanges, getTestLetVariables, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printTypeResolver, printVariable };
|
|
351
|
+
export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type It, type LetValueFormat, type LetVariable, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type TagExpr, type TestLetVariable, type TypeResolver, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTagExpr, formatTags, formatWhen, getPipelineRanges, getTestLetVariableRanges, getTestLetVariables, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printFeatureFlags, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printTypeResolver, printVariable };
|
package/dist/index.mjs
CHANGED
|
@@ -78,7 +78,8 @@ var Parser = class {
|
|
|
78
78
|
type: "standalone",
|
|
79
79
|
text: restOfLine,
|
|
80
80
|
style: "#",
|
|
81
|
-
lineNumber: this.getLineNumber(start)
|
|
81
|
+
lineNumber: this.getLineNumber(start),
|
|
82
|
+
start
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
85
|
if (this.text.startsWith("//", this.pos)) {
|
|
@@ -88,7 +89,8 @@ var Parser = class {
|
|
|
88
89
|
type: "standalone",
|
|
89
90
|
text,
|
|
90
91
|
style: "//",
|
|
91
|
-
lineNumber: this.getLineNumber(start)
|
|
92
|
+
lineNumber: this.getLineNumber(start),
|
|
93
|
+
start
|
|
92
94
|
};
|
|
93
95
|
}
|
|
94
96
|
return null;
|
|
@@ -720,12 +722,12 @@ var Parser = class {
|
|
|
720
722
|
const condition = this.parseIfPipeline("then:");
|
|
721
723
|
this.skipSpaces();
|
|
722
724
|
this.expect("then:");
|
|
723
|
-
this.
|
|
725
|
+
this.skipWhitespaceOnly();
|
|
724
726
|
const thenBranch = this.parseIfPipeline("else:", "end");
|
|
725
727
|
this.skipSpaces();
|
|
726
728
|
const elseBranch = this.tryParse(() => {
|
|
727
729
|
this.expect("else:");
|
|
728
|
-
this.
|
|
730
|
+
this.skipWhitespaceOnly();
|
|
729
731
|
return this.parseIfPipeline("end");
|
|
730
732
|
});
|
|
731
733
|
this.skipSpaces();
|
|
@@ -855,8 +857,15 @@ var Parser = class {
|
|
|
855
857
|
break;
|
|
856
858
|
}
|
|
857
859
|
const hasFollowingStep = this.text.startsWith("|>", this.pos);
|
|
860
|
+
let hasStopKeyword = false;
|
|
861
|
+
for (const keyword of stopKeywords) {
|
|
862
|
+
if (this.text.startsWith(keyword, this.pos)) {
|
|
863
|
+
hasStopKeyword = true;
|
|
864
|
+
break;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
858
867
|
this.pos = lookAheadPos;
|
|
859
|
-
if (hasFollowingStep || steps.length === 0) {
|
|
868
|
+
if (hasFollowingStep || hasStopKeyword || steps.length === 0) {
|
|
860
869
|
comments.push(comment);
|
|
861
870
|
if (this.cur() === "\n") this.pos++;
|
|
862
871
|
continue;
|
|
@@ -1606,7 +1615,7 @@ function printPipeline(pipeline) {
|
|
|
1606
1615
|
items.push({ type: "step", item: step, position: step.start });
|
|
1607
1616
|
});
|
|
1608
1617
|
pipeline.pipeline.comments.forEach((comment) => {
|
|
1609
|
-
items.push({ type: "comment", item: comment, position: comment.
|
|
1618
|
+
items.push({ type: "comment", item: comment, position: comment.start || 0 });
|
|
1610
1619
|
});
|
|
1611
1620
|
items.sort((a, b) => a.position - b.position);
|
|
1612
1621
|
items.forEach((entry) => {
|
|
@@ -1668,6 +1677,26 @@ function printTypeResolver(resolver) {
|
|
|
1668
1677
|
});
|
|
1669
1678
|
return lines.join("\n");
|
|
1670
1679
|
}
|
|
1680
|
+
function printFeatureFlags(pipeline) {
|
|
1681
|
+
const lines = [];
|
|
1682
|
+
lines.push("featureFlags =");
|
|
1683
|
+
const items = [];
|
|
1684
|
+
pipeline.steps.forEach((step) => {
|
|
1685
|
+
items.push({ type: "step", item: step, position: step.start });
|
|
1686
|
+
});
|
|
1687
|
+
pipeline.comments.forEach((comment) => {
|
|
1688
|
+
items.push({ type: "comment", item: comment, position: comment.start || 0 });
|
|
1689
|
+
});
|
|
1690
|
+
items.sort((a, b) => a.position - b.position);
|
|
1691
|
+
items.forEach((entry) => {
|
|
1692
|
+
if (entry.type === "step") {
|
|
1693
|
+
lines.push(formatPipelineStep(entry.item));
|
|
1694
|
+
} else {
|
|
1695
|
+
lines.push(` ${printComment(entry.item)}`);
|
|
1696
|
+
}
|
|
1697
|
+
});
|
|
1698
|
+
return lines.join("\n");
|
|
1699
|
+
}
|
|
1671
1700
|
function printMock(mock, indent = " ") {
|
|
1672
1701
|
const target = mock.target.replace(/^(query|mutation)\.(.*)$/, "$1 $2");
|
|
1673
1702
|
return `${indent}with mock ${target} returning \`${mock.returnValue}\``;
|
|
@@ -1714,9 +1743,6 @@ function printCondition(condition, indent = " ") {
|
|
|
1714
1743
|
function printTest(test) {
|
|
1715
1744
|
const lines = [];
|
|
1716
1745
|
lines.push(` it "${test.name}"`);
|
|
1717
|
-
test.mocks.forEach((mock) => {
|
|
1718
|
-
lines.push(printMock(mock, " "));
|
|
1719
|
-
});
|
|
1720
1746
|
if (test.variables && test.variables.length > 0) {
|
|
1721
1747
|
test.variables.forEach((variable) => {
|
|
1722
1748
|
const formattedValue = variable.format === "quoted" ? `"${variable.value}"` : variable.format === "backtick" ? `\`${variable.value}\`` : variable.value;
|
|
@@ -1726,18 +1752,25 @@ function printTest(test) {
|
|
|
1726
1752
|
}
|
|
1727
1753
|
lines.push(` when ${formatWhen(test.when)}`);
|
|
1728
1754
|
let hasWithClause = false;
|
|
1729
|
-
if (test.
|
|
1730
|
-
lines.push(` with
|
|
1755
|
+
if (test.input) {
|
|
1756
|
+
lines.push(` with input \`${test.input}\``);
|
|
1731
1757
|
hasWithClause = true;
|
|
1732
1758
|
}
|
|
1733
|
-
|
|
1759
|
+
test.mocks.forEach((mock) => {
|
|
1760
|
+
const prefix = hasWithClause ? "and" : "with";
|
|
1761
|
+
const mockLine = printMock(mock, " ");
|
|
1762
|
+
const mockContent = mockLine.trim().replace(/^(with|and)\s+/, "");
|
|
1763
|
+
lines.push(` ${prefix} ${mockContent}`);
|
|
1764
|
+
hasWithClause = true;
|
|
1765
|
+
});
|
|
1766
|
+
if (test.headers) {
|
|
1734
1767
|
const prefix = hasWithClause ? "and with" : "with";
|
|
1735
|
-
lines.push(` ${prefix}
|
|
1768
|
+
lines.push(` ${prefix} headers \`${test.headers}\``);
|
|
1736
1769
|
hasWithClause = true;
|
|
1737
1770
|
}
|
|
1738
|
-
if (test.
|
|
1771
|
+
if (test.body) {
|
|
1739
1772
|
const prefix = hasWithClause ? "and with" : "with";
|
|
1740
|
-
lines.push(` ${prefix}
|
|
1773
|
+
lines.push(` ${prefix} body \`${test.body}\``);
|
|
1741
1774
|
hasWithClause = true;
|
|
1742
1775
|
}
|
|
1743
1776
|
if (test.cookies) {
|
|
@@ -1841,6 +1874,9 @@ function prettyPrint(program) {
|
|
|
1841
1874
|
program.variables.forEach((variable) => {
|
|
1842
1875
|
allItems.push({ type: "variable", item: variable, lineNumber: variable.lineNumber || 0 });
|
|
1843
1876
|
});
|
|
1877
|
+
if (program.featureFlags) {
|
|
1878
|
+
allItems.push({ type: "featureFlags", item: program.featureFlags, lineNumber: program.featureFlags.start || 0 });
|
|
1879
|
+
}
|
|
1844
1880
|
program.describes.forEach((describe) => {
|
|
1845
1881
|
allItems.push({ type: "describe", item: describe, lineNumber: describe.lineNumber || 0 });
|
|
1846
1882
|
});
|
|
@@ -1894,6 +1930,9 @@ function prettyPrint(program) {
|
|
|
1894
1930
|
case "variable":
|
|
1895
1931
|
lines.push(printVariable(entry.item));
|
|
1896
1932
|
break;
|
|
1933
|
+
case "featureFlags":
|
|
1934
|
+
lines.push(printFeatureFlags(entry.item));
|
|
1935
|
+
break;
|
|
1897
1936
|
case "describe":
|
|
1898
1937
|
lines.push(printDescribe(entry.item));
|
|
1899
1938
|
break;
|
|
@@ -1916,7 +1955,7 @@ function formatConfigValue(value) {
|
|
|
1916
1955
|
return value.value.toString();
|
|
1917
1956
|
}
|
|
1918
1957
|
}
|
|
1919
|
-
function formatPipelineStep(step, indent = " ") {
|
|
1958
|
+
function formatPipelineStep(step, indent = " ", isLastStep = false) {
|
|
1920
1959
|
if (step.kind === "Regular") {
|
|
1921
1960
|
const argsPart = step.args.length > 0 ? `(${step.args.join(", ")})` : "";
|
|
1922
1961
|
const configPart = formatStepConfig(step.config, step.configType);
|
|
@@ -1934,18 +1973,57 @@ function formatPipelineStep(step, indent = " ") {
|
|
|
1934
1973
|
return lines.join("\n");
|
|
1935
1974
|
} else if (step.kind === "If") {
|
|
1936
1975
|
const lines = [`${indent}|> if`];
|
|
1937
|
-
|
|
1938
|
-
|
|
1976
|
+
const conditionItems = [];
|
|
1977
|
+
step.condition.steps.forEach((s) => {
|
|
1978
|
+
conditionItems.push({ type: "step", item: s, position: s.start });
|
|
1979
|
+
});
|
|
1980
|
+
step.condition.comments.forEach((c) => {
|
|
1981
|
+
conditionItems.push({ type: "comment", item: c, position: c.start || 0 });
|
|
1982
|
+
});
|
|
1983
|
+
conditionItems.sort((a, b) => a.position - b.position);
|
|
1984
|
+
conditionItems.forEach((entry) => {
|
|
1985
|
+
if (entry.type === "step") {
|
|
1986
|
+
lines.push(formatPipelineStep(entry.item, indent + " "));
|
|
1987
|
+
} else {
|
|
1988
|
+
lines.push(`${indent} ${printComment(entry.item)}`);
|
|
1989
|
+
}
|
|
1939
1990
|
});
|
|
1940
1991
|
lines.push(`${indent} then:`);
|
|
1941
|
-
|
|
1942
|
-
|
|
1992
|
+
const thenItems = [];
|
|
1993
|
+
step.thenBranch.steps.forEach((s) => {
|
|
1994
|
+
thenItems.push({ type: "step", item: s, position: s.start });
|
|
1995
|
+
});
|
|
1996
|
+
step.thenBranch.comments.forEach((c) => {
|
|
1997
|
+
thenItems.push({ type: "comment", item: c, position: c.start || 0 });
|
|
1998
|
+
});
|
|
1999
|
+
thenItems.sort((a, b) => a.position - b.position);
|
|
2000
|
+
thenItems.forEach((entry) => {
|
|
2001
|
+
if (entry.type === "step") {
|
|
2002
|
+
lines.push(formatPipelineStep(entry.item, indent + " "));
|
|
2003
|
+
} else {
|
|
2004
|
+
lines.push(`${indent} ${printComment(entry.item)}`);
|
|
2005
|
+
}
|
|
1943
2006
|
});
|
|
1944
2007
|
if (step.elseBranch) {
|
|
1945
2008
|
lines.push(`${indent} else:`);
|
|
1946
|
-
|
|
1947
|
-
|
|
2009
|
+
const elseItems = [];
|
|
2010
|
+
step.elseBranch.steps.forEach((s) => {
|
|
2011
|
+
elseItems.push({ type: "step", item: s, position: s.start });
|
|
2012
|
+
});
|
|
2013
|
+
step.elseBranch.comments.forEach((c) => {
|
|
2014
|
+
elseItems.push({ type: "comment", item: c, position: c.start || 0 });
|
|
1948
2015
|
});
|
|
2016
|
+
elseItems.sort((a, b) => a.position - b.position);
|
|
2017
|
+
elseItems.forEach((entry) => {
|
|
2018
|
+
if (entry.type === "step") {
|
|
2019
|
+
lines.push(formatPipelineStep(entry.item, indent + " "));
|
|
2020
|
+
} else {
|
|
2021
|
+
lines.push(`${indent} ${printComment(entry.item)}`);
|
|
2022
|
+
}
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
if (!isLastStep) {
|
|
2026
|
+
lines.push(`${indent}end`);
|
|
1949
2027
|
}
|
|
1950
2028
|
return lines.join("\n");
|
|
1951
2029
|
} else if (step.kind === "Dispatch") {
|
|
@@ -2025,12 +2103,20 @@ function formatPipelineRef(ref) {
|
|
|
2025
2103
|
items.push({ type: "step", item: step, position: step.start });
|
|
2026
2104
|
});
|
|
2027
2105
|
ref.pipeline.comments.forEach((comment) => {
|
|
2028
|
-
items.push({ type: "comment", item: comment, position: comment.
|
|
2106
|
+
items.push({ type: "comment", item: comment, position: comment.start || 0 });
|
|
2029
2107
|
});
|
|
2030
2108
|
items.sort((a, b) => a.position - b.position);
|
|
2031
|
-
|
|
2109
|
+
let lastStepIndex = -1;
|
|
2110
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
2111
|
+
if (items[i].type === "step") {
|
|
2112
|
+
lastStepIndex = i;
|
|
2113
|
+
break;
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
items.forEach((entry, index) => {
|
|
2032
2117
|
if (entry.type === "step") {
|
|
2033
|
-
|
|
2118
|
+
const isLastStep = index === lastStepIndex;
|
|
2119
|
+
lines.push(formatPipelineStep(entry.item, " ", isLastStep));
|
|
2034
2120
|
} else {
|
|
2035
2121
|
lines.push(` ${printComment(entry.item)}`);
|
|
2036
2122
|
}
|
|
@@ -2068,6 +2154,7 @@ export {
|
|
|
2068
2154
|
printCondition,
|
|
2069
2155
|
printConfig,
|
|
2070
2156
|
printDescribe,
|
|
2157
|
+
printFeatureFlags,
|
|
2071
2158
|
printGraphQLSchema,
|
|
2072
2159
|
printMock,
|
|
2073
2160
|
printMutationResolver,
|