Skip to content

Commit f836666

Browse files
lvluulvluu
andauthored
fix(yaml-to-json): allow merge key to be parsed (CorentinTh#1359)
* fix(yaml-to-json): allow merge key to be parsed * correct e2e tests --------- Co-authored-by: lvluu <[email protected]>
1 parent aa8cba9 commit f836666

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/tools/yaml-to-json-converter/yaml-to-json.e2e.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,53 @@ test.describe('Tool - Yaml to json', () => {
2828
`.trim(),
2929
);
3030
});
31+
32+
test('Yaml is parsed with merge key and output correct json', async ({ page }) => {
33+
await page.getByTestId('input').fill(`
34+
default: &default
35+
name: ''
36+
age: 0
37+
38+
person:
39+
*default
40+
41+
persons:
42+
- <<: *default
43+
age: 1
44+
- <<: *default
45+
name: John
46+
- { age: 3, <<: *default }
47+
48+
`);
49+
50+
const generatedJson = await page.getByTestId('area-content').innerText();
51+
52+
expect(generatedJson.trim()).toEqual(
53+
`
54+
{
55+
"default": {
56+
"name": "",
57+
"age": 0
58+
},
59+
"person": {
60+
"name": "",
61+
"age": 0
62+
},
63+
"persons": [
64+
{
65+
"name": "",
66+
"age": 1
67+
},
68+
{
69+
"name": "John",
70+
"age": 0
71+
},
72+
{
73+
"age": 3,
74+
"name": ""
75+
}
76+
]
77+
}`.trim(),
78+
);
79+
});
3180
});

src/tools/yaml-to-json-converter/yaml-to-json.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { withDefaultOnError } from '@/utils/defaults';
66
77
function transformer(value: string) {
88
return withDefaultOnError(() => {
9-
const obj = parseYaml(value);
9+
const obj = parseYaml(value, { merge: true });
1010
return obj ? JSON.stringify(obj, null, 3) : '';
1111
}, '');
1212
}

0 commit comments

Comments
 (0)