-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
generate.controller.integration.spec.ts
63 lines (51 loc) 路 2.01 KB
/
generate.controller.integration.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {GenerateCmd} from "@tsed/cli";
import {CliService, ProjectPackageJson} from "@tsed/cli-core";
import {CliPlatformTest, FakeCliFs} from "@tsed/cli-testing";
import {dirname, resolve} from "path";
import "../../../src";
import {ensureDirSync, existsSync, readFileSync, writeFileSync} from "fs-extra";
const TEMPLATE_DIR = resolve(require.resolve("@tsed/cli"), "..", "..", "templates");
function readFile(file: string, content: string, rewrite = true) {
const path = `${__dirname}/${file}`
ensureDirSync(dirname(path))
if (!existsSync(path) || rewrite) {
writeFileSync(path, content, {encoding: "utf8"});
}
return readFileSync(path, {encoding: "utf8"});
}
describe("Generate DataSource", () => {
beforeEach(() =>
CliPlatformTest.bootstrap({
templateDir: TEMPLATE_DIR,
commands: [GenerateCmd]
})
);
afterEach(() => CliPlatformTest.reset());
it("should generate the template with the right options (simple path)", async () => {
const cliService = CliPlatformTest.get<CliService>(CliService);
const projectPackageJson = CliPlatformTest.get<ProjectPackageJson>(ProjectPackageJson);
projectPackageJson.setRaw({
name: "",
version: "1.0.0",
description: "",
scripts: {},
dependencies: {},
devDependencies: {}
});
await cliService.exec("generate", {
rootDir: "./project-data",
type: "typeorm:datasource",
name: "Test",
typeormDataSource: "typeorm:mysql"
});
expect(FakeCliFs.getKeys()).toEqual([
"project-name/docker-compose.yml",
"project-name/src/datasources",
"project-name/src/datasources/TestDatasource.ts"
]);
const datasource = FakeCliFs.entries.get("project-name/src/datasources/TestDatasource.ts");
expect(datasource).toEqual(readFile("data/TestDatasource.ts.txt", datasource!, false));
const dockerCompose = FakeCliFs.entries.get("project-name/docker-compose.yml");
expect(dockerCompose).toEqual(readFile("data/docker-compose.yml.txt", dockerCompose!, false));
});
});