diff --git a/packages/frontend/package.json b/packages/frontend/package.json index b5d69fd445..569b59fcf7 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -10,8 +10,8 @@ "build-storybook-pre": "(tsc -p .storybook || echo done.) && node .storybook/generate.js && node .storybook/preload-locale.js && node .storybook/preload-theme.js", "build-storybook": "pnpm build-storybook-pre && storybook build --webpack-stats-json storybook-static", "chromatic": "chromatic", - "test": "vitest --run --globals", - "test-and-coverage": "vitest --run --coverage --globals", + "test": "node scripts/vitest.mjs --run --globals", + "test-and-coverage": "node scripts/vitest.mjs --run --coverage --globals", "typecheck-all": "pnpm run --no-bail typecheck:vue && pnpm run --no-bail typecheck:test && pnpm run --no-bail typecheck:scripts && pnpm run --no-bail typecheck:storybook", "typecheck": "pnpm run typecheck:vue && pnpm run typecheck:test && pnpm run typecheck:scripts && pnpm run typecheck:storybook", "typecheck:vue": "vue-tsc -p tsconfig.vue.json --noEmit", diff --git a/packages/frontend/scripts/vitest.mjs b/packages/frontend/scripts/vitest.mjs new file mode 100644 index 0000000000..33d32943f3 --- /dev/null +++ b/packages/frontend/scripts/vitest.mjs @@ -0,0 +1,33 @@ +/** + * Hot-swaps tsconfig files to work around vite limitations. + * Based on idea from https://github.com/vitejs/vite/discussions/8483#discussioncomment-6830634 + */ + +import nodeFs from 'node:fs/promises'; +import nodePath from 'node:path'; +import { execa } from 'execa'; + +const rootDir = nodePath.resolve(import.meta.dirname, '../'); +const tsConfig = nodePath.resolve(rootDir, 'tsconfig.json'); +const tsConfigBak = nodePath.resolve(rootDir, 'tsconfig.json.bak'); +const tsConfigVue = nodePath.resolve(rootDir, 'tsconfig.vue.json'); + +console.log('Staging tsconfig.vue.json as tsconfig.json...'); +await nodeFs.rename(tsConfig, tsConfigBak); +await nodeFs.copyFile(tsConfigVue, tsConfig); + +try { + console.log('Starting vitest...'); + await execa( + 'vitest', + process.argv.slice(2), + { + stdout: process.stdout, + stderr: process.stderr, + }, + ); +} finally { + console.log('Restoring original tsconfig.json...'); + await nodeFs.rm(tsConfig); + await nodeFs.rename(tsConfigBak, tsConfig); +} diff --git a/packages/frontend/test/note.test.ts b/packages/frontend/test/note.test.ts index d971098419..4926821290 100644 --- a/packages/frontend/test/note.test.ts +++ b/packages/frontend/test/note.test.ts @@ -30,7 +30,7 @@ describe('MkMediaImage', () => { comment: null, properties: {}, ...image, - } as DriveFile, + } as Misskey.entities.DriveFile, }, global: { directives, components }, }); diff --git a/packages/frontend/test/tsconfig.json b/packages/frontend/test/tsconfig.json index 360277e3a6..4e79dd82ac 100644 --- a/packages/frontend/test/tsconfig.json +++ b/packages/frontend/test/tsconfig.json @@ -4,17 +4,28 @@ "compilerOptions": { "module": "NodeNext", "moduleResolution": "NodeNext", - "baseUrl": "./", + "rootDir": "../", "paths": { - "@/*": ["../src/*"] + "@/*": ["../src/*"], + "@@/*": ["../../frontend-shared/*"] }, "typeRoots": [ - "../node_modules/@types" + "../@types", + "../node_modules/@types", + "../node_modules/@vue-macros", + "../node_modules" ], "types": ["node"] }, "include": [ + "../lib/**/*.ts", + "../src/**/*.ts", + "../src/**/*.vue", + "../@types/**/*.ts", "./**/*.ts", - "../src/**/*.vue" + ], + "exclude": [ + "node_modules", + "../.storybook/**/*" ] }