Repository: honojs/hono
File: src/helper/ssg/index.test.tsx (TypeScript)

Code before:
              <p>{content}</p>
            </body>
          </html>
        )
      })
      await next()
    })
    app.get('/Charlie', (c) => {
      return c.render('Hello!', { title: 'Charlies Page' })
    })
    // Included params
    app.get('/post/:post', ssgParams(() => [
      {
        post: '1'
      },
      {
        post: '2'
      }
    ]), c => c.html(<h1>{c.req.param('post')}</h1>))

    const fsMock = {
      writeFile: vi.fn((path, data) => Promise.resolve()),
      mkdir: vi.fn((path, options) => Promise.resolve()),
    }

    const htmlMap = await generateHtmlMap(app, {})
    const files = await saveHtmlToLocal(htmlMap, fsMock, './static')

    expect(files.length).toBeGreaterThan(0)
    expect(fsMock.mkdir).toHaveBeenCalledWith(expect.any(String), { recursive: true })
    expect(fsMock.writeFile).toHaveBeenCalled()
  })
  it('Should handle errors correctly', async () => {
    const app = new Hono()
    app.get('/', (c) => c.text('Hello, World!'))
    app.get('/about', (c) => c.text('About Page'))
    app.get('/about/some', (c) => c.text('About Page 2tier'))
    app.post('/about/some/thing', (c) => c.text('About Page 3tier'))
    app.get('/bravo', (c) => c.html('Bravo Page'))
    app.get('/Charlie', async (c, next) => {
      c.setRenderer((content, head) => {
        return c.html(
          <html>
            <head>
              <title>{head.title || ''}</title>
            </head>
            <body>
              <p>{content}</p>
            </body>
          </html>
        )

Review comment (suggestion):
We should write the tests for checking the contents of `htmlMap`. Like this:

```ts
expect(htmlMap.get('/post/1')).toBe('<h1>1</h1>')
```

Code after:
        return c.html(
          <html>
            <head>
              <title>{head.title || ''}</title>
            </head>
            <body>
              <p>{content}</p>
            </body>
          </html>
        )
      })
      await next()
    })
    app.get('/Charlie', (c) => {
      return c.render('Hello!', { title: 'Charlies Page' })
    })

    // Included params
    app.get(
      '/post/:post',
      ssgParams(() => postParams),
      (c) => c.html(<h1>{c.req.param('post')}</h1>)
    )
  })
  it('Should correctly generate static HTML files for Hono routes', async () => {
    const fsMock: FileSystemModule = {
      writeFile: vi.fn(() => Promise.resolve()),
      mkdir: vi.fn(() => Promise.resolve()),
    }

    const htmlMap = await fetchRoutesContent(app)

    for (const postParam of postParams) {
      const html = htmlMap.get(`/post/${postParam.post}`)
      expect(html?.content).toBe(`<h1>${postParam.post}</h1>`)
    }

    const files = await saveContentToFiles(htmlMap, fsMock, './static')

    expect(files.length).toBeGreaterThan(0)
    expect(fsMock.mkdir).toHaveBeenCalledWith(expect.any(String), {
      recursive: true,
    })
    expect(fsMock.writeFile).toHaveBeenCalled()
  })

  it('Should handle file system errors correctly in saveContentToFiles', async () => {
    const fsMock: FileSystemModule = {
      writeFile: vi.fn(() => Promise.reject(new Error('Write error'))),
      mkdir: vi.fn(() => Promise.resolve()),
    }