Skip to content

Commit 28202a7

Browse files
PR comments.
1 parent fc8c05e commit 28202a7

File tree

2 files changed

+37
-51
lines changed

2 files changed

+37
-51
lines changed

lib/commands/create-project.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ export class CreateProjectCommand implements ICommand {
3939
this.$errors.fail("You cannot use --ng and --template simultaneously.");
4040
}
4141

42-
if (this.$options.ng) {
43-
this.$options.template = constants.ANGULAR_NAME;
44-
}
42+
let selectedTemplate = this.$options.ng ? constants.ANGULAR_NAME : this.$options.template;
4543

46-
this.$projectService.createProject(args[0], this.$options.template).wait();
44+
this.$projectService.createProject(args[0], selectedTemplate).wait();
4745
}).future<void>()();
4846
}
4947

test/project-commands.ts

+35-47
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/// <reference path=".d.ts" />
22
"use strict";
33

4-
import * as yok from "../lib/common/yok";
4+
import { Yok } from "../lib/common/yok";
55
import * as stubs from "./stubs";
66
import { CreateProjectCommand } from "../lib/commands/create-project";
77
import * as constants from "../lib/constants";
88
import {assert} from "chai";
99

1010
let selectedTemplateName: string;
1111
let isProjectCreated: boolean;
12-
let dummyArgsString = "dummyArgsString";
12+
let dummyArgs = ["dummyArgsString"];
1313

1414
class ProjectServiceMock implements IProjectService {
1515
createProject(projectName: string, selectedTemplate?: string): IFuture<void> {
@@ -27,7 +27,7 @@ class ProjectNameValidatorMock implements IProjectNameValidator {
2727
}
2828

2929
function createTestInjector() {
30-
let testInjector = new yok.Yok();
30+
let testInjector = new Yok();
3131

3232
testInjector.register("injector", testInjector);
3333
testInjector.register("staticConfig", {});
@@ -44,70 +44,58 @@ function createTestInjector() {
4444
return testInjector;
4545
}
4646

47-
describe('Project Service Tests', () => {
47+
describe("Project commands tests", () => {
4848
let testInjector: IInjector;
49+
let options: IOptions;
50+
let createProjectCommand: ICommand;
4951

5052
beforeEach(() => {
5153
testInjector = createTestInjector();
5254
isProjectCreated = false;
55+
selectedTemplateName = undefined;
56+
options = testInjector.resolve("$options");
57+
createProjectCommand = testInjector.resolve("$createCommand");
5358
});
5459

55-
describe("project commands tests", () => {
56-
describe("#CreateProjectCommand", () => {
57-
it("should not fail when using only --ng.", () => {
58-
let options: IOptions = testInjector.resolve("$options");
59-
options.ng = true;
60+
describe("#CreateProjectCommand", () => {
61+
it("should not fail when using only --ng.", () => {
62+
options.ng = true;
6063

61-
let createProjectCommand: ICommand = testInjector.resolve("$createCommand");
64+
createProjectCommand.execute(dummyArgs).wait();
6265

63-
createProjectCommand.execute([dummyArgsString]).wait();
64-
65-
assert.isTrue(isProjectCreated);
66-
});
67-
68-
it("should not fail when using only --template.", () => {
69-
let options: IOptions = testInjector.resolve("$options");
70-
options.template = "ng";
71-
72-
let createProjectCommand: ICommand = testInjector.resolve("$createCommand");
73-
74-
createProjectCommand.execute([dummyArgsString]).wait();
75-
76-
assert.isTrue(isProjectCreated);
77-
});
66+
assert.isTrue(isProjectCreated);
67+
});
7868

79-
it("should set the template name correctly when used --ng.", () => {
80-
let options: IOptions = testInjector.resolve("$options");
81-
options.ng = true;
69+
it("should not fail when using only --template.", () => {
70+
options.template = "ng";
8271

83-
let createProjectCommand: ICommand = testInjector.resolve("$createCommand");
72+
createProjectCommand.execute(dummyArgs).wait();
8473

85-
createProjectCommand.execute([dummyArgsString]).wait();
74+
assert.isTrue(isProjectCreated);
75+
});
8676

87-
assert.deepEqual(options.template, constants.ANGULAR_NAME);
88-
});
77+
it("should set the template name correctly when used --ng.", () => {
78+
options.ng = true;
8979

90-
it("should not set the template name when --ng is not used.", () => {
91-
let options: IOptions = testInjector.resolve("$options");
92-
options.ng = false;
80+
createProjectCommand.execute(dummyArgs).wait();
9381

94-
let createProjectCommand: ICommand = testInjector.resolve("$createCommand");
82+
assert.deepEqual(selectedTemplateName, constants.ANGULAR_NAME);
83+
});
9584

96-
createProjectCommand.execute([dummyArgsString]).wait();
85+
it("should not set the template name when --ng is not used.", () => {
86+
options.ng = false;
9787

98-
assert.isUndefined(options.template);
99-
});
88+
createProjectCommand.execute(dummyArgs).wait();
10089

101-
it("should fail when --ng and --template are used simultaneously.", () => {
102-
let options: IOptions = testInjector.resolve("$options");
103-
options.ng = true;
104-
options.template = "ng";
90+
assert.isUndefined(selectedTemplateName);
91+
});
10592

106-
let createProjectCommand: ICommand = testInjector.resolve("$createCommand");
93+
it("should fail when --ng and --template are used simultaneously.", () => {
94+
options.ng = true;
95+
options.template = "ng";
10796

108-
assert.throws(() => {
109-
createProjectCommand.execute([dummyArgsString]).wait();
110-
});
97+
assert.throws(() => {
98+
createProjectCommand.execute(dummyArgs).wait();
11199
});
112100
});
113101
});

0 commit comments

Comments
 (0)