Skip to content

Commit ce330d8

Browse files
authored
test: assert current vue snapshot behaviour (#444)
1 parent 8228be5 commit ce330d8

File tree

4 files changed

+345
-1
lines changed

4 files changed

+345
-1
lines changed

Diff for: example/src/runtime/components/TestMeSetup.vue

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script setup lang="ts">
2+
defineProps<{ count: number }>()
3+
</script>
4+
5+
<template>
6+
<div>
7+
{{ count }}
8+
</div>
9+
</template>

Diff for: test/__snapshots__/TestMe.vue.d.ts

+315
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
2+
count: {
3+
type: NumberConstructor;
4+
required: true;
5+
};
6+
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
7+
count: {
8+
type: NumberConstructor;
9+
required: true;
10+
};
11+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
12+
export default _default;
13+
declare module 'vue' {
14+
interface GlobalComponents {
15+
}
16+
interface GlobalDirectives {
17+
}
18+
}
19+
declare global {
20+
const __VLS_intrinsicElements: __VLS_IntrinsicElements;
21+
const __VLS_directiveBindingRestFields: {
22+
instance: null;
23+
oldValue: null;
24+
modifiers: any;
25+
dir: any;
26+
};
27+
const __VLS_unref: typeof import('vue').unref;
28+
const __VLS_nativeElements: {
29+
a: HTMLAnchorElement;
30+
abbr: HTMLElement;
31+
address: HTMLElement;
32+
area: HTMLAreaElement;
33+
article: HTMLElement;
34+
aside: HTMLElement;
35+
audio: HTMLAudioElement;
36+
b: HTMLElement;
37+
base: HTMLBaseElement;
38+
bdi: HTMLElement;
39+
bdo: HTMLElement;
40+
blockquote: HTMLQuoteElement;
41+
body: HTMLBodyElement;
42+
br: HTMLBRElement;
43+
button: HTMLButtonElement;
44+
canvas: HTMLCanvasElement;
45+
caption: HTMLTableCaptionElement;
46+
cite: HTMLElement;
47+
code: HTMLElement;
48+
col: HTMLTableColElement;
49+
colgroup: HTMLTableColElement;
50+
data: HTMLDataElement;
51+
datalist: HTMLDataListElement;
52+
dd: HTMLElement;
53+
del: HTMLModElement;
54+
details: HTMLDetailsElement;
55+
dfn: HTMLElement;
56+
dialog: HTMLDialogElement;
57+
div: HTMLDivElement;
58+
dl: HTMLDListElement;
59+
dt: HTMLElement;
60+
em: HTMLElement;
61+
embed: HTMLEmbedElement;
62+
fieldset: HTMLFieldSetElement;
63+
figcaption: HTMLElement;
64+
figure: HTMLElement;
65+
footer: HTMLElement;
66+
form: HTMLFormElement;
67+
h1: HTMLHeadingElement;
68+
h2: HTMLHeadingElement;
69+
h3: HTMLHeadingElement;
70+
h4: HTMLHeadingElement;
71+
h5: HTMLHeadingElement;
72+
h6: HTMLHeadingElement;
73+
head: HTMLHeadElement;
74+
header: HTMLElement;
75+
hgroup: HTMLElement;
76+
hr: HTMLHRElement;
77+
html: HTMLHtmlElement;
78+
i: HTMLElement;
79+
iframe: HTMLIFrameElement;
80+
img: HTMLImageElement;
81+
input: HTMLInputElement;
82+
ins: HTMLModElement;
83+
kbd: HTMLElement;
84+
label: HTMLLabelElement;
85+
legend: HTMLLegendElement;
86+
li: HTMLLIElement;
87+
link: HTMLLinkElement;
88+
main: HTMLElement;
89+
map: HTMLMapElement;
90+
mark: HTMLElement;
91+
menu: HTMLMenuElement;
92+
meta: HTMLMetaElement;
93+
meter: HTMLMeterElement;
94+
nav: HTMLElement;
95+
noscript: HTMLElement;
96+
object: HTMLObjectElement;
97+
ol: HTMLOListElement;
98+
optgroup: HTMLOptGroupElement;
99+
option: HTMLOptionElement;
100+
output: HTMLOutputElement;
101+
p: HTMLParagraphElement;
102+
picture: HTMLPictureElement;
103+
pre: HTMLPreElement;
104+
progress: HTMLProgressElement;
105+
q: HTMLQuoteElement;
106+
rp: HTMLElement;
107+
rt: HTMLElement;
108+
ruby: HTMLElement;
109+
s: HTMLElement;
110+
samp: HTMLElement;
111+
script: HTMLScriptElement;
112+
search: HTMLElement;
113+
section: HTMLElement;
114+
select: HTMLSelectElement;
115+
slot: HTMLSlotElement;
116+
small: HTMLElement;
117+
source: HTMLSourceElement;
118+
span: HTMLSpanElement;
119+
strong: HTMLElement;
120+
style: HTMLStyleElement;
121+
sub: HTMLElement;
122+
summary: HTMLElement;
123+
sup: HTMLElement;
124+
table: HTMLTableElement;
125+
tbody: HTMLTableSectionElement;
126+
td: HTMLTableCellElement;
127+
template: HTMLTemplateElement;
128+
textarea: HTMLTextAreaElement;
129+
tfoot: HTMLTableSectionElement;
130+
th: HTMLTableCellElement;
131+
thead: HTMLTableSectionElement;
132+
time: HTMLTimeElement;
133+
title: HTMLTitleElement;
134+
tr: HTMLTableRowElement;
135+
track: HTMLTrackElement;
136+
u: HTMLElement;
137+
ul: HTMLUListElement;
138+
var: HTMLElement;
139+
video: HTMLVideoElement;
140+
wbr: HTMLElement;
141+
animate: SVGAnimateElement;
142+
animateMotion: SVGAnimateMotionElement;
143+
animateTransform: SVGAnimateTransformElement;
144+
circle: SVGCircleElement;
145+
clipPath: SVGClipPathElement;
146+
defs: SVGDefsElement;
147+
desc: SVGDescElement;
148+
ellipse: SVGEllipseElement;
149+
feBlend: SVGFEBlendElement;
150+
feColorMatrix: SVGFEColorMatrixElement;
151+
feComponentTransfer: SVGFEComponentTransferElement;
152+
feComposite: SVGFECompositeElement;
153+
feConvolveMatrix: SVGFEConvolveMatrixElement;
154+
feDiffuseLighting: SVGFEDiffuseLightingElement;
155+
feDisplacementMap: SVGFEDisplacementMapElement;
156+
feDistantLight: SVGFEDistantLightElement;
157+
feDropShadow: SVGFEDropShadowElement;
158+
feFlood: SVGFEFloodElement;
159+
feFuncA: SVGFEFuncAElement;
160+
feFuncB: SVGFEFuncBElement;
161+
feFuncG: SVGFEFuncGElement;
162+
feFuncR: SVGFEFuncRElement;
163+
feGaussianBlur: SVGFEGaussianBlurElement;
164+
feImage: SVGFEImageElement;
165+
feMerge: SVGFEMergeElement;
166+
feMergeNode: SVGFEMergeNodeElement;
167+
feMorphology: SVGFEMorphologyElement;
168+
feOffset: SVGFEOffsetElement;
169+
fePointLight: SVGFEPointLightElement;
170+
feSpecularLighting: SVGFESpecularLightingElement;
171+
feSpotLight: SVGFESpotLightElement;
172+
feTile: SVGFETileElement;
173+
feTurbulence: SVGFETurbulenceElement;
174+
filter: SVGFilterElement;
175+
foreignObject: SVGForeignObjectElement;
176+
g: SVGGElement;
177+
image: SVGImageElement;
178+
line: SVGLineElement;
179+
linearGradient: SVGLinearGradientElement;
180+
marker: SVGMarkerElement;
181+
mask: SVGMaskElement;
182+
metadata: SVGMetadataElement;
183+
mpath: SVGMPathElement;
184+
path: SVGPathElement;
185+
pattern: SVGPatternElement;
186+
polygon: SVGPolygonElement;
187+
polyline: SVGPolylineElement;
188+
radialGradient: SVGRadialGradientElement;
189+
rect: SVGRectElement;
190+
set: SVGSetElement;
191+
stop: SVGStopElement;
192+
svg: SVGSVGElement;
193+
switch: SVGSwitchElement;
194+
symbol: SVGSymbolElement;
195+
text: SVGTextElement;
196+
textPath: SVGTextPathElement;
197+
tspan: SVGTSpanElement;
198+
use: SVGUseElement;
199+
view: SVGViewElement;
200+
};
201+
type __VLS_IntrinsicElements = import('vue/jsx-runtime').JSX.IntrinsicElements;
202+
type __VLS_Element = import('vue/jsx-runtime').JSX.Element;
203+
type __VLS_GlobalComponents = import('vue').GlobalComponents & Pick<typeof import('vue'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;
204+
type __VLS_GlobalDirectives = import('vue').GlobalDirectives;
205+
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
206+
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
207+
type __VLS_unknownDirective = (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
208+
type __VLS_WithComponent<N0 extends string, LocalComponents, N1 extends string, N2 extends string, N3 extends string> = N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : {
209+
[K in N0]: LocalComponents[N1];
210+
} : N2 extends keyof LocalComponents ? N2 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : {
211+
[K in N0]: LocalComponents[N2];
212+
} : N3 extends keyof LocalComponents ? N3 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : {
213+
[K in N0]: LocalComponents[N3];
214+
} : N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : {
215+
[K in N0]: __VLS_GlobalComponents[N1];
216+
} : N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : {
217+
[K in N0]: __VLS_GlobalComponents[N2];
218+
} : N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : {
219+
[K in N0]: __VLS_GlobalComponents[N3];
220+
} : {
221+
[K in N0]: unknown;
222+
};
223+
type __VLS_FunctionalComponentProps<T, K> = '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends {
224+
__ctx?: {
225+
props?: infer P;
226+
};
227+
} ? NonNullable<P> : never : T extends (props: infer P, ...args: any) => any ? P : {};
228+
type __VLS_IsFunction<T, K> = K extends keyof T ? __VLS_IsAny<T[K]> extends false ? unknown extends T[K] ? false : true : false : false;
229+
type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
230+
type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R ? U extends T ? never : __VLS_OverloadUnionInner<T, Pick<T, keyof T> & U & ((...args: A) => R)> | ((...args: A) => R) : never;
231+
type __VLS_OverloadUnion<T> = Exclude<__VLS_OverloadUnionInner<(() => never) & T>, T extends () => never ? never : () => never>;
232+
type __VLS_ConstructorOverloads<T> = __VLS_OverloadUnion<T> extends infer F ? F extends (event: infer E, ...args: infer A) => any ? {
233+
[K in E & string]: (...args: A) => void;
234+
} : never : never;
235+
type __VLS_NormalizeEmits<T> = __VLS_PrettifyGlobal<__VLS_UnionToIntersection<__VLS_ConstructorOverloads<T> & {
236+
[K in keyof T]: T[K] extends any[] ? {
237+
(...args: T[K]): void;
238+
} : never;
239+
}>>;
240+
type __VLS_PrettifyGlobal<T> = {
241+
[K in keyof T]: T[K];
242+
} & {};
243+
type __VLS_PickFunctionalComponentCtx<T, K> = NonNullable<__VLS_PickNotAny<'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends {
244+
__ctx?: infer Ctx;
245+
} ? Ctx : never : any, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any>>;
246+
type __VLS_UseTemplateRef<T> = Readonly<import('vue').ShallowRef<T | null>>;
247+
function __VLS_getVForSourceType(source: number): [number, number, number][];
248+
function __VLS_getVForSourceType(source: string): [string, number, number][];
249+
function __VLS_getVForSourceType<T extends any[]>(source: T): [
250+
item: T[number],
251+
key: number,
252+
index: number
253+
][];
254+
function __VLS_getVForSourceType<T extends {
255+
[Symbol.iterator](): Iterator<any>;
256+
}>(source: T): [
257+
item: T extends {
258+
[Symbol.iterator](): Iterator<infer T1>;
259+
} ? T1 : never,
260+
key: number,
261+
index: undefined
262+
][];
263+
function __VLS_getVForSourceType<T extends number | {
264+
[Symbol.iterator](): Iterator<any>;
265+
}>(source: T): [
266+
item: number | (Exclude<T, number> extends {
267+
[Symbol.iterator](): Iterator<infer T1>;
268+
} ? T1 : never),
269+
key: number,
270+
index: undefined
271+
][];
272+
function __VLS_getVForSourceType<T>(source: T): [
273+
item: T[keyof T],
274+
key: keyof T,
275+
index: number
276+
][];
277+
function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
278+
function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
279+
function __VLS_asFunctionalDirective<T>(dir: T): T extends import('vue').ObjectDirective ? NonNullable<T['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']> : T extends (...args: any) => any ? T : __VLS_unknownDirective;
280+
function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
281+
function __VLS_makeOptional<T>(t: T): {
282+
[K in keyof T]?: T[K];
283+
};
284+
function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
285+
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K): T extends new (...args: any) => any ? (props: (K extends {
286+
$props: infer Props;
287+
} ? Props : any) & Record<string, unknown>, ctx?: any) => __VLS_Element & {
288+
__ctx?: {
289+
attrs?: any;
290+
slots?: K extends {
291+
$slots: infer Slots;
292+
} ? Slots : any;
293+
emit?: K extends {
294+
$emit: infer Emit;
295+
} ? Emit : any;
296+
} & {
297+
props?: (K extends {
298+
$props: infer Props;
299+
} ? Props : any) & Record<string, unknown>;
300+
expose?(exposed: K): void;
301+
};
302+
} : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T> : T extends (...args: any) => any ? T : (_: {} & Record<string, unknown>, ctx?: any) => {
303+
__ctx?: {
304+
attrs?: any;
305+
expose?: any;
306+
slots?: any;
307+
emit?: any;
308+
props?: {} & Record<string, unknown>;
309+
};
310+
};
311+
function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T & Record<string, unknown>) => void;
312+
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
313+
function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
314+
function __VLS_tryAsConstant<const T>(t: T): T;
315+
}

