Skip to content

Commit

Permalink
test: add test for exportEqualsDeclarations
Browse files Browse the repository at this point in the history
  • Loading branch information
velut committed Jan 16, 2024
1 parent 5492c3f commit b5d55c3
Showing 1 changed file with 129 additions and 0 deletions.
129 changes: 129 additions & 0 deletions src/export-equals-declarations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import dedent from "ts-dedent";
import {
ModuleKind,
ModuleResolutionKind,
Project,
ScriptTarget,
} from "ts-morph";
import { expect, test } from "vitest";
import { exportEqualsDeclarations } from "./export-equals-declarations";

test("shorthand ambient module", () => {
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.d.ts",
dedent`
declare module 'foo';
`,
);
expect(
exportEqualsDeclarations("", indexFile.getModuleOrThrow("'foo'")),
).toStrictEqual([]);
});

test("export default", () => {
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`
export default function() {}
`,
);
expect(exportEqualsDeclarations("", indexFile)).toStrictEqual([]);
});

test("export equals expression", () => {
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`
export = 42;
`,
);
expect(exportEqualsDeclarations("", indexFile)).toStrictEqual([]);
});

test("export equals identifier", () => {
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`
declare function foo(s: string): func1.Interface1;
export = foo;
`,
);
expect(exportEqualsDeclarations("", indexFile).at(0)?.exportName).toBe("foo");
});

test("export equals identifier hidden", () => {
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`
/** @internal */
declare function foo(s: string): func1.Interface1;
export = foo;
`,
);
expect(exportEqualsDeclarations("", indexFile)).toStrictEqual([]);
});

test("export equals identifier namespace", () => {
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`
declare namespace foo {};
export = foo;
`,
);
expect(exportEqualsDeclarations("", indexFile)).toStrictEqual([]);
});

0 comments on commit b5d55c3

Please sign in to comment.