diff --git a/CHANGELOG.md b/CHANGELOG.md index 9df0ab3..ca8a1fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ +# Changelog + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +## [4.0.0](https://github.com/victorgarciaesgi/nuxt-typed-router/compare/v3.5.0...v4.0.0) (2023-12-07) + +New features + +- `ignoreRoutes` option now support Globs pattern + +Fixs + +- Fixed strict:true errors when using `router.push('xxx')` +- Fixed import of `NuxtLocaleRoute` + + + + Changelog All notable changes to this project will be documented in this file. diff --git a/docs/content/3.options/4.ignoreRoutes.md b/docs/content/3.options/4.ignoreRoutes.md index a07f996..e30df84 100644 --- a/docs/content/3.options/4.ignoreRoutes.md +++ b/docs/content/3.options/4.ignoreRoutes.md @@ -5,12 +5,13 @@ title: ignoreRoutes # ignoreRoutes Allow to ignore selected files to be typed, for exemple 404 routes or catch-all routes. -You can pass an array of file paths (taking base of your `pagesDir`). +You can pass an array of file paths or glob patterns (taking base of your `pagesDir`). + Usage: ```ts -ignoreRoutes: ["[...404].vue", "admin/[...slug].vue"]; +ignoreRoutes: ["[...404].vue", "admin/[...slug].vue", "ignored/**/*"]; ``` ## Type diff --git a/docs/package.json b/docs/package.json index b567f44..383761b 100755 --- a/docs/package.json +++ b/docs/package.json @@ -9,7 +9,7 @@ "preview": "nuxi preview" }, "devDependencies": { - "@nuxt-themes/docus": "1.14.3", - "nuxt": "3.8.1" + "@nuxt-themes/docus": "1.15.0", + "nuxt": "3.10.1" } } diff --git a/package.json b/package.json index ee8b400..16ed819 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "nuxt-typed-router", - "version": "3.5.1", - "description": "Provide autocompletion for routes paths, names and params in Nuxt apps", + "version": "4.0.0", + "description": "Provide a type safe router to Nuxt", "type": "module", - "main": "./dist/module.cjs", + "main": "./dist/module.mjs", "types": "./dist/types.d.ts", "exports": { ".": { @@ -15,23 +15,24 @@ "dist" ], "scripts": { - "prepack": "nuxt-module-build build", + "build": "nuxt-module-build build", + "prepack": "pnpm run typecheck && pnpm build", "dev": "nuxi dev playground", "dev:build": "nuxi build playground", "prepare:playground": "nuxi prepare playground", - "dev:prepare": "nuxt-module-build build --stub && nuxi prepare playground && pnpm run test:prepare-fixtures", - "build:test": "cross-env NUXT_BUILD_TYPE=stub pnpm run prepack && pnpm run dev:build", - "test:prepare-fixtures": "nuxi prepare test/fixtures/simple && nuxi prepare test/fixtures/withOptions && nuxi prepare test/fixtures/complex", - "test:fixtures": "vitest run --dir test", - "test:types": "pnpm run typecheck && pnpm run test:vue", - "test:vue": "vue-tsc -p test/fixtures/simple/tsconfig.json --noEmit && vue-tsc -p test/fixtures/complex/tsconfig.json --noEmit", - "test": "pnpm run dev:prepare && pnpm run test:types && pnpm run test:fixtures", + "dev:prepare": "nuxt-module-build build --stub && nuxi prepare playground", + "build:test": "cross-env NUXT_BUILD_TYPE=stub pnpm run build && pnpm run dev:build", "lint": "eslint --ext .ts --ext .vue .", "docs:dev": "cd docs && pnpm run dev", - "docs:prepare": "nuxt-module-build --stub && nuxi prepare playground", - "docs:build": "npm run docs:prepare && cd docs && nuxi generate", + "docs:build": "cd docs && nuxt generate", "typecheck": "tsc --noEmit", - "release": "bumpp && npm publish && git push --follow-tags" + "release": "bumpp && npm publish && git push --follow-tags", + "test:prepare-fixtures": "nuxi prepare test/fixtures/sample-project", + "test:types-fixtures": "nuxi typecheck test/fixtures/sample-project", + "test:fixtures": "vitest run --dir test ", + "test:types": "pnpm run typecheck", + "test": "pnpm run dev:prepare && pnpm run test:prepare-fixtures && pnpm run test:types && pnpm run test:fixtures", + "test:debug": "NUXT_ROUTER_CONFIG_NAME=$CONFIG pnpm run test:types-fixtures" }, "publishConfig": { "access": "public" @@ -63,54 +64,58 @@ "prettier": "^2.5.x || 3.x" }, "dependencies": { - "@nuxt/kit": "3.8.2", + "@nuxt/kit": "3.10.1", "chalk": "5.3.0", - "defu": "6.1.3", + "defu": "6.1.4", + "globby": "14.0.1", "lodash-es": "4.17.21", "log-symbols": "6.0.0", "mkdirp": "3.0.1", - "nanoid": "5.0.3", - "pathe": "1.1.1", - "prettier": "3.1.0" + "nanoid": "5.0.5", + "pathe": "1.1.2", + "prettier": "3.2.5" }, "devDependencies": { - "@nuxt/devtools": "1.0.3", - "@nuxt/schema": "3.8.2", - "@nuxt/module-builder": "0.5.4", - "@nuxt/test-utils": "3.8.1", - "@nuxt/types": "2.17.2", + "@intlify/core-base": "9.9.1", + "@intlify/message-compiler": "9.9.1", + "@intlify/shared": "9.9.1", + "@intlify/vue-i18n-bridge": "1.1.0", + "@intlify/vue-router-bridge": "1.1.0", + "@nuxt/content": "2.12.0", + "@nuxt/devtools": "1.0.8", + "@nuxt/module-builder": "0.5.5", + "@nuxt/schema": "3.10.1", + "@nuxt/test-utils": "3.11.0", + "@nuxt/types": "2.17.3", "@nuxtjs/eslint-config-typescript": "12.1.0", - "@nuxt/content": "2.9.0", - "@nuxtjs/i18n": "8.0.0-rc.5", + "@nuxtjs/i18n": "8.1.0", "@nuxtjs/web-vitals": "0.2.6", + "@playwright/test": "1.41.2", "@types/lodash-es": "4.17.12", - "@types/node": "20.10.0", - "@typescript-eslint/eslint-plugin": "6.12.0", - "@typescript-eslint/parser": "6.12.0", - "@vue/test-utils": "2.4.2", - "bumpp": "9.2.0", - "changelogithub": "0.13.2", + "@types/node": "20.11.17", + "@typescript-eslint/eslint-plugin": "6.21.0", + "@typescript-eslint/parser": "6.21.0", + "@vue/test-utils": "2.4.4", + "bumpp": "9.3.0", + "changelogithub": "0.13.3", "cross-env": "7.0.3", - "eslint": "8.54.0", - "eslint-config-prettier": "9.0.0", - "eslint-plugin-vue": "9.18.1", - "nuxt": "3.8.2", + "eslint": "8.56.0", + "eslint-config-prettier": "9.1.0", + "eslint-plugin-vue": "9.21.1", + "nuxt": "3.10.1", "nuxt-seo-kit": "1.3.13", - "playwright": "1.40.1", - "@playwright/test": "1.40.1", - "tsd": "0.29.0", - "typescript": "5.3.2", - "vitest": "0.34.6", - "vue": "3.3.10", - "vue-eslint-parser": "9.3.2", + "playwright": "1.41.2", + "prettier": "3.1.1", + "tsd": "0.30.4", + "tslib": "2.6.2", + "typescript": "5.3.3", + "vitest": "1.2.2", + "vue": "3.4.18", + "vue-eslint-parser": "9.4.2", + "vue-i18n": "9.9.1", + "vue-i18n-routing": "1.2.0", "vue-router": "4.2.5", - "vue-tsc": "1.8.22", - "vue-i18n": "9.8.0", - "@intlify/shared": "9.8.0", - "@intlify/message-compiler": "9.8.0", - "@intlify/core-base": "9.8.0", - "@intlify/vue-router-bridge": "1.1.0", - "@intlify/vue-i18n-bridge": "1.1.0", - "vue-i18n-routing": "1.2.0" + "vue-tsc": "1.8.27", + "zx": "7.2.3" } } diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index 5f38e4a..39c792c 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -1,3 +1,5 @@ +import { fileURLToPath } from 'url'; + export default defineNuxtConfig({ extends: ['nuxt-seo-kit'], modules: ['nuxt-typed-router', '@nuxtjs/i18n', '@nuxt/content'], @@ -8,7 +10,7 @@ export default defineNuxtConfig({ plugin: true, pathCheck: true, removeNuxtDefs: true, - ignoreRoutes: ['[...404].vue'], + ignoreRoutes: ['[...404].vue', 'ignoreFolder/**/*'], }, content: { documentDriven: false, @@ -32,4 +34,7 @@ export default defineNuxtConfig({ }, ], }, + alias: { + $$: fileURLToPath(new URL('../src', import.meta.url)), + }, }); diff --git a/playground/src/components/TestLink.vue b/playground/src/components/TestLink.vue index 68e6db8..383f0ed 100644 --- a/playground/src/components/TestLink.vue +++ b/playground/src/components/TestLink.vue @@ -2,15 +2,11 @@ - diff --git a/playground/src/pages/[lang]/post/[slug].vue b/playground/src/pages/[lang]/post/[slug].vue index e69de29..517134a 100644 --- a/playground/src/pages/[lang]/post/[slug].vue +++ b/playground/src/pages/[lang]/post/[slug].vue @@ -0,0 +1 @@ + diff --git a/test/fixtures/complex/src/pages/admin/[id].vue b/playground/src/pages/ignoreFolder/foo.vue similarity index 100% rename from test/fixtures/complex/src/pages/admin/[id].vue rename to playground/src/pages/ignoreFolder/foo.vue diff --git a/playground/src/pages/index.vue b/playground/src/pages/index.vue index 1ec2f11..1e56603 100644 --- a/playground/src/pages/index.vue +++ b/playground/src/pages/index.vue @@ -1,13 +1,12 @@ diff --git a/test/fixtures/simple/pages/admin/[id].vue b/test/fixtures/sample-project/src/pages/admin/[id].vue similarity index 100% rename from test/fixtures/simple/pages/admin/[id].vue rename to test/fixtures/sample-project/src/pages/admin/[id].vue diff --git a/test/fixtures/complex/src/pages/admin/[id]/action-[slug].vue b/test/fixtures/sample-project/src/pages/admin/[id]/action-[slug].vue similarity index 100% rename from test/fixtures/complex/src/pages/admin/[id]/action-[slug].vue rename to test/fixtures/sample-project/src/pages/admin/[id]/action-[slug].vue diff --git a/test/fixtures/complex/src/pages/admin/[id]/index.vue b/test/fixtures/sample-project/src/pages/admin/[id]/index.vue similarity index 100% rename from test/fixtures/complex/src/pages/admin/[id]/index.vue rename to test/fixtures/sample-project/src/pages/admin/[id]/index.vue diff --git a/test/fixtures/complex/src/pages/admin/[id]/profile.vue b/test/fixtures/sample-project/src/pages/admin/[id]/profile.vue similarity index 100% rename from test/fixtures/complex/src/pages/admin/[id]/profile.vue rename to test/fixtures/sample-project/src/pages/admin/[id]/profile.vue diff --git a/test/fixtures/complex/src/pages/admin/[id]/settings.vue b/test/fixtures/sample-project/src/pages/admin/[id]/settings.vue similarity index 100% rename from test/fixtures/complex/src/pages/admin/[id]/settings.vue rename to test/fixtures/sample-project/src/pages/admin/[id]/settings.vue diff --git a/test/fixtures/complex/src/pages/admin/panel/[[blou]].vue b/test/fixtures/sample-project/src/pages/admin/panel/[[blou]].vue similarity index 100% rename from test/fixtures/complex/src/pages/admin/panel/[[blou]].vue rename to test/fixtures/sample-project/src/pages/admin/panel/[[blou]].vue diff --git a/test/fixtures/complex/src/pages/baguette.vue b/test/fixtures/sample-project/src/pages/baguette.vue similarity index 100% rename from test/fixtures/complex/src/pages/baguette.vue rename to test/fixtures/sample-project/src/pages/baguette.vue diff --git a/test/fixtures/sample-project/src/pages/index.vue b/test/fixtures/sample-project/src/pages/index.vue new file mode 100644 index 0000000..9ed4e76 --- /dev/null +++ b/test/fixtures/sample-project/src/pages/index.vue @@ -0,0 +1,5 @@ + + + diff --git a/test/fixtures/complex/src/pages/user/[foo]-[[bar]].vue b/test/fixtures/sample-project/src/pages/user/[foo]-[[bar]].vue similarity index 100% rename from test/fixtures/complex/src/pages/user/[foo]-[[bar]].vue rename to test/fixtures/sample-project/src/pages/user/[foo]-[[bar]].vue diff --git a/test/fixtures/complex/src/pages/user/[id].vue b/test/fixtures/sample-project/src/pages/user/[id].vue similarity index 100% rename from test/fixtures/complex/src/pages/user/[id].vue rename to test/fixtures/sample-project/src/pages/user/[id].vue diff --git a/test/fixtures/complex/src/pages/user/[id]/[slug].vue b/test/fixtures/sample-project/src/pages/user/[id]/[slug].vue similarity index 100% rename from test/fixtures/complex/src/pages/user/[id]/[slug].vue rename to test/fixtures/sample-project/src/pages/user/[id]/[slug].vue diff --git a/test/fixtures/complex/src/pages/user/[id]/[slug]/articles.vue b/test/fixtures/sample-project/src/pages/user/[id]/[slug]/articles.vue similarity index 100% rename from test/fixtures/complex/src/pages/user/[id]/[slug]/articles.vue rename to test/fixtures/sample-project/src/pages/user/[id]/[slug]/articles.vue diff --git a/test/fixtures/complex/src/pages/user/[id]/[slug]/index.vue b/test/fixtures/sample-project/src/pages/user/[id]/[slug]/index.vue similarity index 100% rename from test/fixtures/complex/src/pages/user/[id]/[slug]/index.vue rename to test/fixtures/sample-project/src/pages/user/[id]/[slug]/index.vue diff --git a/test/fixtures/complex/src/pages/user/[id]/index.vue b/test/fixtures/sample-project/src/pages/user/[id]/index.vue similarity index 100% rename from test/fixtures/complex/src/pages/user/[id]/index.vue rename to test/fixtures/sample-project/src/pages/user/[id]/index.vue diff --git a/test/fixtures/complex/src/pages/user/[id]/posts.vue b/test/fixtures/sample-project/src/pages/user/[id]/posts.vue similarity index 100% rename from test/fixtures/complex/src/pages/user/[id]/posts.vue rename to test/fixtures/sample-project/src/pages/user/[id]/posts.vue diff --git a/test/fixtures/complex/src/pages/user/[one]-foo-[two].vue b/test/fixtures/sample-project/src/pages/user/[one]-foo-[two].vue similarity index 100% rename from test/fixtures/complex/src/pages/user/[one]-foo-[two].vue rename to test/fixtures/sample-project/src/pages/user/[one]-foo-[two].vue diff --git a/test/fixtures/complex/src/pages/user/catch/[...slug].vue b/test/fixtures/sample-project/src/pages/user/catch/[...slug].vue similarity index 100% rename from test/fixtures/complex/src/pages/user/catch/[...slug].vue rename to test/fixtures/sample-project/src/pages/user/catch/[...slug].vue diff --git a/test/fixtures/complex/src/pages/user/index.vue b/test/fixtures/sample-project/src/pages/user/index.vue similarity index 100% rename from test/fixtures/complex/src/pages/user/index.vue rename to test/fixtures/sample-project/src/pages/user/index.vue diff --git a/test/fixtures/complex/src/pages/user/test-[[optional]].vue b/test/fixtures/sample-project/src/pages/user/test-[[optional]].vue similarity index 100% rename from test/fixtures/complex/src/pages/user/test-[[optional]].vue rename to test/fixtures/sample-project/src/pages/user/test-[[optional]].vue diff --git a/test/fixtures/sample-project/tests/README.md b/test/fixtures/sample-project/tests/README.md new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/complex/tests/misc/definePageMeta.spec-d.ts b/test/fixtures/sample-project/tests/[classic]/misc/definePageMeta.spec-d.ts similarity index 98% rename from test/fixtures/complex/tests/misc/definePageMeta.spec-d.ts rename to test/fixtures/sample-project/tests/[classic]/misc/definePageMeta.spec-d.ts index ae2cee4..4b0b400 100644 --- a/test/fixtures/complex/tests/misc/definePageMeta.spec-d.ts +++ b/test/fixtures/sample-project/tests/[classic]/misc/definePageMeta.spec-d.ts @@ -72,7 +72,7 @@ definePageMeta({ // ! ------ Should Error ❌ // @ts-expect-error -assertType(definePageMeta({ redirect: '' })); +assertType(definePageMeta({ redirect: '/foo' })); // @ts-expect-error assertType(definePageMeta({ redirect: '/admin ' })); // @ts-expect-error diff --git a/test/fixtures/complex/tests/router/NuxtLink.spec-d.ts b/test/fixtures/sample-project/tests/[classic]/router/NuxtLink.spec-d.ts similarity index 100% rename from test/fixtures/complex/tests/router/NuxtLink.spec-d.ts rename to test/fixtures/sample-project/tests/[classic]/router/NuxtLink.spec-d.ts diff --git a/test/fixtures/complex/tests/router/navigateTo.spec-d.ts b/test/fixtures/sample-project/tests/[classic]/router/navigateTo.spec-d.ts similarity index 100% rename from test/fixtures/complex/tests/router/navigateTo.spec-d.ts rename to test/fixtures/sample-project/tests/[classic]/router/navigateTo.spec-d.ts diff --git a/test/fixtures/complex/tests/router/useRouter.spec-d.ts b/test/fixtures/sample-project/tests/[classic]/router/useRouter.spec-d.ts similarity index 97% rename from test/fixtures/complex/tests/router/useRouter.spec-d.ts rename to test/fixtures/sample-project/tests/[classic]/router/useRouter.spec-d.ts index 3d4502b..94b0d9d 100644 --- a/test/fixtures/complex/tests/router/useRouter.spec-d.ts +++ b/test/fixtures/sample-project/tests/[classic]/router/useRouter.spec-d.ts @@ -1,6 +1,6 @@ import { assertType } from 'vitest'; -import type { TypedRouter, } from '@typed-router'; -import { useRouter } from '@typed-router'; +import type { TypedRouter } from '@typed-router'; +import { useRouter } from '@typed-router'; // @ts-expect-error Ensure global imports are disabled declare const globalDecl: (typeof globalThis)['useRouter']; @@ -8,6 +8,8 @@ declare const globalDecl: (typeof globalThis)['useRouter']; // Given const router = useRouter(); +router.push({ name: 'index' }); + assertType(router); // - Usage of useRouter with useRouter diff --git a/test/fixtures/complex/tests/routes/useRoute.spec-d.ts b/test/fixtures/sample-project/tests/[classic]/routes/useRoute.spec-d.ts similarity index 100% rename from test/fixtures/complex/tests/routes/useRoute.spec-d.ts rename to test/fixtures/sample-project/tests/[classic]/routes/useRoute.spec-d.ts diff --git a/test/fixtures/sample-project/tests/[classic]/test.vue b/test/fixtures/sample-project/tests/[classic]/test.vue new file mode 100644 index 0000000..cb1064c --- /dev/null +++ b/test/fixtures/sample-project/tests/[classic]/test.vue @@ -0,0 +1,29 @@ + + + diff --git a/test/fixtures/complex/tests/router/$typedRouter.spec-d.ts b/test/fixtures/sample-project/tests/[withPlugin]/$typedRouter.spec-d.ts similarity index 100% rename from test/fixtures/complex/tests/router/$typedRouter.spec-d.ts rename to test/fixtures/sample-project/tests/[withPlugin]/$typedRouter.spec-d.ts diff --git a/test/fixtures/simple/tests/misc/definePageMeta.spec-d.ts b/test/fixtures/sample-project/tests/[withStrict]/misc/definePageMeta.spec-d.ts similarity index 50% rename from test/fixtures/simple/tests/misc/definePageMeta.spec-d.ts rename to test/fixtures/sample-project/tests/[withStrict]/misc/definePageMeta.spec-d.ts index ae2cee4..e58ef18 100644 --- a/test/fixtures/simple/tests/misc/definePageMeta.spec-d.ts +++ b/test/fixtures/sample-project/tests/[withStrict]/misc/definePageMeta.spec-d.ts @@ -1,4 +1,4 @@ -import { assertType, expectTypeOf } from 'vitest'; +import { assertType } from 'vitest'; import { definePageMeta } from '@typed-router'; // Given @@ -48,12 +48,6 @@ definePageMeta({ redirect: { name: 'user-id-slug', params: { id: 1 } } }); // @ts-expect-error definePageMeta({ redirect: { name: 'test-module' } }); -// * --- Path navigation -// @ts-expect-error -definePageMeta({ redirect: '/fooooooooooo' }); -// @ts-expect-error -definePageMeta({ redirect: { path: '/foo' } }); - // $ ----- Should be valid ✅ definePageMeta({ redirect: { name: 'index' } }); @@ -72,46 +66,4 @@ definePageMeta({ // ! ------ Should Error ❌ // @ts-expect-error -assertType(definePageMeta({ redirect: '' })); -// @ts-expect-error -assertType(definePageMeta({ redirect: '/admin ' })); -// @ts-expect-error -assertType(definePageMeta({ redirect: '/admin/ /' })); -// @ts-expect-error -assertType(definePageMeta({ redirect: `/ / // / / eefzr` })); -// @ts-expect-error -assertType(definePageMeta({ redirect: '/elzhlzehflzhef' })); -// @ts-expect-error -assertType(definePageMeta({ redirect: '/admin/foo/bar' })); -// @ts-expect-error -assertType(definePageMeta({ redirect: '/admin/foo/bar/baz' })); -// @ts-expect-error -assertType(definePageMeta({ redirect: `/admin/${id}/action-bar/taz?query` })); -// @ts-expect-error -assertType(definePageMeta({ redirect: '/admin/panel/3O9393/bar' })); -// @ts-expect-error -assertType(definePageMeta({ redirect: '/admin/foo/ profile/ezfje' })); -// @ts-expect-error -assertType(definePageMeta({ redirect: '/admin/3U93U/settings/baz' })); -// @ts-expect-error -assertType(definePageMeta({ redirect: '/admin/panel/?fjzk' })); - -// $ ----- Should be valid ✅ - -const id = '38789803'; -assertType(definePageMeta({ redirect: '/' })); -assertType(definePageMeta({ redirect: '/baguette' })); -assertType(definePageMeta({ redirect: '/admin/foo' })); -assertType(definePageMeta({ redirect: '/admin/foo/' })); -assertType(definePageMeta({ redirect: `/admin/${id}/action-bar#hash` })); -assertType(definePageMeta({ redirect: `/admin/${id}/action-bar?query=bar` })); -assertType(definePageMeta({ redirect: '/admin/foo/profile/' })); -assertType(definePageMeta({ redirect: `/admin/${id}/settings` })); -assertType(definePageMeta({ redirect: '/admin/panel/' })); -assertType(definePageMeta({ redirect: '/admin/panel/938783/' })); -assertType(definePageMeta({ redirect: '/user/38873-' })); -assertType(definePageMeta({ redirect: '/user/38673/bar/#hash' })); -assertType(definePageMeta({ redirect: '/user/ç9737/foo/articles?baz=foo' })); -assertType(definePageMeta({ redirect: '/user/catch/1/2' })); -assertType(definePageMeta({ redirect: '/user/test-' })); -assertType(definePageMeta({ redirect: '/user' })); +definePageMeta({ redirect: '/' }); diff --git a/test/fixtures/simple/tests/router/NuxtLink.spec-d.ts b/test/fixtures/sample-project/tests/[withStrict]/router/NuxtLink.spec-d.ts similarity index 53% rename from test/fixtures/simple/tests/router/NuxtLink.spec-d.ts rename to test/fixtures/sample-project/tests/[withStrict]/router/NuxtLink.spec-d.ts index 30d7c07..17967f9 100644 --- a/test/fixtures/simple/tests/router/NuxtLink.spec-d.ts +++ b/test/fixtures/sample-project/tests/[withStrict]/router/NuxtLink.spec-d.ts @@ -1,7 +1,7 @@ import { assertType, vi } from 'vitest'; -import type { TypedNuxtLink } from '../../.nuxt/typed-router/typed-router'; +import type { GlobalComponents } from 'vue'; -const NuxtLink: TypedNuxtLink = vi.fn() as any; +const NuxtLink: GlobalComponents['NuxtLink'] = vi.fn() as any; // ! ------ Should Error ❌ @@ -27,9 +27,9 @@ assertType(new NuxtLink({ to: { name: 'user-foo-bar', params: { bar: 1 } } })); // * --- [...slug].vue // @ts-expect-error -assertType(new NuxtLink({ to: { name: 'user-catch-slug' } })); +assertType(new NuxtLink({ to: { name: 'user-slug' } })); // @ts-expect-error -assertType(new NuxtLink({ to: { name: 'user-catch-slug', params: { slug: 1 } } })); +assertType(new NuxtLink({ to: { name: 'user-slug', params: { slug: 1 } } })); // * --- [one]-foo-[two].vue // @ts-expect-error @@ -47,6 +47,15 @@ assertType(new NuxtLink({ to: { name: 'user-id-slug', params: { id: 1 } } })); // @ts-expect-error assertType(new NuxtLink({ to: { name: 'test-module' } })); +// --- Path navigation + +// ! ------ Should Error ❌ + +// @ts-expect-error +assertType(new NuxtLink({ to: '/' })); +// @ts-expect-error +assertType(new NuxtLink({ to: { path: '/' } })); + // $ ----- Should be valid ✅ assertType(new NuxtLink({ to: { name: 'index' } })); @@ -66,58 +75,14 @@ assertType( }) ); -// --- Path navigation - -// ! ------ Should Error ❌ - -// @ts-expect-error -assertType(new NuxtLink({ to: '' })); -// @ts-expect-error -assertType(new NuxtLink({ to: '/admin ' })); -// @ts-expect-error -assertType(new NuxtLink({ to: '/admin/ /' })); -// @ts-expect-error -assertType(new NuxtLink({ to: `/ / // / / eefzr` })); -// @ts-expect-error -assertType(new NuxtLink({ to: '/elzhlzehflzhef' })); -// @ts-expect-error -assertType(new NuxtLink({ to: '/admin/foo/bar' })); -// @ts-expect-error -assertType(new NuxtLink({ to: '/admin/foo/bar/baz' })); -// @ts-expect-error -assertType(new NuxtLink({ to: `/admin/${id}/action-bar/taz?query` })); -// @ts-expect-error -assertType(new NuxtLink({ to: '/admin/panel/3O9393/bar' })); -// @ts-expect-error -assertType(new NuxtLink({ to: '/admin/foo/ profile/ezfje' })); -// @ts-expect-error -assertType(new NuxtLink({ to: '/admin/3U93U/settings/baz' })); -// @ts-expect-error -assertType(new NuxtLink({ to: '/admin/panel/?fjzk' })); - -// $ ----- Should be valid ✅ - -const id = '38789803'; -assertType(new NuxtLink({ to: '/' })); -assertType(new NuxtLink({ to: '/baguette' })); -assertType(new NuxtLink({ to: '/admin/foo' })); -assertType(new NuxtLink({ to: '/admin/foo/' })); -assertType(new NuxtLink({ to: `/admin/${id}/action-bar#hash` })); -assertType(new NuxtLink({ to: `/admin/${id}/action-bar?query=bar` })); -assertType(new NuxtLink({ to: '/admin/foo/profile/' })); -assertType(new NuxtLink({ to: `/admin/${id}/settings` })); -assertType(new NuxtLink({ to: '/admin/panel/' })); -assertType(new NuxtLink({ to: '/admin/panel/938783/' })); -assertType(new NuxtLink({ to: '/user/38873-' })); -assertType(new NuxtLink({ to: '/user/38673/bar/#hash' })); -assertType(new NuxtLink({ to: '/user/ç9737/foo/articles?baz=foo' })); -assertType(new NuxtLink({ to: '/user/catch/1/2' })); -assertType(new NuxtLink({ to: '/user/test-' })); -assertType(new NuxtLink({ to: '/user' })); +assertType( + new NuxtLink({ + to: { name: 'test-module', params: { foo: 1 }, query: { foo: 'bar' } }, + }) +); // - With External prop // $ ----- Should be valid ✅ -assertType(new NuxtLink({ to: '/admin/:id/', external: false })); assertType(new NuxtLink({ to: 'http://google.com', external: true })); diff --git a/test/fixtures/simple/tests/router/navigateTo.spec-d.ts b/test/fixtures/sample-project/tests/[withStrict]/router/navigateTo.spec-d.ts similarity index 67% rename from test/fixtures/simple/tests/router/navigateTo.spec-d.ts rename to test/fixtures/sample-project/tests/[withStrict]/router/navigateTo.spec-d.ts index 37aea62..5235ebe 100644 --- a/test/fixtures/simple/tests/router/navigateTo.spec-d.ts +++ b/test/fixtures/sample-project/tests/[withStrict]/router/navigateTo.spec-d.ts @@ -1,5 +1,6 @@ -import { assertType, test } from 'vitest'; +import { assertType } from 'vitest'; import type { LocationQuery } from 'vue-router'; +import test from 'node:test'; // ! ------ Should Error ❌ @@ -25,9 +26,9 @@ navigateTo({ name: 'user-foo-bar', params: { bar: 1 } }); // * --- [...slug].vue // @ts-expect-error -navigateTo({ name: 'user-catch-slug' }); +navigateTo({ name: 'user-slug' }); // @ts-expect-error -navigateTo({ name: 'user-catch-slug', params: { slug: 1 } }); +navigateTo({ name: 'user-slug', params: { slug: 1 } }); // * --- [one]-foo-[two].vue // @ts-expect-error @@ -55,61 +56,14 @@ navigateTo({ name: 'user-catch-slug', params: { slug: ['foo'] } }); navigateTo({ name: 'user-catch-slug', params: { slug: [1, 2, 3] } }); navigateTo({ name: 'user-one-foo-two', params: { one: 1, two: '2' } }); navigateTo({ name: 'user-id-slug', params: { slug: '2' }, query: { foo: 'bar' } }); +navigateTo({ name: 'test-module', params: { foo: 1 }, query: { foo: 'bar' } }); // --- Path navigation // ! ------ Should Error ❌ // @ts-expect-error -assertType(navigateTo('')); -// @ts-expect-error -assertType(navigateTo('/admin ')); -// @ts-expect-error -assertType(navigateTo('/admin/ /')); -// @ts-expect-error -assertType(navigateTo(`/ / // / / eefzr`)); -// @ts-expect-error -assertType(navigateTo('/elzhlzehflzhef')); -// @ts-expect-error -assertType(navigateTo('/admin/foo/bar')); -// @ts-expect-error -assertType(navigateTo('/admin/foo/bar/baz')); -// @ts-expect-error -assertType(navigateTo(`/admin/${id}/action-bar/taz?query`)); -// @ts-expect-error -assertType(navigateTo('/admin/panel/3O9393/bar')); -// @ts-expect-error -assertType(navigateTo('/admin/foo/ profile/ezfje')); -// @ts-expect-error -assertType(navigateTo('/admin/3U93U/settings/baz')); -// @ts-expect-error -assertType(navigateTo('/admin/panel/?fjzk')); -// @ts-expect-error -assertType(navigateTo('/admin/panel/938783/ ')); -// @ts-expect-error -assertType(navigateTo('/user/3887/foo/bar/')); -// @ts-expect-error -assertType(navigateTo('/admin/:id//')); - -// $ ----- Should be valid ✅ - -const id = '38789803'; assertType(navigateTo('/')); -assertType(navigateTo('/baguette')); -assertType(navigateTo('/admin/foo')); -assertType(navigateTo('/admin/foo/')); -assertType(navigateTo(`/admin/${id}/action-bar#hash`)); -assertType(navigateTo(`/admin/${id}/action-bar?query=bar`)); -assertType(navigateTo('/admin/foo/profile/')); -assertType(navigateTo(`/admin/${id}/settings`)); -assertType(navigateTo('/admin/panel/')); -assertType(navigateTo('/admin/panel/938783/')); -assertType(navigateTo('/user/38873-')); -assertType(navigateTo('/user/38673/bar/#hash')); -assertType(navigateTo('/user/ç9737/foo/articles?baz=foo')); -assertType(navigateTo('/user/catch/1/2')); -assertType(navigateTo('/user/test-')); -assertType(navigateTo('/user')); // - Resolved routes @@ -214,20 +168,19 @@ test('', async () => { } }); -// - With paths - -// * --- [foo]-[[bar]].vue +// * --- Routes added by modules test('', async () => { - const resolvedNavigateToRoute = await navigateTo('/admin/3883/action-376773'); + const resolvedNavigateToRoute = await navigateTo({ + name: 'test-module', + params: { + foo: 1, + }, + }); if (resolvedNavigateToRoute && !(resolvedNavigateToRoute instanceof Error)) { - assertType<'admin-id-action-slug'>(resolvedNavigateToRoute.name); + assertType<'test-module'>(resolvedNavigateToRoute.name); assertType<{ - id: string; - slug: string; + foo: string; }>(resolvedNavigateToRoute.params); - - // @ts-expect-error - assertType<'admin-id'>(resolvedNavigateToRoute.name); } }); diff --git a/test/fixtures/sample-project/tests/[withStrict]/router/useRouter.spec-d.ts b/test/fixtures/sample-project/tests/[withStrict]/router/useRouter.spec-d.ts new file mode 100644 index 0000000..50d96d6 --- /dev/null +++ b/test/fixtures/sample-project/tests/[withStrict]/router/useRouter.spec-d.ts @@ -0,0 +1,89 @@ +import { assertType } from 'vitest'; +import type { TypedRouter } from '@typed-router'; +import { useRouter } from '@typed-router'; + +// @ts-expect-error Ensure global imports are disabled +declare const globalDecl: (typeof globalThis)['useRouter']; + +// Given +const router = useRouter(); + +assertType(router); + +// - Usage of useRouter with useRouter + +// ! ------ Should Error ❌ + +// * index.vue +// @ts-expect-error +router.push({ name: 'index', params: { id: 1 } }); +// @ts-expect-error +router.push({ name: 'index', params: { id: 1 } }); +// @ts-expect-error +router.push({ name: 'blabla-baguette' }); + +// * --- [id].vue +// @ts-expect-error +router.push({ name: 'user-id' }); +// @ts-expect-error +router.push({ name: 'user-id', params: { foo: 'bar' } }); + +// * --- [foo]-[[bar]].vue +// @ts-expect-error +router.push({ name: 'user-foo-bar' }); +// @ts-expect-error +router.push({ name: 'user-foo-bar', params: { bar: 1 } }); + +// * --- [...slug].vue +// @ts-expect-error +router.push({ name: 'user-slug' }); +// @ts-expect-error +router.push({ name: 'user-slug', params: { slug: 1 } }); + +// * --- [one]-foo-[two].vue +// @ts-expect-error +router.push({ name: 'user-one-foo-two' }); +// @ts-expect-error +router.push({ name: 'user-one-foo-two', params: { one: 1 } }); + +// * --- [id]/[slug].vue +// @ts-expect-error +router.push({ name: 'user-id-slug' }); +// @ts-expect-error +router.push({ name: 'user-id-slug', params: { id: 1 } }); + +// * --- Routes added by modules +// @ts-expect-error +router.push({ name: 'test-module' }); + +// $ ----- Should be valid ✅ + +router.push({ name: 'index' }); +router.push({ name: 'user-id', params: { id: 1 }, hash: 'baz' }); +router.push({ name: 'user-foo-bar', params: { foo: 'bar' }, force: true }); +router.push({ name: 'user-foo-bar', params: { foo: 'bar', bar: 'baz' } }); +router.push({ name: 'user-catch-slug', params: { slug: ['foo'] } }); +router.push({ name: 'user-catch-slug', params: { slug: [1, 2, 3] } }); +router.push({ name: 'user-one-foo-two', params: { one: 1, two: '2' } }); +router.push({ name: 'user-id-slug', params: { slug: '2' }, query: { foo: 'bar' } }); +router.push({ name: 'test-module', params: { foo: 1 }, query: { foo: 'bar' } }); + +router.replace({ name: 'index' }); +router.replace({ name: 'user-id', params: { id: 1 }, hash: 'baz' }); + +// --- Path navigation + +// ! ------ Should Error ❌ +// @ts-expect-error +assertType(router.push('/')); + +// * Resolved routes + +const resolved1 = router.resolve({ name: 'index' }); +assertType<'index'>(resolved1.name); +// @ts-expect-error +assertType<'index'>(resolved1.params); + +const resolved2 = router.resolve({ name: 'user-id', params: { id: 1 }, hash: 'baz' }); +assertType<'user-id'>(resolved2.name); +assertType<{ id: string }>(resolved2.params); diff --git a/test/fixtures/simple/tests/routes/useRoute.spec-d.ts b/test/fixtures/sample-project/tests/[withStrict]/routes/useRoute.spec-d.ts similarity index 89% rename from test/fixtures/simple/tests/routes/useRoute.spec-d.ts rename to test/fixtures/sample-project/tests/[withStrict]/routes/useRoute.spec-d.ts index 5993a5f..2287c8e 100644 --- a/test/fixtures/simple/tests/routes/useRoute.spec-d.ts +++ b/test/fixtures/sample-project/tests/[withStrict]/routes/useRoute.spec-d.ts @@ -72,3 +72,12 @@ if (route.name === 'user-id-slug') { slug: string; }>(route.params); } + +// * --- Routes added by modules +if (route.name === 'test-module') { + assertType>(route); + assertType<'test-module'>(route.name); + assertType<{ + foo: string; + }>(route.params); +} diff --git a/test/fixtures/complex/tests/i18n/NuxtLinkLocale.spec-d.ts b/test/fixtures/sample-project/tests/i18n/NuxtLinkLocale.spec-d.ts similarity index 100% rename from test/fixtures/complex/tests/i18n/NuxtLinkLocale.spec-d.ts rename to test/fixtures/sample-project/tests/i18n/NuxtLinkLocale.spec-d.ts diff --git a/test/fixtures/complex/tests/i18n/useLocalePath.spec-d.ts b/test/fixtures/sample-project/tests/i18n/useLocalePath.spec-d.ts similarity index 100% rename from test/fixtures/complex/tests/i18n/useLocalePath.spec-d.ts rename to test/fixtures/sample-project/tests/i18n/useLocalePath.spec-d.ts diff --git a/test/fixtures/complex/tests/i18n/useLocaleRoute.spec-d.ts b/test/fixtures/sample-project/tests/i18n/useLocaleRoute.spec-d.ts similarity index 100% rename from test/fixtures/complex/tests/i18n/useLocaleRoute.spec-d.ts rename to test/fixtures/sample-project/tests/i18n/useLocaleRoute.spec-d.ts diff --git a/test/fixtures/complex/tsconfig.json b/test/fixtures/sample-project/tsconfig.json similarity index 100% rename from test/fixtures/complex/tsconfig.json rename to test/fixtures/sample-project/tsconfig.json diff --git a/test/fixtures/simple/.gitignore b/test/fixtures/simple/.gitignore deleted file mode 100644 index 438cb08..0000000 --- a/test/fixtures/simple/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -node_modules -*.log* -.nuxt -.nitro -.cache -.output -.env -dist diff --git a/test/fixtures/simple/README.md b/test/fixtures/simple/README.md deleted file mode 100644 index c699c96..0000000 --- a/test/fixtures/simple/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# Nuxt 3 Minimal Starter - -Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more. - -## Setup - -Make sure to install the dependencies: - -```bash -# yarn -yarn install - -# npm -npm install - -# pnpm -pnpm install -``` - -## Development Server - -Start the development server on http://localhost:3000 - -```bash -npm run dev -``` - -## Production - -Build the application for production: - -```bash -npm run build -``` - -Locally preview production build: - -```bash -npm run preview -``` - -Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information. diff --git a/test/fixtures/simple/app.vue b/test/fixtures/simple/app.vue deleted file mode 100644 index 01b7bef..0000000 --- a/test/fixtures/simple/app.vue +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/test/fixtures/simple/nuxt.config.ts b/test/fixtures/simple/nuxt.config.ts deleted file mode 100644 index a278ee6..0000000 --- a/test/fixtures/simple/nuxt.config.ts +++ /dev/null @@ -1,8 +0,0 @@ -export default defineNuxtConfig({ - modules: ['nuxt-typed-router'], - vite: { - resolve: { - dedupe: ['vue-router'], - }, - }, -}); diff --git a/test/fixtures/simple/package.json b/test/fixtures/simple/package.json deleted file mode 100644 index ca2431f..0000000 --- a/test/fixtures/simple/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "private": true, - "name": "simple", - "version": "1.0.0", - "scripts": { - "build": "nuxt build", - "dev": "nuxt dev", - "generate": "nuxt generate", - "preview": "nuxt preview" - }, - "devDependencies": { - "nuxt": "^3.8.2", - "vue": "3.3.10", - "nuxt-typed-router": "workspace:*" - } -} diff --git a/test/fixtures/simple/pages/admin.vue b/test/fixtures/simple/pages/admin.vue deleted file mode 100644 index 7dcf98f..0000000 --- a/test/fixtures/simple/pages/admin.vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/admin/[id]/action-[slug].vue b/test/fixtures/simple/pages/admin/[id]/action-[slug].vue deleted file mode 100644 index 7dcf98f..0000000 --- a/test/fixtures/simple/pages/admin/[id]/action-[slug].vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/admin/[id]/index.vue b/test/fixtures/simple/pages/admin/[id]/index.vue deleted file mode 100644 index 7dcf98f..0000000 --- a/test/fixtures/simple/pages/admin/[id]/index.vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/admin/[id]/profile.vue b/test/fixtures/simple/pages/admin/[id]/profile.vue deleted file mode 100644 index 7dcf98f..0000000 --- a/test/fixtures/simple/pages/admin/[id]/profile.vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/admin/[id]/settings.vue b/test/fixtures/simple/pages/admin/[id]/settings.vue deleted file mode 100644 index 7dcf98f..0000000 --- a/test/fixtures/simple/pages/admin/[id]/settings.vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/admin/panel/[[blou]].vue b/test/fixtures/simple/pages/admin/panel/[[blou]].vue deleted file mode 100644 index 7dcf98f..0000000 --- a/test/fixtures/simple/pages/admin/panel/[[blou]].vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/baguette.vue b/test/fixtures/simple/pages/baguette.vue deleted file mode 100644 index 7dcf98f..0000000 --- a/test/fixtures/simple/pages/baguette.vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/user/[foo]-[[bar]].vue b/test/fixtures/simple/pages/user/[foo]-[[bar]].vue deleted file mode 100644 index 87ac15c..0000000 --- a/test/fixtures/simple/pages/user/[foo]-[[bar]].vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/user/[id].vue b/test/fixtures/simple/pages/user/[id].vue deleted file mode 100644 index 094637f..0000000 --- a/test/fixtures/simple/pages/user/[id].vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/user/[id]/[slug].vue b/test/fixtures/simple/pages/user/[id]/[slug].vue deleted file mode 100644 index 094637f..0000000 --- a/test/fixtures/simple/pages/user/[id]/[slug].vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/user/[id]/[slug]/articles.vue b/test/fixtures/simple/pages/user/[id]/[slug]/articles.vue deleted file mode 100644 index 7dcf98f..0000000 --- a/test/fixtures/simple/pages/user/[id]/[slug]/articles.vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/user/[id]/[slug]/index.vue b/test/fixtures/simple/pages/user/[id]/[slug]/index.vue deleted file mode 100644 index 9070ec8..0000000 --- a/test/fixtures/simple/pages/user/[id]/[slug]/index.vue +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/test/fixtures/simple/pages/user/[id]/index.vue b/test/fixtures/simple/pages/user/[id]/index.vue deleted file mode 100644 index 2504a8a..0000000 --- a/test/fixtures/simple/pages/user/[id]/index.vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/user/[id]/posts.vue b/test/fixtures/simple/pages/user/[id]/posts.vue deleted file mode 100644 index 094637f..0000000 --- a/test/fixtures/simple/pages/user/[id]/posts.vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/user/[one]-foo-[two].vue b/test/fixtures/simple/pages/user/[one]-foo-[two].vue deleted file mode 100644 index 87ac15c..0000000 --- a/test/fixtures/simple/pages/user/[one]-foo-[two].vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/user/catch/[...slug].vue b/test/fixtures/simple/pages/user/catch/[...slug].vue deleted file mode 100644 index 87ac15c..0000000 --- a/test/fixtures/simple/pages/user/catch/[...slug].vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/user/index.vue b/test/fixtures/simple/pages/user/index.vue deleted file mode 100644 index 7dcf98f..0000000 --- a/test/fixtures/simple/pages/user/index.vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/pages/user/test-[[optional]].vue b/test/fixtures/simple/pages/user/test-[[optional]].vue deleted file mode 100644 index 87ac15c..0000000 --- a/test/fixtures/simple/pages/user/test-[[optional]].vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/simple/tests/router/useRouter.spec-d.ts b/test/fixtures/simple/tests/router/useRouter.spec-d.ts deleted file mode 100644 index 09aa5a6..0000000 --- a/test/fixtures/simple/tests/router/useRouter.spec-d.ts +++ /dev/null @@ -1,153 +0,0 @@ -import { assertType } from 'vitest'; -import test from 'node:test'; -import type { TypedRouter } from '@typed-router'; - -// Given -const router = useRouter(); - -assertType(router); - -// - Usage of useRouter with useRouter - -// ! ------ Should Error ❌ - -// * index.vue -// @ts-expect-error -router.push({ name: 'index', params: { id: 1 } }); -// @ts-expect-error -router.push({ name: 'index', params: { id: 1 } }); -// @ts-expect-error -router.push({ name: 'blabla-baguette' }); - -// * --- [id].vue -// @ts-expect-error -router.push({ name: 'user-id' }); -// @ts-expect-error -router.push({ name: 'user-id', params: { foo: 'bar' } }); - -// * --- [foo]-[[bar]].vue -// @ts-expect-error -router.push({ name: 'user-foo-bar' }); -// @ts-expect-error -router.push({ name: 'user-foo-bar', params: { bar: 1 } }); - -// * --- [...slug].vue -// @ts-expect-error -router.push({ name: 'user-slug' }); -// @ts-expect-error -router.push({ name: 'user-slug', params: { slug: 1 } }); - -// * --- [one]-foo-[two].vue -// @ts-expect-error -router.push({ name: 'user-one-foo-two' }); -// @ts-expect-error -router.push({ name: 'user-one-foo-two', params: { one: 1 } }); - -// * --- [id]/[slug].vue -// @ts-expect-error -router.push({ name: 'user-id-slug' }); -// @ts-expect-error -router.push({ name: 'user-id-slug', params: { id: 1 } }); - -// * --- Routes added by modules -// @ts-expect-error -router.push({ name: 'test-module' }); - -// * --- Path navigation -// @ts-expect-error -router.push('/fooooooooooo'); -// @ts-expect-error -router.push({ path: '/foo' }); - -// $ ----- Should be valid ✅ - -router.push({ name: 'index' }); -router.push({ name: 'user-id', params: { id: 1 }, hash: 'baz' }); -router.push({ name: 'user-foo-bar', params: { foo: 'bar' }, force: true }); -router.push({ name: 'user-foo-bar', params: { foo: 'bar', bar: 'baz' } }); -router.push({ name: 'user-catch-slug', params: { slug: ['foo'] } }); -router.push({ name: 'user-catch-slug', params: { slug: [1, 2, 3] } }); -router.push({ name: 'user-one-foo-two', params: { one: 1, two: '2' } }); -router.push({ name: 'user-id-slug', params: { slug: '2' }, query: { foo: 'bar' } }); - -router.replace({ name: 'index' }); -router.replace({ name: 'user-id', params: { id: 1 }, hash: 'baz' }); -router.replace('/admin'); - -// --- Path navigation - -// ! ------ Should Error ❌ - -// @ts-expect-error -assertType(router.push('')); -// @ts-expect-error -assertType(router.push('/admin ')); -// @ts-expect-error -assertType(router.push('/admin/ /')); -// @ts-expect-error -assertType(router.push(`/ / // / / eefzr`)); -// @ts-expect-error -assertType(router.push('/elzhlzehflzhef')); -// @ts-expect-error -assertType(router.push('/admin/foo/bar')); -// @ts-expect-error -assertType(router.push('/admin/foo/bar/baz')); -// @ts-expect-error -assertType(router.push(`/admin/${id}/action-bar/taz?query`)); -// @ts-expect-error -assertType(router.push('/admin/panel/3O9393/bar')); -// @ts-expect-error -assertType(router.push('/admin/foo/ profile/ezfje')); -// @ts-expect-error -assertType(router.push('/admin/3U93U/settings/baz')); -// @ts-expect-error -assertType(router.push('/admin/panel/?fjzk')); - -// $ ----- Should be valid ✅ - -const id = '38789803'; -assertType(router.push('/')); -assertType(router.push('/baguette')); -assertType(router.push('/admin/foo')); -assertType(router.push('/admin/foo/')); -assertType(router.push(`/admin/${id}/action-bar#hash`)); -assertType(router.push(`/admin/${id}/action-bar?query=bar`)); -assertType(router.push('/admin/foo/profile/')); -assertType(router.push(`/admin/${id}/settings`)); -assertType(router.push('/admin/panel/')); -assertType(router.push('/admin/panel/938783/')); -assertType(router.push('/user/38873-')); -assertType(router.push('/user/38673/bar/#hash')); -assertType(router.push('/user/ç9737/foo/articles?baz=foo')); -assertType(router.push('/user/catch/1/2')); -assertType(router.push('/user/test-')); -assertType(router.push('/user')); - -// * Resolved routes - -test('', () => { - const resolved = router.resolve({ name: 'index' }); - assertType<'index'>(resolved.name); - // @ts-expect-error - assertType<'index'>(resolved.params); -}); - -test('', () => { - const resolved = router.resolve({ name: 'user-id', params: { id: 1 }, hash: 'baz' }); - assertType<'user-id'>(resolved.name); - assertType<{ id: string }>(resolved.params); - - // @ts-expect-error - assertType<'user-eojzpejfze'>(resolved.name); -}); - -test('', () => { - const resolved = router.resolve('/admin/foo/'); - assertType<'admin-id'>(resolved.name); - assertType<{ id: string }>(resolved.params); - - // @ts-expect-error - assertType<'jzeifjlfej'>(resolved.name); - // @ts-expect-error - assertType<{ foo: string }>(resolved.params); -}); diff --git a/test/fixtures/simple/tests/routes/useLink.spec-d.ts b/test/fixtures/simple/tests/routes/useLink.spec-d.ts deleted file mode 100644 index 04eb3c4..0000000 --- a/test/fixtures/simple/tests/routes/useLink.spec-d.ts +++ /dev/null @@ -1,245 +0,0 @@ -import { assertType, test } from 'vitest'; -import type { LocationQuery } from 'vue-router'; - -// ! ------ Should Error ❌ - -// * index.vue -// @ts-expect-error -useLink({ to: { name: 'index', params: { id: 1 } } }); -// @ts-expect-error -useLink({ to: { name: 'index', params: { id: 1 } } }); -// @ts-expect-error -useLink({ to: { name: 'blabla-baguette' } }); - -// * --- [id].vue -// @ts-expect-error -useLink({ to: { name: 'user-id' } }); -// @ts-expect-error -useLink({ to: { name: 'user-id', params: { foo: 'bar' } } }); - -// * --- [foo]-[[bar]].vue -// @ts-expect-error -useLink({ to: { name: 'user-foo-bar' } }); -// @ts-expect-error -useLink({ to: { name: 'user-foo-bar', params: { bar: 1 } } }); - -// * --- [...slug].vue -// @ts-expect-error -useLink({ to: { name: 'user-catch-slug' } }); -// @ts-expect-error -useLink({ to: { name: 'user-catch-slug', params: { slug: 1 } } }); - -// * --- [one]-foo-[two].vue -// @ts-expect-error -useLink({ to: { name: 'user-one-foo-two' } }); -// @ts-expect-error -useLink({ to: { name: 'user-one-foo-two', params: { one: 1 } } }); - -// * --- [id]/[slug].vue -// @ts-expect-error -useLink({ to: { name: 'user-id-slug' } }); -// @ts-expect-error -useLink({ to: { name: 'user-id-slug', params: { id: 1 } } }); - -// * --- Routes added by modules -// @ts-expect-error -useLink({ to: { name: 'test-module' } }); - -// $ ----- Should be valid ✅ - -useLink({ to: { name: 'index' } }); -useLink({ to: { name: 'user-id', params: { id: 1 }, hash: 'baz' } }); -useLink({ to: { name: 'user-foo-bar', params: { foo: 'bar' }, force: true } }); -useLink({ to: { name: 'user-foo-bar', params: { foo: 'bar', bar: 'baz' } } }); -useLink({ to: { name: 'user-catch-slug', params: { slug: ['foo'] } } }); -useLink({ to: { name: 'user-catch-slug', params: { slug: [1, 2, 3] } } }); -useLink({ to: { name: 'user-one-foo-two', params: { one: 1, two: '2' } } }); -useLink({ to: { name: 'user-id-slug', params: { slug: '2' }, query: { foo: 'bar' } } }); - -// --- Path navigation - -// ! ------ Should Error ❌ - -// @ts-expect-error -assertType(useLink({ to: '' })); -// @ts-expect-error -assertType(useLink({ to: '/admin ' })); -// @ts-expect-error -assertType(useLink({ to: '/admin/ /' })); -// @ts-expect-error -assertType(useLink({ to: `/ / // / / eefzr` })); -// @ts-expect-error -assertType(useLink({ to: '/elzhlzehflzhef' })); -// @ts-expect-error -assertType(useLink({ to: '/admin/foo/bar' })); -// @ts-expect-error -assertType(useLink({ to: '/admin/foo/bar/baz' })); -// @ts-expect-error -assertType(useLink({ to: `/admin/${id}/action-bar/taz?query` })); -// @ts-expect-error -assertType(useLink({ to: '/admin/panel/3O9393/bar' })); -// @ts-expect-error -assertType(useLink({ to: '/admin/foo/ profile/ezfje' })); -// @ts-expect-error -assertType(useLink({ to: '/admin/3U93U/settings/baz' })); -// @ts-expect-error -assertType(useLink({ to: '/admin/panel/?fjzk' })); -// @ts-expect-error -assertType(useLink({ to: '/admin/panel/938783/ ' })); -// @ts-expect-error -assertType(useLink({ to: '/user/3887/foo/bar/' })); -// @ts-expect-error -assertType(useLink({ to: '/admin/:id//' })); - -// $ ----- Should be valid ✅ - -const id = '38789803'; -assertType(useLink({ to: '/' })); -assertType(useLink({ to: '/baguette' })); -assertType(useLink({ to: '/admin/foo' })); -assertType(useLink({ to: '/admin/foo/' })); -assertType(useLink({ to: `/admin/${id}/action-bar#hash` })); -assertType(useLink({ to: `/admin/${id}/action-bar?query=bar` })); -assertType(useLink({ to: '/admin/foo/profile/' })); -assertType(useLink({ to: `/admin/${id}/settings` })); -assertType(useLink({ to: '/admin/panel/' })); -assertType(useLink({ to: '/admin/panel/938783/' })); -assertType(useLink({ to: '/user/38873-' })); -assertType(useLink({ to: '/user/38673/bar/#hash' })); -assertType(useLink({ to: '/user/ç9737/foo/articles?baz=foo' })); -assertType(useLink({ to: '/user/catch/1/2' })); -assertType(useLink({ to: '/user/test-' })); -assertType(useLink({ to: '/user' })); - -// - Resolved routes - -// * index.vue -test('', async () => { - const resolvedNavigateToRoute = useLink({ - to: { - name: 'index', - }, - }); - - if (resolvedNavigateToRoute) { - assertType<'index'>(resolvedNavigateToRoute.route.value.name); - // @ts-expect-error - assertType(resolvedNavigateToRoute.params); - } -}); - -// * --- [id].vue -test('', async () => { - const resolvedNavigateToRoute = await useLink({ - to: { - name: 'user-id', - params: { - id: 1, - }, - }, - }); - - if (resolvedNavigateToRoute) { - assertType<'user-id'>(resolvedNavigateToRoute.route.value.name); - assertType<{ - id: string; - }>(resolvedNavigateToRoute.route.value.params); - } -}); - -// * --- [foo]-[[bar]].vue -test('', async () => { - const resolvedNavigateToRoute = await useLink({ - to: { - name: 'user-foo-bar', - params: { - foo: 1, - bar: 1, - }, - }, - }); - - if (resolvedNavigateToRoute) { - assertType<'user-foo-bar'>(resolvedNavigateToRoute.route.value.name); - assertType<{ - foo: string; - bar?: string | undefined; - }>(resolvedNavigateToRoute.route.value.params); - } -}); - -// * --- [...slug].vue -test('', async () => { - const resolvedNavigateToRoute = await useLink({ - to: { - name: 'user-catch-slug', - params: { - slug: [1, 2, 3], - }, - }, - }); - - if (resolvedNavigateToRoute) { - assertType<'user-catch-slug'>(resolvedNavigateToRoute.route.value.name); - assertType<{ - slug: string[]; - }>(resolvedNavigateToRoute.route.value.params); - } -}); - -// * --- [one]-foo-[two].vue - -const resolvedNavigateToRoute = await useLink({ - to: { - name: 'user-one-foo-two', - params: { one: 1, two: 2 }, - }, -}); - -if (resolvedNavigateToRoute) { - assertType<'user-one-foo-two'>(resolvedNavigateToRoute.route.value.name); - assertType<{ - one: string | number; - two: string | number; - }>(resolvedNavigateToRoute.route.value.params); - assertType(resolvedNavigateToRoute.route.value.query); -} - -// * --- [id]/[slug].vue -test('', async () => { - const resolvedNavigateToRoute = await useLink({ - to: { - name: 'user-id-slug', - params: { - slug: 1, - id: 1, - }, - }, - }); - - if (resolvedNavigateToRoute) { - assertType<'user-id-slug'>(resolvedNavigateToRoute.route.value.name); - assertType<{ - id: string; - slug: string; - }>(resolvedNavigateToRoute.route.value.params); - } -}); - -// - With paths - -// * --- [foo]-[[bar]].vue -test('', async () => { - const resolvedNavigateToRoute = await useLink({ to: '/admin/3883/action-376773' }); - - if (resolvedNavigateToRoute) { - assertType<'admin-id-action-slug'>(resolvedNavigateToRoute.route.value.name); - assertType<{ - id: string; - slug: string; - }>(resolvedNavigateToRoute.route.value.params); - - // @ts-expect-error - assertType<'admin-id'>(resolvedNavigateToRoute.route.value.name); - } -}); diff --git a/test/fixtures/simple/tsconfig.json b/test/fixtures/simple/tsconfig.json deleted file mode 100644 index 3c61969..0000000 --- a/test/fixtures/simple/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - // https://nuxt.com/docs/guide/concepts/typescript - "extends": "./.nuxt/tsconfig.json", - "compilerOptions": { - "verbatimModuleSyntax": false - } -} diff --git a/test/fixtures/withOptions/.gitignore b/test/fixtures/withOptions/.gitignore deleted file mode 100644 index 438cb08..0000000 --- a/test/fixtures/withOptions/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -node_modules -*.log* -.nuxt -.nitro -.cache -.output -.env -dist diff --git a/test/fixtures/withOptions/README.md b/test/fixtures/withOptions/README.md deleted file mode 100644 index c699c96..0000000 --- a/test/fixtures/withOptions/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# Nuxt 3 Minimal Starter - -Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more. - -## Setup - -Make sure to install the dependencies: - -```bash -# yarn -yarn install - -# npm -npm install - -# pnpm -pnpm install -``` - -## Development Server - -Start the development server on http://localhost:3000 - -```bash -npm run dev -``` - -## Production - -Build the application for production: - -```bash -npm run build -``` - -Locally preview production build: - -```bash -npm run preview -``` - -Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information. diff --git a/test/fixtures/withOptions/app.vue b/test/fixtures/withOptions/app.vue deleted file mode 100644 index 01b7bef..0000000 --- a/test/fixtures/withOptions/app.vue +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/test/fixtures/withOptions/nuxt.config.ts b/test/fixtures/withOptions/nuxt.config.ts deleted file mode 100644 index 658a9f2..0000000 --- a/test/fixtures/withOptions/nuxt.config.ts +++ /dev/null @@ -1,10 +0,0 @@ -import NuxtTypedRouter from '../../..'; - -export default defineNuxtConfig({ - modules: [NuxtTypedRouter], - vite: { - resolve: { - dedupe: ['vue-router'], - }, - }, -}); diff --git a/test/fixtures/withOptions/package.json b/test/fixtures/withOptions/package.json deleted file mode 100644 index b856c02..0000000 --- a/test/fixtures/withOptions/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "private": true, - "name": "with-options", - "version": "1.0.0", - "scripts": { - "build": "nuxt build", - "dev": "nuxt dev", - "generate": "nuxt generate", - "preview": "nuxt preview" - }, - "devDependencies": { - "nuxt": "3.8.2", - "nuxt-typed-router": "workspace:*" - } -} diff --git a/test/fixtures/withOptions/pages/index.vue b/test/fixtures/withOptions/pages/index.vue deleted file mode 100644 index e3a145e..0000000 --- a/test/fixtures/withOptions/pages/index.vue +++ /dev/null @@ -1,7 +0,0 @@ - - - diff --git a/test/fixtures/withOptions/pages/user/[...slug].vue b/test/fixtures/withOptions/pages/user/[...slug].vue deleted file mode 100644 index 87ac15c..0000000 --- a/test/fixtures/withOptions/pages/user/[...slug].vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/withOptions/pages/user/[foo]-[[bar]].vue b/test/fixtures/withOptions/pages/user/[foo]-[[bar]].vue deleted file mode 100644 index 87ac15c..0000000 --- a/test/fixtures/withOptions/pages/user/[foo]-[[bar]].vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/withOptions/pages/user/[id].vue b/test/fixtures/withOptions/pages/user/[id].vue deleted file mode 100644 index 094637f..0000000 --- a/test/fixtures/withOptions/pages/user/[id].vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/withOptions/pages/user/[id]/[slug].vue b/test/fixtures/withOptions/pages/user/[id]/[slug].vue deleted file mode 100644 index 094637f..0000000 --- a/test/fixtures/withOptions/pages/user/[id]/[slug].vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/withOptions/pages/user/[id]/[slug]/articles.vue b/test/fixtures/withOptions/pages/user/[id]/[slug]/articles.vue deleted file mode 100644 index 7dcf98f..0000000 --- a/test/fixtures/withOptions/pages/user/[id]/[slug]/articles.vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/withOptions/pages/user/[id]/[slug]/index.vue b/test/fixtures/withOptions/pages/user/[id]/[slug]/index.vue deleted file mode 100644 index 9070ec8..0000000 --- a/test/fixtures/withOptions/pages/user/[id]/[slug]/index.vue +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/test/fixtures/withOptions/pages/user/[id]/index.vue b/test/fixtures/withOptions/pages/user/[id]/index.vue deleted file mode 100644 index 2504a8a..0000000 --- a/test/fixtures/withOptions/pages/user/[id]/index.vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/withOptions/pages/user/[id]/posts.vue b/test/fixtures/withOptions/pages/user/[id]/posts.vue deleted file mode 100644 index 094637f..0000000 --- a/test/fixtures/withOptions/pages/user/[id]/posts.vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/withOptions/pages/user/[one]-foo-[two].vue b/test/fixtures/withOptions/pages/user/[one]-foo-[two].vue deleted file mode 100644 index 87ac15c..0000000 --- a/test/fixtures/withOptions/pages/user/[one]-foo-[two].vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/withOptions/pages/user/index.vue b/test/fixtures/withOptions/pages/user/index.vue deleted file mode 100644 index 7dcf98f..0000000 --- a/test/fixtures/withOptions/pages/user/index.vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/withOptions/pages/user/test-[[optional]].vue b/test/fixtures/withOptions/pages/user/test-[[optional]].vue deleted file mode 100644 index 87ac15c..0000000 --- a/test/fixtures/withOptions/pages/user/test-[[optional]].vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/fixtures/withOptions/tests/e2e/withPartialStrict.spec.ts b/test/fixtures/withOptions/tests/e2e/withPartialStrict.spec.ts deleted file mode 100644 index b3dda7e..0000000 --- a/test/fixtures/withOptions/tests/e2e/withPartialStrict.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -test('empty') - -// import { fileURLToPath } from 'node:url'; -// import { setup } from '@nuxt/test-utils'; -// import { assertType } from 'vitest'; -// import { useRouter } from '../../.nuxt/typed-router'; -// import type { TypedNuxtLink } from '../../.nuxt/typed-router/typed-router'; - -// test.skip('The strict option should behave correctly with partial strict options', async () => { -// await setup({ -// rootDir: fileURLToPath(new URL('../../fixtures/withOptions', import.meta.url)), -// setupTimeout: 120000, -// nuxtConfig: { -// nuxtTypedRouter: { -// strict: { -// NuxtLink: { -// strictRouteLocation: true, -// }, -// router: { -// strictToArgument: true, -// }, -// }, -// }, -// }, -// } as any); - -// // const diagnostic = await runTypesDiagnostics(__dirname, __filename); - -// // expect(diagnostic.length).toBe(0); - -// const NuxtLink: TypedNuxtLink = vi.fn() as any; - -// const router = { push: vi.fn() } as unknown as ReturnType; - -// assertType(router.push('/user')); -// // @ts-expect-error -// assertType(router.push({ path: '/login' })); - -// // @ts-expect-error -// assertType(new NuxtLink('/user')); -// assertType(new NuxtLink({ to: { path: '/user' } })); -// }); diff --git a/test/fixtures/withOptions/tests/e2e/withStrict.spec.ts b/test/fixtures/withOptions/tests/e2e/withStrict.spec.ts deleted file mode 100644 index 2c105e8..0000000 --- a/test/fixtures/withOptions/tests/e2e/withStrict.spec.ts +++ /dev/null @@ -1,37 +0,0 @@ -test('empty') -// import { setup } from '@nuxt/test-utils'; -// import { fileURLToPath } from 'node:url'; -// import { assertType } from 'vitest'; -// import { useRouter } from '../../.nuxt/typed-router'; -// import type { TypedNuxtLink } from '../../.nuxt/typed-router/typed-router'; - -// test.skip('The strict option should behave correctly with strict: true', async () => { -// await setup({ -// rootDir: fileURLToPath(new URL('../../fixtures/withOptions', import.meta.url)), -// setupTimeout: 120000, -// nuxtConfig: { -// nuxtTypedRouter: { -// strict: true, -// }, -// }, -// } as any); - -// // const diagnostic = await runTypesDiagnostics(__dirname, __filename); - -// // expect(diagnostic.length).toBe(0); - -// const NuxtLink: TypedNuxtLink = vi.fn() as any; - -// const router = { push: vi.fn() } as unknown as ReturnType; - -// // @ts-expect-error -// assertType(router.push('/foo')); -// // @ts-expect-error -// assertType(router.push({ path: '/login' })); - -// // @ts-expect-error -// assertType(new NuxtLink('/login')); -// // @ts-expect-error -// assertType(new NuxtLink({ path: '/goooo' })); -// }); - diff --git a/test/fixtures/withOptions/tsconfig.json b/test/fixtures/withOptions/tsconfig.json deleted file mode 100644 index 2c90bb7..0000000 --- a/test/fixtures/withOptions/tsconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "./.nuxt/tsconfig.json", - "compilerOptions": { - "types": ["vitest/globals"] - } -} diff --git a/test/samples-config/classic.ts b/test/samples-config/classic.ts new file mode 100644 index 0000000..ccac3ac --- /dev/null +++ b/test/samples-config/classic.ts @@ -0,0 +1,5 @@ +import { NuxtConfig } from '@nuxt/schema'; + +const config: NuxtConfig = {}; + +export default config; diff --git a/test/samples-config/withPlugin.ts b/test/samples-config/withPlugin.ts new file mode 100644 index 0000000..51bada2 --- /dev/null +++ b/test/samples-config/withPlugin.ts @@ -0,0 +1,8 @@ +import { NuxtConfig } from '@nuxt/schema'; + +const config: NuxtConfig = { + nuxtTypedRouter: { + plugin: true, + }, +}; +export default config; diff --git a/test/samples-config/withStrict.ts b/test/samples-config/withStrict.ts new file mode 100644 index 0000000..330156b --- /dev/null +++ b/test/samples-config/withStrict.ts @@ -0,0 +1,8 @@ +import { NuxtConfig } from '@nuxt/schema'; + +const config: NuxtConfig = { + nuxtTypedRouter: { + strict: true, + }, +}; +export default config; diff --git a/test/unit/setupTypeTest.ts b/test/unit/setupTypeTest.ts new file mode 100644 index 0000000..5196dd3 --- /dev/null +++ b/test/unit/setupTypeTest.ts @@ -0,0 +1,11 @@ +import { timeout } from '$$/utils'; +import { $ } from 'zx'; + +export async function setupNuxtTestWithConfig(configName: string) { + try { + await $`NUXT_ROUTER_CONFIG_NAME=${configName} pnpm run test:types-fixtures`; + await timeout(100); + } catch (e) { + return Promise.reject(`Typecheck failed for config: [${configName}]: ${e}`); + } +} diff --git a/test/unit/unitTestAllConfigs.spec.ts b/test/unit/unitTestAllConfigs.spec.ts new file mode 100644 index 0000000..11a5292 --- /dev/null +++ b/test/unit/unitTestAllConfigs.spec.ts @@ -0,0 +1,15 @@ +import path from 'path'; +import { setupNuxtTestWithConfig } from './setupTypeTest'; +import { globby } from 'globby'; + +describe.sequential('Testing types with different configs', async () => { + try { + const allConfigs = await globby('test/samples-config', { absolute: false }); + for (let config of allConfigs) { + const configFileName = path.parse(config).name; + await setupNuxtTestWithConfig(configFileName); + } + } catch (e: any) { + throw new Error(e); + } +}); diff --git a/test/utils/index.ts b/test/utils/index.ts index 7da0ba4..ee894da 100644 --- a/test/utils/index.ts +++ b/test/utils/index.ts @@ -1,6 +1,26 @@ -export * from './tsd.utils'; -export * from './typecheck'; +import type { NuxtConfig } from '@nuxt/schema'; +import { globbySync } from 'globby'; export function timeout(count: number) { return new Promise((resolve) => setTimeout(resolve, count)); } + +export function getConfigFromName(configName: string, config: NuxtConfig): NuxtConfig { + const files = globbySync(`test/fixtures/sample-project/tests/[${configName}]`); + return { + ...config, + nuxtTypedRouter: { + ...config.nuxtTypedRouter, + ignoreRoutes: ['[...404].vue', '[tests]/**/*.vue'], + }, + typescript: { + tsConfig: { + files: [ + ...files.map((m) => m.replace('test/fixtures/sample-project', '..')), + `../src/pages/[tests]/[${configName}].vue`, + ], + exclude: ['../tests/**/*', '../src/pages/[tests]/**/*.vue'], + }, + }, + }; +} diff --git a/test/utils/tsd.utils.ts b/test/utils/tsd.utils.ts deleted file mode 100644 index c9fdc10..0000000 --- a/test/utils/tsd.utils.ts +++ /dev/null @@ -1,21 +0,0 @@ -import path from 'path'; -import tsd from 'tsd'; - -export async function runTypesDiagnostics(dirName: string, fileName: string) { - const diagnostic = await tsd({ - cwd: dirName, - testFiles: [path.basename(fileName)], - typingsFile: `./${path.basename(fileName)}`, - }); - - if (diagnostic.length) { - console.error( - diagnostic.map( - (m) => `Error in file ${m.fileName}:${m.line}:${m.column}: - ${m.message}` - ) - ); - } - - return diagnostic; -} diff --git a/test/utils/typecheck.ts b/test/utils/typecheck.ts deleted file mode 100644 index e13fb6a..0000000 --- a/test/utils/typecheck.ts +++ /dev/null @@ -1,8 +0,0 @@ -// Check required param -export function required(arg: string) {} - -// Check optional param -export function optional(arg: undefined extends T ? T : never) {} - -// Check array params -export function array(arg: string[]) {} diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..7ae9a3d --- /dev/null +++ b/vercel.json @@ -0,0 +1,5 @@ +{ + "github": { + "silent": true + } +} diff --git a/vite.config.ts b/vite.config.ts index 71af7e8..dfc7885 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,8 +4,18 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { globals: true, - testTimeout: 10000, - threads: false, + passWithNoTests: true, + pool: 'forks', + poolOptions: { + forks: { + singleFork: true, + }, + }, + sequence: { + concurrent: false, + hooks: 'list', + setupFiles: 'list', + }, }, resolve: { alias: {