eventmodeler 0.2.8 → 0.2.9
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/lib/format.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
export type OutputFormat = 'xml' | 'json';
|
|
2
|
+
/**
|
|
3
|
+
* Escape string for use in XML attributes (escapes quotes)
|
|
4
|
+
*/
|
|
2
5
|
export declare function escapeXml(str: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Escape string for use in XML text content (doesn't escape quotes)
|
|
8
|
+
*/
|
|
9
|
+
export declare function escapeXmlText(str: string): string;
|
|
3
10
|
export declare function outputJson(data: unknown): void;
|
package/dist/lib/format.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escape string for use in XML attributes (escapes quotes)
|
|
3
|
+
*/
|
|
1
4
|
export function escapeXml(str) {
|
|
2
5
|
return str
|
|
3
6
|
.replace(/&/g, '&')
|
|
@@ -6,6 +9,15 @@ export function escapeXml(str) {
|
|
|
6
9
|
.replace(/"/g, '"')
|
|
7
10
|
.replace(/'/g, ''');
|
|
8
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Escape string for use in XML text content (doesn't escape quotes)
|
|
14
|
+
*/
|
|
15
|
+
export function escapeXmlText(str) {
|
|
16
|
+
return str
|
|
17
|
+
.replace(/&/g, '&')
|
|
18
|
+
.replace(/</g, '<')
|
|
19
|
+
.replace(/>/g, '>');
|
|
20
|
+
}
|
|
9
21
|
export function outputJson(data) {
|
|
10
22
|
console.log(JSON.stringify(data, null, 2));
|
|
11
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { escapeXml, outputJson } from '../../lib/format.js';
|
|
1
|
+
import { escapeXml, escapeXmlText, outputJson } from '../../lib/format.js';
|
|
2
2
|
import { findElementOrExit } from '../../lib/element-lookup.js';
|
|
3
3
|
function formatFieldValues(values) {
|
|
4
4
|
if (!values || Object.keys(values).length === 0)
|
|
@@ -243,7 +243,7 @@ function formatSliceXml(model, slice) {
|
|
|
243
243
|
for (const scenario of scenarios) {
|
|
244
244
|
xml += ` <scenario name="${escapeXml(scenario.name)}">\n`;
|
|
245
245
|
if (scenario.description) {
|
|
246
|
-
xml += ` <description>${
|
|
246
|
+
xml += ` <description>${escapeXmlText(scenario.description)}</description>\n`;
|
|
247
247
|
}
|
|
248
248
|
if (scenario.givenEvents.length > 0) {
|
|
249
249
|
xml += ' <given>\n';
|
|
@@ -252,7 +252,7 @@ function formatSliceXml(model, slice) {
|
|
|
252
252
|
const name = evt?.name ?? 'UnknownEvent';
|
|
253
253
|
const values = formatFieldValues(given.fieldValues);
|
|
254
254
|
xml += values
|
|
255
|
-
? ` <event type="${escapeXml(name)}">${
|
|
255
|
+
? ` <event type="${escapeXml(name)}">${escapeXmlText(values)}</event>\n`
|
|
256
256
|
: ` <event type="${escapeXml(name)}"/>\n`;
|
|
257
257
|
}
|
|
258
258
|
xml += ' </given>\n';
|
|
@@ -263,7 +263,7 @@ function formatSliceXml(model, slice) {
|
|
|
263
263
|
const values = formatFieldValues(scenario.whenCommand.fieldValues);
|
|
264
264
|
xml += ' <when>\n';
|
|
265
265
|
xml += values
|
|
266
|
-
? ` <command type="${escapeXml(name)}">${
|
|
266
|
+
? ` <command type="${escapeXml(name)}">${escapeXmlText(values)}</command>\n`
|
|
267
267
|
: ` <command type="${escapeXml(name)}"/>\n`;
|
|
268
268
|
xml += ' </when>\n';
|
|
269
269
|
}
|
|
@@ -272,7 +272,7 @@ function formatSliceXml(model, slice) {
|
|
|
272
272
|
xml += ` <error`;
|
|
273
273
|
if (scenario.then.errorType)
|
|
274
274
|
xml += ` type="${escapeXml(scenario.then.errorType)}"`;
|
|
275
|
-
xml += `>${
|
|
275
|
+
xml += `>${escapeXmlText(scenario.then.errorMessage ?? '')}</error>\n`;
|
|
276
276
|
}
|
|
277
277
|
else if (scenario.then.type === 'events' && scenario.then.expectedEvents) {
|
|
278
278
|
for (const expected of scenario.then.expectedEvents) {
|
|
@@ -280,7 +280,7 @@ function formatSliceXml(model, slice) {
|
|
|
280
280
|
const name = evt?.name ?? 'UnknownEvent';
|
|
281
281
|
const values = formatFieldValues(expected.fieldValues);
|
|
282
282
|
xml += values
|
|
283
|
-
? ` <event type="${escapeXml(name)}">${
|
|
283
|
+
? ` <event type="${escapeXml(name)}">${escapeXmlText(values)}</event>\n`
|
|
284
284
|
: ` <event type="${escapeXml(name)}"/>\n`;
|
|
285
285
|
}
|
|
286
286
|
}
|
|
@@ -289,7 +289,7 @@ function formatSliceXml(model, slice) {
|
|
|
289
289
|
const rm = model.readModels.get(assertion.readModelStickyId);
|
|
290
290
|
const name = rm?.name ?? 'UnknownReadModel';
|
|
291
291
|
xml += ` <read-model-assertion type="${escapeXml(name)}">\n`;
|
|
292
|
-
xml += ` <expected>${
|
|
292
|
+
xml += ` <expected>${escapeXmlText(formatFieldValues(assertion.expectedFieldValues))}</expected>\n`;
|
|
293
293
|
xml += ' </read-model-assertion>\n';
|
|
294
294
|
}
|
|
295
295
|
xml += ' </then>\n';
|