Skip to content

Commit f9f7dfd

Browse files
authored
test: add inline snapshots for runtime/ transforms (#257)
1 parent ecc2230 commit f9f7dfd

File tree

7 files changed

+63
-9
lines changed

7 files changed

+63
-9
lines changed

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ export default createConfigForNuxt({
1212
'./example/playground',
1313
],
1414
},
15+
}).append({
16+
ignores: ['test/__snapshots__/*'],
1517
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script lang="ts">
2+
import { defineComponent } from 'vue'
3+
4+
export default defineComponent({
5+
props: {
6+
count: {
7+
type: Number,
8+
required: true,
9+
},
10+
},
11+
})
12+
</script>
13+
14+
<template>
15+
<div>
16+
{{ count }}
17+
</div>
18+
</template>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// TODO: investigate how to avoid the need for this import
2+
import type {} from 'ofetch'
3+
import { useFetch } from '#app'
4+
5+
export const useWrappedFetch = () => {
6+
return useFetch('/api/applications')
7+
}

test/__snapshots__/TestMe.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script>
2+
import { defineComponent } from "vue";
3+
export default defineComponent({
4+
props: {
5+
count: {
6+
type: Number,
7+
required: true
8+
}
9+
}
10+
});
11+
</script>
12+
13+
<template>
14+
<div>
15+
{{ count }}
16+
</div>
17+
</template>

test/__snapshots__/plugin.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare const _default: import("#app").Plugin<{
2+
injection: "injected";
3+
}> & import("#app").ObjectPlugin<{
4+
injection: "injected";
5+
}>;
6+
export default _default;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export declare const useWrappedFetch: () => import("#app").AsyncData<unknown, import("ofetch").FetchError<any> | null>;

test/build.spec.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,17 @@ describe('module builder', () => {
8686

8787
it('should generate typed plugin', async () => {
8888
const pluginDts = await readFile(join(distDir, 'runtime/plugins/plugin.d.ts'), 'utf-8')
89-
expect(pluginDts).toMatchInlineSnapshot(`
90-
"declare const _default: import("#app").Plugin<{
91-
injection: "injected";
92-
}> & import("#app").ObjectPlugin<{
93-
injection: "injected";
94-
}>;
95-
export default _default;
96-
"
97-
`)
89+
expect(pluginDts).toMatchFileSnapshot('__snapshots__/plugin.d.ts')
90+
})
91+
92+
// TODO: https://github.com/nuxt/module-builder/issues/239
93+
it('should generate components correctly', async () => {
94+
const componentFile = await readFile(join(distDir, 'runtime/components/TestMe.vue'), 'utf-8')
95+
expect(componentFile).toMatchFileSnapshot('__snapshots__/TestMe.vue')
96+
})
97+
98+
it('should generate wrapped composables', async () => {
99+
const componentFile = await readFile(join(distDir, 'runtime/composables/useWrappedFetch.d.ts'), 'utf-8')
100+
expect(componentFile).toMatchFileSnapshot('__snapshots__/useWrappedFetch.d.ts')
98101
})
99102
})

0 commit comments

Comments
 (0)