-
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 exportEqualsDeclarations
- Loading branch information
Showing
1 changed file
with
129 additions
and
0 deletions.
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,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([]); | ||
}); |