Skip to content

test: add inline snapshots for runtime/ transforms #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ export default createConfigForNuxt({
'./example/playground',
],
},
}).append({
ignores: ['test/__snapshots__/*'],
})
18 changes: 18 additions & 0 deletions example/src/runtime/components/TestMe.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
props: {
count: {
type: Number,
required: true,
},
},
})
</script>

<template>
<div>
{{ count }}
</div>
</template>
7 changes: 7 additions & 0 deletions example/src/runtime/composables/useWrappedFetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// TODO: investigate how to avoid the need for this import
import type {} from 'ofetch'
import { useFetch } from '#app'

export const useWrappedFetch = () => {
return useFetch('/api/applications')
}
17 changes: 17 additions & 0 deletions test/__snapshots__/TestMe.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script>
import { defineComponent } from "vue";
export default defineComponent({
props: {
count: {
type: Number,
required: true
}
}
});
</script>

<template>
<div>
{{ count }}
</div>
</template>
6 changes: 6 additions & 0 deletions test/__snapshots__/plugin.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare const _default: import("#app").Plugin<{
injection: "injected";
}> & import("#app").ObjectPlugin<{
injection: "injected";
}>;
export default _default;
1 change: 1 addition & 0 deletions test/__snapshots__/useWrappedFetch.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const useWrappedFetch: () => import("#app").AsyncData<unknown, import("ofetch").FetchError<any> | null>;
21 changes: 12 additions & 9 deletions test/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,17 @@ describe('module builder', () => {

it('should generate typed plugin', async () => {
const pluginDts = await readFile(join(distDir, 'runtime/plugins/plugin.d.ts'), 'utf-8')
expect(pluginDts).toMatchInlineSnapshot(`
"declare const _default: import("#app").Plugin<{
injection: "injected";
}> & import("#app").ObjectPlugin<{
injection: "injected";
}>;
export default _default;
"
`)
expect(pluginDts).toMatchFileSnapshot('__snapshots__/plugin.d.ts')
})

// TODO: https://github.com/nuxt/module-builder/issues/239
it('should generate components correctly', async () => {
const componentFile = await readFile(join(distDir, 'runtime/components/TestMe.vue'), 'utf-8')
expect(componentFile).toMatchFileSnapshot('__snapshots__/TestMe.vue')
})

it('should generate wrapped composables', async () => {
const componentFile = await readFile(join(distDir, 'runtime/composables/useWrappedFetch.d.ts'), 'utf-8')
expect(componentFile).toMatchFileSnapshot('__snapshots__/useWrappedFetch.d.ts')
})
})