Skip to content

Commit

Permalink
test: add test for exports with identical name
Browse files Browse the repository at this point in the history
  • Loading branch information
velut committed Feb 2, 2024
1 parent 0f84ffe commit 5f88bf1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
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 };",
},
]
`;
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();
});

0 comments on commit 5f88bf1

Please sign in to comment.