Skip to content

Commit f897b64

Browse files
authoredDec 10, 2022
chore(esbuild): add test for configuration overrides (#11267)
1 parent 8241758 commit f897b64

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
 

‎packages/vite/src/node/__tests__/plugins/esbuild.spec.ts

+56
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,62 @@ describe('transformWithEsbuild', () => {
249249
expect(result?.code).toBeTruthy()
250250
expect(result?.map).toBeTruthy()
251251
})
252+
253+
test('correctly overrides TS configuration and applies automatic transform', async () => {
254+
const jsxImportSource = 'bar'
255+
const result = await transformWithEsbuild(
256+
'const foo = () => <></>',
257+
'baz.jsx',
258+
{
259+
tsconfigRaw: {
260+
compilerOptions: {
261+
jsx: 'preserve',
262+
},
263+
},
264+
jsx: 'automatic',
265+
jsxImportSource,
266+
},
267+
)
268+
expect(result?.code).toContain(`${jsxImportSource}/jsx-runtime`)
269+
expect(result?.code).toContain('/* @__PURE__ */')
270+
})
271+
272+
test('correctly overrides TS configuration and preserves code', async () => {
273+
const foo = 'const foo = () => <></>'
274+
const result = await transformWithEsbuild(foo, 'baz.jsx', {
275+
tsconfigRaw: {
276+
compilerOptions: {
277+
jsx: 'react-jsx',
278+
},
279+
},
280+
jsx: 'preserve',
281+
})
282+
expect(result?.code).toContain(foo)
283+
})
284+
285+
test('correctly overrides TS configuration and transforms code', async () => {
286+
const jsxFactory = 'h',
287+
jsxFragment = 'bar'
288+
const result = await transformWithEsbuild(
289+
'const foo = () => <></>',
290+
'baz.jsx',
291+
{
292+
tsconfigRaw: {
293+
compilerOptions: {
294+
jsxFactory: 'g',
295+
jsxFragmentFactory: 'foo',
296+
jsxImportSource: 'baz',
297+
},
298+
},
299+
jsx: 'transform',
300+
jsxFactory,
301+
jsxFragment,
302+
},
303+
)
304+
expect(result?.code).toContain(
305+
`/* @__PURE__ */ ${jsxFactory}(${jsxFragment}, null)`,
306+
)
307+
})
252308
})
253309

254310
/**

0 commit comments

Comments
 (0)
Please sign in to comment.