Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(esbuild): add test for configuration overrides #11267

Merged
merged 4 commits into from Dec 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions packages/vite/src/node/__tests__/plugins/esbuild.spec.ts
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