import { expect, test } from 'vitest'
import { instances, runBrowserTests } from './utils'

test('vi.defineHelper hides internal stack traces', async () => {
  const { errorTree } = await runBrowserTests({
    root: './fixtures/assertion-helper',
  })

  const projectTree = errorTree({ project: true, stackTrace: true })
  expect(Object.keys(projectTree).sort()).toEqual(instances.map(i => i.browser).sort())

  for (const [name, tree] of Object.entries(projectTree)) {
    if (name === 'firefox') {
      expect.soft(tree).toMatchInlineSnapshot(`
        {
          "basic.test.ts": {
            "async": [
              "expected 'async' to deeply equal 'x'
            at basic.test.ts:26:9",
            ],
            "soft": [
              "expected 'soft' to deeply equal 'x'
            at basic.test.ts:30:3",
            ],
            "soft async": [
              "expected 'soft async' to deeply equal 'x'
            at basic.test.ts:34:9",
            ],
            "sync": [
              "expected 'sync' to deeply equal 'x'
            at basic.test.ts:22:3",
            ],
          },
        }
      `)
    }
    else if (name === 'webkit') {
      expect.soft(tree).toMatchInlineSnapshot(`
        {
          "basic.test.ts": {
            "async": [
              "expected 'async' to deeply equal 'x'
            at basic.test.ts:26:9",
            ],
            "soft": [
              "expected 'soft' to deeply equal 'x'
            at basic.test.ts:30:3",
            ],
            "soft async": [
              "expected 'soft async' to deeply equal 'x'
            at basic.test.ts:34:9",
            ],
            "sync": [
              "expected 'sync' to deeply equal 'x'
            at basic.test.ts:22:3",
            ],
          },
        }
      `)
    }
    else {
      expect.soft(tree).toMatchInlineSnapshot(`
        {
          "basic.test.ts": {
            "async": [
              "expected 'async' to deeply equal 'x'
            at basic.test.ts:26:3",
            ],
            "soft": [
              "expected 'soft' to deeply equal 'x'
            at basic.test.ts:30:3",
            ],
            "soft async": [
              "expected 'soft async' to deeply equal 'x'
            at basic.test.ts:34:3",
            ],
            "sync": [
              "expected 'sync' to deeply equal 'x'
            at basic.test.ts:22:3",
            ],
          },
        }
      `)
    }
  }
})
