|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { generateDTS } from './generateDTS' |
| 3 | + |
| 4 | +describe('generateDTS', () => { |
| 5 | + it('generates a well-formed dts file', () => { |
| 6 | + expect( |
| 7 | + generateDTS({ |
| 8 | + routesModule: 'vue-router/auto-routes', |
| 9 | + routeNamedMap: 'export interface RouteNamedMap {}', |
| 10 | + routeFileInfoMap: 'export interface _RouteFileInfoMap {}', |
| 11 | + paramsTypesDeclaration: '', |
| 12 | + customParamsTypeList: [], |
| 13 | + }) |
| 14 | + ).toMatchInlineSnapshot(` |
| 15 | + "/* eslint-disable */ |
| 16 | + /* prettier-ignore */ |
| 17 | + // oxfmt-ignore |
| 18 | + // @ts-nocheck |
| 19 | + // noinspection ES6UnusedImports |
| 20 | + // Generated by vue-router. !! DO NOT MODIFY THIS FILE !! |
| 21 | + // It's recommended to commit this file. |
| 22 | + // Make sure to add this file to your tsconfig.json file as an "includes" or "files" entry. |
| 23 | +
|
| 24 | + import type { |
| 25 | + RouteRecordInfo, |
| 26 | + ParamValue, |
| 27 | + ParamValueOneOrMore, |
| 28 | + ParamValueZeroOrMore, |
| 29 | + ParamValueZeroOrOne, |
| 30 | + } from 'vue-router' |
| 31 | + import type { |
| 32 | + _ExtractParamParserType, |
| 33 | + } from 'vue-router/experimental' |
| 34 | +
|
| 35 | + declare module 'vue-router' { |
| 36 | + interface TypesConfig { |
| 37 | + ParamParsers: |
| 38 | +
|
| 39 | + } |
| 40 | + } |
| 41 | +
|
| 42 | + declare module 'vue-router/auto-routes' { |
| 43 | + /** |
| 44 | + * Route name map generated by vue-router |
| 45 | + */ |
| 46 | + export interface RouteNamedMap {} |
| 47 | +
|
| 48 | + /** |
| 49 | + * Route file to route info map by vue-router. |
| 50 | + * Used by the \\\`sfc-typed-router\\\` Volar plugin to automatically type \\\`useRoute()\\\`. |
| 51 | + * |
| 52 | + * Each key is a file path relative to the project root with 2 properties: |
| 53 | + * - routes: union of route names of the possible routes when in this page (passed to useRoute<...>()) |
| 54 | + * - views: names of nested views (can be passed to <RouterView name="...">) |
| 55 | + * |
| 56 | + * @internal |
| 57 | + */ |
| 58 | + export interface _RouteFileInfoMap {} |
| 59 | +
|
| 60 | + /** |
| 61 | + * Get a union of possible route names in a certain route component file. |
| 62 | + * Used by the \\\`sfc-typed-router\\\` Volar plugin to automatically type \\\`useRoute()\\\`. |
| 63 | + * |
| 64 | + * @internal |
| 65 | + */ |
| 66 | + export type _RouteNamesForFilePath<FilePath extends string> = |
| 67 | + _RouteFileInfoMap extends Record<FilePath, infer Info> |
| 68 | + ? Info['routes'] |
| 69 | + : keyof RouteNamedMap |
| 70 | + } |
| 71 | +
|
| 72 | + export {} |
| 73 | + " |
| 74 | + `) |
| 75 | + }) |
| 76 | +}) |
0 commit comments