diff --git a/packages/lib/preprocess/src/add-blank-lines.spec.cjs b/packages/lib/preprocess/src/add-blank-lines.spec.cjs index 26c0e2e06c..9092ba4f3a 100644 --- a/packages/lib/preprocess/src/add-blank-lines.spec.cjs +++ b/packages/lib/preprocess/src/add-blank-lines.spec.cjs @@ -2,54 +2,58 @@ import { describe, it, expect } from 'vitest'; import addBlankLines from '../src/add-blank-lines.cjs'; describe('addBlankLines Preprocessor', () => { - - it('should add a blank line after a component opening tag', () => { - const input = `
+ it('should add a blank line after a component opening tag', () => { + const input = `
Here is a metric definition
`; - const expectedOutput = `
+ const expectedOutput = `
Here is a metric definition
`; - const result = addBlankLines.markup({ content: input, filename: 'test.md' }); - expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim()); - }); - + const result = addBlankLines.markup({ content: input, filename: 'test.md' }); + expect(result.code.replace(/\s+/g, ' ').trim()).toBe( + expectedOutput.replace(/\s+/g, ' ').trim() + ); + }); - it('should add a newline after {/each}', () => { - const input = `{#each items as item} + it('should add a newline after {/each}', () => { + const input = `{#each items as item} {item.name} {/each}`; - const expectedOutput = `{#each items as item} + const expectedOutput = `{#each items as item} {item.name} {/each} `; - const result = addBlankLines.markup({ content: input, filename: 'test.md' }); - expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim()); - }); + const result = addBlankLines.markup({ content: input, filename: 'test.md' }); + expect(result.code.replace(/\s+/g, ' ').trim()).toBe( + expectedOutput.replace(/\s+/g, ' ').trim() + ); + }); it('should add a newline before {/each}', () => { - const input = `{#each items as item} + const input = `{#each items as item} {item.name} {/each}`; - const expectedOutput = `{#each items as item} + const expectedOutput = `{#each items as item} {item.name} {/each}`; - const result = addBlankLines.markup({ content: input, filename: 'test.md' }); - expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim()); - }); + const result = addBlankLines.markup({ content: input, filename: 'test.md' }); + expect(result.code.replace(/\s+/g, ' ').trim()).toBe( + expectedOutput.replace(/\s+/g, ' ').trim() + ); + }); - it('should add a newline before {:else}', () => { - const input = `{#if condition} + it('should add a newline before {:else}', () => { + const input = `{#if condition} Condition met {:else} Condition not met {/if}`; - const expectedOutput = `{#if condition} + const expectedOutput = `{#if condition} Condition met {:else} @@ -57,9 +61,11 @@ Condition not met {/if}`; - const result = addBlankLines.markup({ content: input, filename: 'test.md' }); - expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim()); - }); + const result = addBlankLines.markup({ content: input, filename: 'test.md' }); + expect(result.code.replace(/\s+/g, ' ').trim()).toBe( + expectedOutput.replace(/\s+/g, ' ').trim() + ); + }); it('should clean up excessive blank lines in attributes', () => { const input = ``; - + const result = addBlankLines.markup({ content: input, filename: 'test.md' }); - - expect(result.code.replace(/\s+/g, ' ').trim()).toEqual(expectedOutput.replace(/\s+/g, ' ').trim()); - }); - - it('should handle a component with no attributes', () => { - const input = ``; - const expectedOutput = ``; + expect(result.code.replace(/\s+/g, ' ').trim()).toEqual( + expectedOutput.replace(/\s+/g, ' ').trim() + ); + }); - const result = addBlankLines.markup({ content: input, filename: 'test.md' }); - expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim()); - }); + it('should handle a component with no attributes', () => { + const input = ``; + const expectedOutput = ``; + const result = addBlankLines.markup({ content: input, filename: 'test.md' }); + expect(result.code.replace(/\s+/g, ' ').trim()).toBe( + expectedOutput.replace(/\s+/g, ' ').trim() + ); + }); }); diff --git a/packages/lib/preprocess/src/process-each-blocks.spec.cjs b/packages/lib/preprocess/src/process-each-blocks.spec.cjs index 4e9f813d42..19cedce6da 100644 --- a/packages/lib/preprocess/src/process-each-blocks.spec.cjs +++ b/packages/lib/preprocess/src/process-each-blocks.spec.cjs @@ -2,26 +2,27 @@ import { describe, it, expect } from 'vitest'; import processEachBlocks from '../src/process-each-blocks.cjs'; describe('processEachBlocks Preprocessor', () => { - - it('should handle text without blank line before closing each tag', () => { - const input = `{#each something as thing} + it('should handle text without blank line before closing each tag', () => { + const input = `{#each something as thing}

text {/each}

`; - const expectedOutput = `{#each something as thing} + const expectedOutput = `{#each something as thing}

text

{/each}`; - const result = processEachBlocks.markup({ content: input, filename: 'test.md' }); - expect(result.code.replace(/\s+/g, ' ').trim()).toEqual(expectedOutput.replace(/\s+/g, ' ').trim()); - }); + const result = processEachBlocks.markup({ content: input, filename: 'test.md' }); + expect(result.code.replace(/\s+/g, ' ').trim()).toEqual( + expectedOutput.replace(/\s+/g, ' ').trim() + ); + }); - it('should handle unordered lists without blank line before closing each tag', () => { - const input = ` + it('should handle unordered lists without blank line before closing each tag', () => { + const input = ` {#each something as thing}
  • one {/each}
`; - const expectedOutput = ` + const expectedOutput = `
    {#each something as thing}
  • one @@ -29,16 +30,18 @@ describe('processEachBlocks Preprocessor', () => { {/each}
`; - const result = processEachBlocks.markup({ content: input, filename: 'test.md' }); - expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim()); - }); + const result = processEachBlocks.markup({ content: input, filename: 'test.md' }); + expect(result.code.replace(/\s+/g, ' ').trim()).toBe( + expectedOutput.replace(/\s+/g, ' ').trim() + ); + }); - it('should handle ordered lists without blank line before closing each tag', () => { - const input = ` + it('should handle ordered lists without blank line before closing each tag', () => { + const input = ` {#each something as thing}
  1. one {/each}
`; - const expectedOutput = ` + const expectedOutput = `
    {#each something as thing}
  1. one @@ -46,42 +49,48 @@ describe('processEachBlocks Preprocessor', () => { {/each}
`; - const result = processEachBlocks.markup({ content: input, filename: 'test.md' }); - expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim()); - }); + const result = processEachBlocks.markup({ content: input, filename: 'test.md' }); + expect(result.code.replace(/\s+/g, ' ').trim()).toBe( + expectedOutput.replace(/\s+/g, ' ').trim() + ); + }); - it('should handle unordered lists contained inside each tags', () => { - const input = `{#each something as thing}
    + it('should handle unordered lists contained inside each tags', () => { + const input = `{#each something as thing}
    • one
    {/each}`; - const expectedOutput = `
      + const expectedOutput = `
        {#each something as thing}
      • one
      • {/each}
      `; - const result = processEachBlocks.markup({ content: input, filename: 'test.md' }); - expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim()); - }); + const result = processEachBlocks.markup({ content: input, filename: 'test.md' }); + expect(result.code.replace(/\s+/g, ' ').trim()).toBe( + expectedOutput.replace(/\s+/g, ' ').trim() + ); + }); - it('should handle ordered lists contained inside each tags', () => { - const input = `{#each something as thing}
        + it('should handle ordered lists contained inside each tags', () => { + const input = `{#each something as thing}
        1. one
        {/each}`; - const expectedOutput = `
          + const expectedOutput = `
            {#each something as thing}
          1. one
          2. {/each}
          `; - - const result = processEachBlocks.markup({ content: input, filename: 'test.md' }); - expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim()); - }); - it('should preserve code blocks and inline code snippets', () => { - const input = `# Markdown with Code + const result = processEachBlocks.markup({ content: input, filename: 'test.md' }); + expect(result.code.replace(/\s+/g, ' ').trim()).toBe( + expectedOutput.replace(/\s+/g, ' ').trim() + ); + }); + + it('should preserve code blocks and inline code snippets', () => { + const input = `# Markdown with Code \`\`\`js console.log('Code block'); @@ -94,7 +103,7 @@ Inline code: \`console.log('inline');\`
        1. {item.name}
    {/each}`; - const expectedOutput = `# Markdown with Code + const expectedOutput = `# Markdown with Code \`\`\`js console.log('Code block'); @@ -108,7 +117,9 @@ Inline code: \`console.log('inline');\` {/each}
`; - const result = processEachBlocks.markup({ content: input, filename: 'test.md' }); - expect(result.code.replace(/\s+/g, ' ').trim()).toBe(expectedOutput.replace(/\s+/g, ' ').trim()); - }); + const result = processEachBlocks.markup({ content: input, filename: 'test.md' }); + expect(result.code.replace(/\s+/g, ' ').trim()).toBe( + expectedOutput.replace(/\s+/g, ' ').trim() + ); + }); });