From 746e8882158ca6eab319505ea4f5899d3e7157e5 Mon Sep 17 00:00:00 2001 From: Nogic <24802730+nogic1008@users.noreply.github.com> Date: Tue, 7 Feb 2023 12:00:41 +0900 Subject: [PATCH 1/3] refactor(test): use @vue/test-utils flushPromises --- __tests__/test-utils.ts | 3 +-- package.json | 1 - yarn.lock | 5 ----- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/__tests__/test-utils.ts b/__tests__/test-utils.ts index be67823b8..1a2aa379c 100644 --- a/__tests__/test-utils.ts +++ b/__tests__/test-utils.ts @@ -1,7 +1,6 @@ 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 { mount, flushPromises } from '@vue/test-utils' import type { DefineComponent, Plugin } from 'vue' import { defineComponent, h, Suspense } from 'vue' diff --git a/package.json b/package.json index 6ea702654..b220301b9 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "eslint-config-prettier": "^8.6.0", "eslint-plugin-nuxt": "^4.0.0", "eslint-plugin-simple-import-sort": "^10.0.0", - "flush-promises": "^1.0.2", "js-yaml": "^4.1.0", "jsdom": "^21.1.0", "npm-run-all2": "^6.0.4", diff --git a/yarn.lock b/yarn.lock index 9f955dfe4..e3cb25b9b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2894,11 +2894,6 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787" integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ== -flush-promises@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/flush-promises/-/flush-promises-1.0.2.tgz#4948fd58f15281fed79cbafc86293d5bb09b2ced" - integrity sha512-G0sYfLQERwKz4+4iOZYQEZVpOt9zQrlItIxQAAYAWpfby3gbHrx0osCHz5RLl/XoXevXk0xoN4hDFky/VV9TrA== - follow-redirects@^1.0.0: version "1.15.2" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" From 04cb5ec0a803d1d09c5e73dcf9cb25b628dd8eb3 Mon Sep 17 00:00:00 2001 From: Nogic <24802730+nogic1008@users.noreply.github.com> Date: Tue, 7 Feb 2023 03:16:40 +0000 Subject: [PATCH 2/3] refactor: reduce any uses --- __tests__/pages/songs/index.test.ts | 3 ++- __tests__/test-utils.ts | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/__tests__/pages/songs/index.test.ts b/__tests__/pages/songs/index.test.ts index 61ce545e9..8e1c3f762 100644 --- a/__tests__/pages/songs/index.test.ts +++ b/__tests__/pages/songs/index.test.ts @@ -4,6 +4,7 @@ import { ref } from 'vue' import useSongList from '~~/composables/useSongList' import SongList from '~~/pages/songs/index.vue' +import { Song } from '~~/src/content' import { mountAsync, plugins } from '../../test-utils' @@ -25,7 +26,7 @@ describe('pages/songs/index.vue', () => { bpm: 180, series: ['1st-jp', '2nd'] } - ] + ] as Song[] const global = { plugins, stubs: { NuxtLink: RouterLinkStub, Series: true } } beforeEach(() => { diff --git a/__tests__/test-utils.ts b/__tests__/test-utils.ts index 1a2aa379c..1e62d5c1a 100644 --- a/__tests__/test-utils.ts +++ b/__tests__/test-utils.ts @@ -1,6 +1,6 @@ import Oruga from '@oruga-ui/oruga-next' import { bulmaConfig } from '@oruga-ui/theme-bulma' -import { mount, flushPromises } from '@vue/test-utils' +import { flushPromises, mount } from '@vue/test-utils' import type { DefineComponent, Plugin } from 'vue' import { defineComponent, h, Suspense } from 'vue' @@ -8,9 +8,11 @@ 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] ) => { From 4723e1a4960604f820fab8ae87dd1e5a4fc7cf6d Mon Sep 17 00:00:00 2001 From: Nogic <24802730+nogic1008@users.noreply.github.com> Date: Tue, 7 Feb 2023 04:20:55 +0000 Subject: [PATCH 3/3] refactor: move type definition --- __tests__/content/series.test.ts | 3 ++- __tests__/content/songs.test.ts | 2 +- __tests__/pages/songs/index.test.ts | 3 +-- __tests__/test-utils.ts | 16 +++++++++------- 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 ++++++--- pages/songs/index.vue | 3 +-- src/content.ts | 28 ---------------------------- 12 files changed, 63 insertions(+), 57 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 8e1c3f762..758cf2957 100644 --- a/__tests__/pages/songs/index.test.ts +++ b/__tests__/pages/songs/index.test.ts @@ -4,7 +4,6 @@ import { ref } from 'vue' import useSongList from '~~/composables/useSongList' import SongList from '~~/pages/songs/index.vue' -import { Song } from '~~/src/content' import { mountAsync, plugins } from '../../test-utils' @@ -26,7 +25,7 @@ describe('pages/songs/index.vue', () => { bpm: 180, series: ['1st-jp', '2nd'] } - ] as Song[] + ] 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 1e62d5c1a..af2e1125d 100644 --- a/__tests__/test-utils.ts +++ b/__tests__/test-utils.ts @@ -4,10 +4,6 @@ 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, ...unknown[]])[] = [ [Oruga, bulmaConfig] ] @@ -34,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', @@ -50,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', @@ -67,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 @@