|
| 1 | +import {CliFs, inject} from "@tsed/cli-core"; |
| 2 | +import {CliPlatformTest, FakeCliFs} from "@tsed/cli-testing"; |
| 3 | + |
| 4 | +import {ProjectClient} from "./ProjectClient.js"; |
| 5 | + |
| 6 | +describe("ProjectClient", () => { |
| 7 | + beforeEach(() => |
| 8 | + CliPlatformTest.bootstrap({ |
| 9 | + project: { |
| 10 | + rootDir: "./project-name", |
| 11 | + srcDir: "src" |
| 12 | + } |
| 13 | + }) |
| 14 | + ); |
| 15 | + afterEach(() => CliPlatformTest.reset()); |
| 16 | + |
| 17 | + it("should create a ts source file from string content", async () => { |
| 18 | + const project = new ProjectClient({ |
| 19 | + rootDir: "./project-name" |
| 20 | + }); |
| 21 | + |
| 22 | + const source = await project.createSource("src/Server.ts", "export class Server {}"); |
| 23 | + |
| 24 | + expect(source?.getBaseName()).toBe("Server.ts"); |
| 25 | + expect(source?.getText()).toContain("export class Server"); |
| 26 | + expect(FakeCliFs.files.get("project-name/src/Server.ts")).toContain("export class Server"); |
| 27 | + }); |
| 28 | + |
| 29 | + it("should create a ts source file from a structure", async () => { |
| 30 | + const project = new ProjectClient({ |
| 31 | + rootDir: "./project-name" |
| 32 | + }); |
| 33 | + |
| 34 | + const source = await project.createSource("src/config/config.ts", { |
| 35 | + statements: ["export const config = {};"] |
| 36 | + }); |
| 37 | + |
| 38 | + expect(source?.getBaseName()).toBe("config.ts"); |
| 39 | + expect(source?.getText()).toContain("export const config"); |
| 40 | + |
| 41 | + const fs = inject(CliFs); |
| 42 | + const content = await fs.readFile("project-name/src/config/config.ts", "utf8"); |
| 43 | + |
| 44 | + expect(content).toContain("export const config"); |
| 45 | + }); |
| 46 | +}); |
0 commit comments