-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of namespaces. Add tests.
- Loading branch information
Showing
2 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import dedent from "ts-dedent"; | ||
import { | ||
ModuleKind, | ||
ModuleResolutionKind, | ||
Project, | ||
ScriptTarget, | ||
} from "ts-morph"; | ||
import { expect, test } from "vitest"; | ||
import { headText } from "./head-text"; | ||
|
||
test("return text from declaration before body without JSDoc", () => { | ||
const project = new Project({ | ||
useInMemoryFileSystem: true, | ||
compilerOptions: { | ||
lib: ["lib.esnext.full.d.ts"], | ||
target: ScriptTarget.ESNext, | ||
module: ModuleKind.ESNext, | ||
moduleResolution: ModuleResolutionKind.Bundler, | ||
}, | ||
}); | ||
const indexFile = project.createSourceFile( | ||
"index.ts", | ||
dedent` | ||
/** Docs for FooInterface */ | ||
interface FooInterface { | ||
bar: number; | ||
} | ||
/** Docs for FooClass */ | ||
class FooClass extends FooInterface { | ||
bar; | ||
constructor() { | ||
this.bar = 1; | ||
} | ||
} | ||
/** Docs for FooEnum */ | ||
enum FooEnum { | ||
Bar, | ||
Baz | ||
} | ||
/** Docs for FooNamespace */ | ||
namespace FooNamespace { | ||
/** Docs for FooNamespaceClass */ | ||
class FooNamespaceClass { | ||
bar; | ||
constructor() { | ||
this.bar = 1; | ||
} | ||
} | ||
} | ||
`, | ||
); | ||
expect(headText(indexFile.getInterfaceOrThrow("FooInterface"))).toBe( | ||
"interface FooInterface {}", | ||
); | ||
expect(headText(indexFile.getClassOrThrow("FooClass"))).toBe( | ||
"class FooClass extends FooInterface {}", | ||
); | ||
expect(headText(indexFile.getEnumOrThrow("FooEnum"))).toBe("enum FooEnum {}"); | ||
expect(headText(indexFile.getModuleOrThrow("FooNamespace"))).toBe( | ||
"namespace FooNamespace {}", | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters