Skip to content

Commit

Permalink
fix(yaml-to-json): allow merge key to be parsed (CorentinTh#1359)
Browse files Browse the repository at this point in the history
* fix(yaml-to-json): allow merge key to be parsed

* correct e2e tests

---------

Co-authored-by: lvluu <[email protected]>
  • Loading branch information
lvluu and lvluu authored Oct 24, 2024
1 parent aa8cba9 commit f836666
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
49 changes: 49 additions & 0 deletions src/tools/yaml-to-json-converter/yaml-to-json.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,53 @@ test.describe('Tool - Yaml to json', () => {
`.trim(),
);
});

test('Yaml is parsed with merge key and output correct json', async ({ page }) => {
await page.getByTestId('input').fill(`
default: &default
name: ''
age: 0
person:
*default
persons:
- <<: *default
age: 1
- <<: *default
name: John
- { age: 3, <<: *default }
`);

const generatedJson = await page.getByTestId('area-content').innerText();

expect(generatedJson.trim()).toEqual(
`
{
"default": {
"name": "",
"age": 0
},
"person": {
"name": "",
"age": 0
},
"persons": [
{
"name": "",
"age": 1
},
{
"name": "John",
"age": 0
},
{
"age": 3,
"name": ""
}
]
}`.trim(),
);
});
});
2 changes: 1 addition & 1 deletion src/tools/yaml-to-json-converter/yaml-to-json.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { withDefaultOnError } from '@/utils/defaults';
function transformer(value: string) {
return withDefaultOnError(() => {
const obj = parseYaml(value);
const obj = parseYaml(value, { merge: true });
return obj ? JSON.stringify(obj, null, 3) : '';
}, '');
}
Expand Down

0 comments on commit f836666

Please sign in to comment.