From fa090b4ce3f3b07173df3d040fd0b9363bc0d68d Mon Sep 17 00:00:00 2001 From: Nogic <24802730+nogic1008@users.noreply.github.com> Date: Tue, 7 Feb 2023 13:26:22 +0900 Subject: [PATCH] refactor: use @vue/test-utils flushPromises & refactor type definitions (#740) * refactor(test): use @vue/test-utils flushPromises * refactor: reduce any uses * refactor: move type definition --- __tests__/content/series.test.ts | 3 ++- __tests__/content/songs.test.ts | 2 +- __tests__/pages/songs/index.test.ts | 2 +- __tests__/test-utils.ts | 25 ++++++++++++++----------- components/content/Charts.vue | 2 +- components/content/SeriesList.vue | 2 +- composables/useSoftwareData.ts | 25 +++++++++++++++++++++---- composables/useSoftwareList.ts | 13 +++++++++---- composables/useSongData.ts | 14 +++++++++++--- composables/useSongList.ts | 9 ++++++--- package.json | 1 - pages/songs/index.vue | 3 +-- src/content.ts | 28 ---------------------------- yarn.lock | 5 ----- 14 files changed, 68 insertions(+), 66 deletions(-) delete mode 100644 src/content.ts diff --git a/__tests__/content/series.test.ts b/__tests__/content/series.test.ts index b45c0468a..834231c99 100644 --- a/__tests__/content/series.test.ts +++ b/__tests__/content/series.test.ts @@ -5,8 +5,9 @@ import { basename } from 'node:path' import { load } from 'js-yaml' import { describe, expect, test } from 'vitest' +import type { Software } from '~~/composables/useSoftwareData' +import { platforms, regionList } from '~~/composables/useSoftwareData' import seriesList from '~~/content/series/.seriesList.json' -import { platforms, regionList, Software } from '~~/src/content' const dirpath = './content/series' diff --git a/__tests__/content/songs.test.ts b/__tests__/content/songs.test.ts index 6fcba0305..9763db10a 100644 --- a/__tests__/content/songs.test.ts +++ b/__tests__/content/songs.test.ts @@ -5,8 +5,8 @@ import { basename } from 'node:path' import { load } from 'js-yaml' import { describe, expect, test } from 'vitest' +import type { Song } from '~~/composables/useSongData' import seriesList from '~~/content/series/.seriesList.json' -import { Song } from '~~/src/content' const dirpath = './content/songs' diff --git a/__tests__/pages/songs/index.test.ts b/__tests__/pages/songs/index.test.ts index 61ce545e9..758cf2957 100644 --- a/__tests__/pages/songs/index.test.ts +++ b/__tests__/pages/songs/index.test.ts @@ -25,7 +25,7 @@ describe('pages/songs/index.vue', () => { bpm: 180, series: ['1st-jp', '2nd'] } - ] + ] as Awaited>['songs']['value'] const global = { plugins, stubs: { NuxtLink: RouterLinkStub, Series: true } } beforeEach(() => { diff --git a/__tests__/test-utils.ts b/__tests__/test-utils.ts index be67823b8..af2e1125d 100644 --- a/__tests__/test-utils.ts +++ b/__tests__/test-utils.ts @@ -1,17 +1,14 @@ import Oruga from '@oruga-ui/oruga-next' import { bulmaConfig } from '@oruga-ui/theme-bulma' -import { mount } from '@vue/test-utils' -import flushPromises from 'flush-promises' +import { flushPromises, mount } from '@vue/test-utils' import type { DefineComponent, Plugin } from 'vue' import { defineComponent, h, Suspense } from 'vue' -import type { SoftwareParsedContent } from '~~/composables/useSoftwareData' -import type { SoftwareListData } from '~~/composables/useSoftwareList' -import type { SongParsedContent } from '~~/composables/useSongData' - -export const plugins: (Plugin | [Plugin, ...any[]])[] = [[Oruga, bulmaConfig]] +export const plugins: (Plugin | [Plugin, ...unknown[]])[] = [ + [Oruga, bulmaConfig] +] -export const mountAsync = async >( +export const mountAsync = async >( component: T, options: Parameters>[1] ) => { @@ -33,7 +30,9 @@ export const mountAsync = async >( return wrapper } -export const mockSoftware: SoftwareParsedContent = { +export const mockSoftware: Awaited< + ReturnType +>['software']['value'] = { slug: '1st-jp', title: 'Dance Dance Revolution', platform: 'Play Station', @@ -49,7 +48,9 @@ export const mockSoftware: SoftwareParsedContent = { _id: 'content:series:1st-jp.md' } -export const mockSoftwareList: SoftwareListData[] = [ +export const mockSoftwareList: Awaited< + ReturnType +>['softwareList']['value'] = [ { slug: '1st-jp', title: 'Dance Dance Revolution', @@ -66,7 +67,9 @@ export const mockSoftwareList: SoftwareListData[] = [ } ] -export const mockSong: SongParsedContent = { +export const mockSong: Awaited< + ReturnType +>['song']['value'] = { slug: 'butterfly', name: 'butterfly', artist: 'smile. dk', diff --git a/components/content/Charts.vue b/components/content/Charts.vue index 96ceeeb58..87c60c38f 100644 --- a/components/content/Charts.vue +++ b/components/content/Charts.vue @@ -13,7 +13,7 @@