summaryrefslogtreecommitdiff
path: root/packages/integrations/vue/test/toTsx.test.js
blob: b91b5cad11da6c6d5218df805cdebc2e3bc64029 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { toTSX } from '../dist/editor.cjs';

describe('toTSX function', () => {
	it('should correctly transform Vue code to TSX with comments', () => {
		const vueCode = `
      <template>
        <div>{{ msg }}</div>
      </template>

      <script setup>
        // This is a comment in script setup
        // defineProps(['msg']);
				// console.log('foo)
      </script>
    `;

		const className = 'MyComponent';
		const result = toTSX(vueCode, className);

		// Replace the expectations below with the expected result based on your logic
		assert.strictEqual(
			result,
			`export default function ${className}__AstroComponent_(_props: Record<string, any>): any {}`,
		);
	});
	it('should correctly transform Vue code to TSX', () => {
		const vueCode = `
      <template>
        <div @click="handleClick">{{ msg }}</div>
      </template>

      <script setup>
        const props defineProps({
					msg: String
				});
				const handleClick = () => {
					console.log('foo');
				}
      </script>
    `;

		const className = 'MyComponent';
		const result = toTSX(vueCode, className);
		assert.strictEqual(
			result.replace(/\s/g, ''),
			`import{defineProps}from'vue';constProps=defineProps({msg:String})exportdefaultfunction${className}__AstroComponent_(_props:typeofProps):any{<div></div>}`,
		);
	});
});