Skip to content

Commit 31df458

Browse files
authored
test(component-meta): simplify code with snapshots (#5403)
1 parent eac7125 commit 31df458

File tree

16 files changed

+1122
-815
lines changed

16 files changed

+1122
-815
lines changed

packages/component-meta/tests/index.spec.ts

Lines changed: 1083 additions & 636 deletions
Large diffs are not rendered by default.

packages/tsc/tests/__snapshots__/dts.spec.ts.snap

Lines changed: 7 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,6 @@ type __VLS_PrettifyLocal<T> = {
2727
"
2828
`;
2929
30-
exports[`vue-tsc-dts > Input: class-slots/component.vue, Output: class-slots/component.vue.d.ts 1`] = `
31-
"import type { VNode } from 'vue';
32-
declare const _default: new () => {
33-
$slots: {
34-
default: (props: {
35-
num: number;
36-
}) => VNode[];
37-
foo: (props: {
38-
str: string;
39-
}) => VNode[];
40-
};
41-
};
42-
export default _default;
43-
"
44-
`;
45-
4630
exports[`vue-tsc-dts > Input: empty-component/component.vue, Output: empty-component/component.vue.d.ts 1`] = `
4731
"declare const _default: import("vue").DefineComponent2<{
4832
setup(): {};
@@ -95,55 +79,6 @@ export default _default;
9579
"
9680
`;
9781
98-
exports[`vue-tsc-dts > Input: events/component-class.vue, Output: events/component-class.vue.d.ts 1`] = `
99-
"type __VLS_Emit = {
100-
/** Emitted when foo... */
101-
(evt: "foo", value: string): void;
102-
};
103-
declare const _default: import("vue").DefineComponent2<{
104-
setup(): {};
105-
data(): {};
106-
props: {};
107-
computed: {};
108-
methods: {};
109-
mixins: {}[];
110-
extends: {};
111-
emits: string[];
112-
slots: {};
113-
inject: {};
114-
components: {};
115-
directives: {};
116-
provide: {};
117-
expose: string;
118-
__typeProps: unknown;
119-
__typeEmits: __VLS_Emit;
120-
__typeRefs: {};
121-
__typeEl: any;
122-
__defaults: unknown;
123-
}>;
124-
export default _default;
125-
"
126-
`;
127-
128-
exports[`vue-tsc-dts > Input: events/component-generic.vue, Output: events/component-generic.vue.d.ts 1`] = `
129-
"declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
130-
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
131-
readonly onFoo?: (value: string) => any;
132-
} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onFoo"> & {} & Partial<{}>> & import("vue").PublicProps;
133-
expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
134-
attrs: any;
135-
slots: {};
136-
emit: (evt: "foo", value: string) => void;
137-
}>) => import("vue").VNode & {
138-
__ctx?: Awaited<typeof __VLS_setup>;
139-
};
140-
export default _default;
141-
type __VLS_PrettifyLocal<T> = {
142-
[K in keyof T]: T[K];
143-
} & {};
144-
"
145-
`;
146-
14782
exports[`vue-tsc-dts > Input: generic/component.vue, Output: generic/component.vue.d.ts 1`] = `
14883
"declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
14984
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
@@ -306,7 +241,7 @@ export default _default;
306241
`;
307242
308243
exports[`vue-tsc-dts > Input: reference-type-events/component.vue, Output: reference-type-events/component.vue.d.ts 1`] = `
309-
"import { MyEvents } from './my-events';
244+
"import type { MyEvents } from './my-events';
310245
declare const _default: import("vue").DefineComponent2<{
311246
setup(): {};
312247
data(): {};
@@ -509,7 +444,7 @@ exports[`vue-tsc-dts > Input: reference-type-props/component-js.vue, Output: ref
509444
};
510445
xbar: {
511446
readonly type: StringConstructor;
512-
readonly value: "";
447+
readonly default: "";
513448
};
514449
xbaz: {
515450
readonly type: StringConstructor;
@@ -558,7 +493,7 @@ exports[`vue-tsc-dts > Input: reference-type-props/component-js-setup.vue, Outpu
558493
};
559494
xbar: {
560495
readonly type: StringConstructor;
561-
readonly value: "";
496+
readonly default: "";
562497
};
563498
xbaz: {
564499
readonly type: StringConstructor;
@@ -704,7 +639,7 @@ export declare const StringRequired: {
704639
};
705640
export declare const StringEmpty: {
706641
readonly type: StringConstructor;
707-
readonly value: "";
642+
readonly default: "";
708643
};
709644
export declare const StringUndefined: {
710645
readonly type: StringConstructor;
@@ -713,7 +648,7 @@ export {};
713648
"
714649
`;
715650
716-
exports[`vue-tsc-dts > Input: template-slots/component.vue, Output: template-slots/component.vue.d.ts 1`] = `
651+
exports[`vue-tsc-dts > Input: reference-type-slots/component.vue, Output: reference-type-slots/component.vue.d.ts 1`] = `
717652
"declare var __VLS_1: {}, __VLS_3: {
718653
num: number;
719654
}, __VLS_5: {
@@ -762,7 +697,7 @@ type __VLS_WithSlots<T, S> = T & {
762697
"
763698
`;
764699
765-
exports[`vue-tsc-dts > Input: template-slots/component-define-slots.vue, Output: template-slots/component-define-slots.vue.d.ts 1`] = `
700+
exports[`vue-tsc-dts > Input: reference-type-slots/component-define-slots.vue, Output: reference-type-slots/component-define-slots.vue.d.ts 1`] = `
766701
"import type { VNode } from 'vue';
767702
type __VLS_Slots = {
768703
default: (props: {
@@ -808,44 +743,7 @@ type __VLS_WithSlots<T, S> = T & {
808743
"
809744
`;
810745
811-
exports[`vue-tsc-dts > Input: template-slots/component-destructuring.vue, Output: template-slots/component-destructuring.vue.d.ts 1`] = `
812-
"type __VLS_Slots = {
813-
bottom: (props: {
814-
num: number;
815-
}) => any[];
816-
};
817-
declare const __VLS_component: import("vue").DefineComponent2<{
818-
setup(): {};
819-
data(): {};
820-
props: {};
821-
computed: {};
822-
methods: {};
823-
mixins: {}[];
824-
extends: {};
825-
emits: string[];
826-
slots: {};
827-
inject: {};
828-
components: {};
829-
directives: {};
830-
provide: {};
831-
expose: string;
832-
__typeProps: unknown;
833-
__typeEmits: unknown;
834-
__typeRefs: {};
835-
__typeEl: any;
836-
__defaults: unknown;
837-
}>;
838-
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
839-
export default _default;
840-
type __VLS_WithSlots<T, S> = T & {
841-
new (): {
842-
$slots: S;
843-
};
844-
};
845-
"
846-
`;
847-
848-
exports[`vue-tsc-dts > Input: template-slots/component-no-script.vue, Output: template-slots/component-no-script.vue.d.ts 1`] = `
746+
exports[`vue-tsc-dts > Input: reference-type-slots/component-no-script.vue, Output: reference-type-slots/component-no-script.vue.d.ts 1`] = `
849747
"declare var __VLS_1: {}, __VLS_3: {
850748
num: number;
851749
}, __VLS_5: {

test-workspace/component-meta/class-slots/component.vue

Lines changed: 0 additions & 10 deletions
This file was deleted.

test-workspace/component-meta/events/component-class.vue

Lines changed: 0 additions & 6 deletions
This file was deleted.

test-workspace/component-meta/events/component-generic.vue

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { MyEvents } from './my-events';
2+
import type { MyEvents } from './my-events';
33
44
defineEmits<MyEvents>();
55
</script>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* Emitted when the foo property is changed.
33
*/
4-
type MyEventsFoo = /** Emitted when the foo property is changed.*/ 'foo'
4+
type MyEventsFoo = /** Emitted when the foo property is changed.*/ 'foo';
55
export interface MyEvents {
6-
6+
77
(event: MyEventsFoo, data?: { foo: string; }): void;
8-
(event: 'bar', value: { arg1: number, arg2?: any }): void;
8+
(event: 'bar', value: { arg1: number, arg2?: any; }): void;
99
(e: 'baz'): void;
1010
}

test-workspace/component-meta/reference-type-props/my-props.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface MyIgnoredNestedProps {
1010
}
1111

1212
export interface MyNestedRecursiveProps {
13-
recursive: MyNestedRecursiveProps
13+
recursive: MyNestedRecursiveProps;
1414
}
1515

1616
enum MyEnum {
@@ -48,27 +48,27 @@ export interface MyProps {
4848
* </template>
4949
* ```
5050
*/
51-
foo: string,
51+
foo: string;
5252
/**
5353
* optional number bar
5454
*/
55-
bar?: number,
55+
bar?: number;
5656
/**
5757
* string array baz
5858
*/
59-
baz?: string[],
59+
baz?: string[];
6060
/**
6161
* required union type
6262
*/
63-
union: string | number,
63+
union: string | number;
6464
/**
6565
* optional union type
6666
*/
67-
unionOptional?: string | number,
67+
unionOptional?: string | number;
6868
/**
6969
* required nested object
7070
*/
71-
nested: MyNestedProps,
71+
nested: MyNestedProps;
7272
/**
7373
* required nested object with intersection
7474
*/
@@ -77,45 +77,45 @@ export interface MyProps {
7777
* required additional property
7878
*/
7979
additionalProp: string;
80-
},
80+
};
8181
/**
8282
* optional nested object
8383
*/
84-
nestedOptional?: MyNestedProps | MyIgnoredNestedProps,
84+
nestedOptional?: MyNestedProps | MyIgnoredNestedProps;
8585
/**
8686
* required array object
8787
*/
88-
array: MyNestedProps[],
88+
array: MyNestedProps[];
8989
/**
9090
* optional array object
9191
*/
92-
arrayOptional?: MyNestedProps[],
92+
arrayOptional?: MyNestedProps[];
9393
/**
9494
* enum value
9595
*/
96-
enumValue: MyEnum,
96+
enumValue: MyEnum;
9797
/**
9898
* namespace type
9999
*/
100-
namespaceType: MyNamespace.MyType,
100+
namespaceType: MyNamespace.MyType;
101101
/**
102102
* literal type alias that require context
103103
*/
104-
literalFromContext: MyCategories,
105-
inlined: { foo: string; },
106-
recursive: MyNestedRecursiveProps
104+
literalFromContext: MyCategories;
105+
inlined: { foo: string; };
106+
recursive: MyNestedRecursiveProps;
107107
}
108108

109109
export const StringRequired = {
110110
type: String,
111111
required: true,
112-
} as const
112+
} as const;
113113

114114
export const StringEmpty = {
115115
type: String,
116-
value: '',
117-
} as const
116+
default: '',
117+
} as const;
118118

119119
export const StringUndefined = {
120120
type: String,
121-
} as const
121+
} as const;

test-workspace/component-meta/template-slots/component.vue renamed to test-workspace/component-meta/reference-type-slots/component.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,3 @@
44
<slot name="named-slot" str="str"></slot>
55
<slot name="vbind" v-bind="{ num: 123, str: 'str' }"></slot>
66
</template>
7-
8-
<script setup lang="ts">
9-
</script>

test-workspace/component-meta/template-slots/component-destructuring.vue

Lines changed: 0 additions & 13 deletions
This file was deleted.

test-workspace/component-meta/ts-component/PropDefinitions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ export interface MyProps {
22
/**
33
* string foo
44
*/
5-
foo: string,
5+
foo: string;
66
/**
77
* optional number bar
88
*/
9-
bar?: number,
10-
}
9+
bar?: number;
10+
}

test-workspace/component-meta/ts-component/component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { h, defineComponent } from 'vue';
2-
import { MyProps } from './PropDefinitions';
1+
import { defineComponent, h } from 'vue';
2+
import { type MyProps } from './PropDefinitions';
33

44
export default defineComponent((props: MyProps) => {
55
return () => h('pre', JSON.stringify(props, null, 2));

test-workspace/component-meta/ts-component/component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineComponent } from 'vue';
2-
import { MyProps } from './PropDefinitions';
2+
import type { MyProps } from './PropDefinitions';
33

44
export default defineComponent((props: MyProps) => {
55
return () => <pre>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineComponent } from 'vue';
22

3-
export const Foo = defineComponent((_: { foo: string; }) => ()=> { });
3+
export const Foo = defineComponent((_: { foo: string; }) => () => { });
44

5-
export const Bar = defineComponent((_: { bar?: number; }) => ()=> { });
5+
export const Bar = defineComponent((_: { bar?: number; }) => () => { });

0 commit comments

Comments
 (0)