|
| 1 | +import { dedent } from "ts-dedent"; |
| 2 | +import { ModuleKind, ModuleResolutionKind, Project, ScriptTarget } from "ts-morph"; |
| 3 | +import { expect, test } from "vitest"; |
| 4 | +import { getPackageOverview } from "./get-package-overview.ts"; |
| 5 | + |
| 6 | +test("no overview", () => { |
| 7 | + const project = new Project({ |
| 8 | + useInMemoryFileSystem: true, |
| 9 | + compilerOptions: { |
| 10 | + lib: ["lib.esnext.full.d.ts"], |
| 11 | + target: ScriptTarget.ESNext, |
| 12 | + module: ModuleKind.ESNext, |
| 13 | + moduleResolution: ModuleResolutionKind.Bundler, |
| 14 | + }, |
| 15 | + }); |
| 16 | + const indexFile = project.createSourceFile( |
| 17 | + "index.ts", |
| 18 | + dedent` |
| 19 | + export {}; |
| 20 | + `, |
| 21 | + ); |
| 22 | + expect(getPackageOverview(indexFile)).toBeUndefined(); |
| 23 | +}); |
| 24 | + |
| 25 | +test("with overview", () => { |
| 26 | + const project = new Project({ |
| 27 | + useInMemoryFileSystem: true, |
| 28 | + compilerOptions: { |
| 29 | + lib: ["lib.esnext.full.d.ts"], |
| 30 | + target: ScriptTarget.ESNext, |
| 31 | + module: ModuleKind.ESNext, |
| 32 | + moduleResolution: ModuleResolutionKind.Bundler, |
| 33 | + }, |
| 34 | + }); |
| 35 | + const indexFile = project.createSourceFile( |
| 36 | + "index.ts", |
| 37 | + dedent` |
| 38 | + /** |
| 39 | + @packageDocumentation |
| 40 | + This is the overview. |
| 41 | + */ |
| 42 | +
|
| 43 | + export {}; |
| 44 | + `, |
| 45 | + ); |
| 46 | + expect(getPackageOverview(indexFile)).toBe(dedent` |
| 47 | + /** |
| 48 | + @packageDocumentation |
| 49 | + This is the overview. |
| 50 | + */ |
| 51 | + `); |
| 52 | +}); |
0 commit comments