-
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.
test: add test for exports with identical name
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
test/declarations/__snapshots__/export-variable-and-type-with-identical-name.test.ts.snap
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,24 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`export variable and type with identical name 1`] = ` | ||
[ | ||
{ | ||
"docs": [], | ||
"file": "/index.ts", | ||
"id": "type-alias.foo", | ||
"kind": "type-alias", | ||
"line": 2, | ||
"name": "foo", | ||
"signature": "type foo = string | number;", | ||
}, | ||
{ | ||
"docs": [], | ||
"file": "/index.ts", | ||
"id": "variable.foo", | ||
"kind": "variable", | ||
"line": 3, | ||
"name": "foo", | ||
"signature": "const foo: { a: number };", | ||
}, | ||
] | ||
`; |
37 changes: 37 additions & 0 deletions
37
test/declarations/export-variable-and-type-with-identical-name.test.ts
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,37 @@ | ||
import dedent from "ts-dedent"; | ||
import { | ||
ModuleKind, | ||
ModuleResolutionKind, | ||
Project, | ||
ScriptTarget, | ||
} from "ts-morph"; | ||
import { expect, test } from "vitest"; | ||
import { extractDeclarations } from "../../src"; | ||
|
||
test("export variable and type with identical name", async () => { | ||
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` | ||
// Similar to usage suggested with zod type inference. | ||
export type foo = string | number | ||
export const foo = { a: 1 }; | ||
`, | ||
); | ||
expect( | ||
await extractDeclarations({ | ||
containerName: "", | ||
container: indexFile, | ||
maxDepth: 5, | ||
project, | ||
}), | ||
).toMatchSnapshot(); | ||
}); |