From bc48880fe66a48f415ee8284d24713ef330053de Mon Sep 17 00:00:00 2001 From: lvluu Date: Tue, 22 Oct 2024 16:37:15 +0700 Subject: [PATCH 1/2] fix(yaml-to-json): allow merge key to be parsed --- .../yaml-to-json.e2e.spec.ts | 49 +++++++++++++++++++ .../yaml-to-json-converter/yaml-to-json.vue | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/tools/yaml-to-json-converter/yaml-to-json.e2e.spec.ts b/src/tools/yaml-to-json-converter/yaml-to-json.e2e.spec.ts index 7b2a2d1823..fe2d9ba5e8 100644 --- a/src/tools/yaml-to-json-converter/yaml-to-json.e2e.spec.ts +++ b/src/tools/yaml-to-json-converter/yaml-to-json.e2e.spec.ts @@ -28,4 +28,53 @@ test.describe('Tool - Yaml to json', () => { `.trim(), ); }); + + test('Yaml is parsed and output clean 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(), + ); + }); }); diff --git a/src/tools/yaml-to-json-converter/yaml-to-json.vue b/src/tools/yaml-to-json-converter/yaml-to-json.vue index 39c9297f2b..72608add1c 100644 --- a/src/tools/yaml-to-json-converter/yaml-to-json.vue +++ b/src/tools/yaml-to-json-converter/yaml-to-json.vue @@ -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) : ''; }, ''); } From fd02c35ec394c867353ce9ba488fedd6c5dcccd7 Mon Sep 17 00:00:00 2001 From: lvluu Date: Tue, 22 Oct 2024 16:54:47 +0700 Subject: [PATCH 2/2] correct e2e tests --- src/tools/yaml-to-json-converter/yaml-to-json.e2e.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/yaml-to-json-converter/yaml-to-json.e2e.spec.ts b/src/tools/yaml-to-json-converter/yaml-to-json.e2e.spec.ts index fe2d9ba5e8..d6ed84c3d1 100644 --- a/src/tools/yaml-to-json-converter/yaml-to-json.e2e.spec.ts +++ b/src/tools/yaml-to-json-converter/yaml-to-json.e2e.spec.ts @@ -29,7 +29,7 @@ test.describe('Tool - Yaml to json', () => { ); }); - test('Yaml is parsed and output clean json', async ({ page }) => { + test('Yaml is parsed with merge key and output correct json', async ({ page }) => { await page.getByTestId('input').fill(` default: &default name: ''