Skip to content

Commit

Permalink
chore(esbuild): add test for configuration overrides (#11267)
Browse files Browse the repository at this point in the history
  • Loading branch information
high1 authored Dec 10, 2022
1 parent 8241758 commit f897b64
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions packages/vite/src/node/__tests__/plugins/esbuild.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,62 @@ describe('transformWithEsbuild', () => {
expect(result?.code).toBeTruthy()
expect(result?.map).toBeTruthy()
})

test('correctly overrides TS configuration and applies automatic transform', async () => {
const jsxImportSource = 'bar'
const result = await transformWithEsbuild(
'const foo = () => <></>',
'baz.jsx',
{
tsconfigRaw: {
compilerOptions: {
jsx: 'preserve',
},
},
jsx: 'automatic',
jsxImportSource,
},
)
expect(result?.code).toContain(`${jsxImportSource}/jsx-runtime`)
expect(result?.code).toContain('/* @__PURE__ */')
})

test('correctly overrides TS configuration and preserves code', async () => {
const foo = 'const foo = () => <></>'
const result = await transformWithEsbuild(foo, 'baz.jsx', {
tsconfigRaw: {
compilerOptions: {
jsx: 'react-jsx',
},
},
jsx: 'preserve',
})
expect(result?.code).toContain(foo)
})

test('correctly overrides TS configuration and transforms code', async () => {
const jsxFactory = 'h',
jsxFragment = 'bar'
const result = await transformWithEsbuild(
'const foo = () => <></>',
'baz.jsx',
{
tsconfigRaw: {
compilerOptions: {
jsxFactory: 'g',
jsxFragmentFactory: 'foo',
jsxImportSource: 'baz',
},
},
jsx: 'transform',
jsxFactory,
jsxFragment,
},
)
expect(result?.code).toContain(
`/* @__PURE__ */ ${jsxFactory}(${jsxFragment}, null)`,
)
})
})

/**
Expand Down

0 comments on commit f897b64

Please sign in to comment.