Diff for: test/__snapshots__/TestMeSetup.vue

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script setup lang="ts">
2+
defineProps<{ count: number }>()
3+
</script>
4+
5+
<template>
6+
<div>
7+
{{ count }}
8+
</div>
9+
</template>

Diff for: test/build.spec.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,21 @@ describe('module builder', () => {
127127
expect(runtimeImport!.code.trim()).toMatchInlineSnapshot(`"import { SharedTypeFromRuntime } from '../dist/runtime/plugins/plugin.js';"`)
128128
})
129129

130-
// TODO: https://github.com/nuxt/module-builder/issues/239
131130
it('should generate components correctly', async () => {
132131
const componentFile = await readFile(join(distDir, 'runtime/components/TestMe.vue'), 'utf-8')
133132
await expect(componentFile.replace(/\r\n/g, '\n')).toMatchFileSnapshot('__snapshots__/TestMe.vue')
133+
134+
const componentDeclarationFile = await readFile(join(distDir, 'runtime/components/TestMe.vue.d.ts'), 'utf-8')
135+
await expect(componentDeclarationFile.replace(/\r\n/g, '\n')).toMatchFileSnapshot('__snapshots__/TestMe.vue.d.ts')
136+
})
137+
138+
it('should generate components with <script setup> correctly', async () => {
139+
const componentFile = await readFile(join(distDir, 'runtime/components/TestMeSetup.vue'), 'utf-8')
140+
await expect(componentFile.replace(/\r\n/g, '\n')).toMatchFileSnapshot('__snapshots__/TestMeSetup.vue')
141+
142+
// TODO: https://github.com/nuxt/module-builder/issues/239
143+
// const componentDeclarationFile = await readFile(join(distDir, 'runtime/components/TestMeSetup.vue.d.ts'), 'utf-8')
144+
// await expect(componentDeclarationFile.replace(/\r\n/g, '\n')).toMatchFileSnapshot('__snapshots__/TestMeSetup.vue.d.ts')
134145
})
135146

136147
it('should generate wrapped composables', async () => {

0 commit comments

Comments
 (0)