Skip to content
This repository was archived by the owner on Mar 28, 2022. It is now read-only.

Commit 496c68f

Browse files
committed
Fix Programmatic CLI init and start manually
1 parent 49befa0 commit 496c68f

5 files changed

Lines changed: 21 additions & 10 deletions

File tree

jest.acceptance.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
clearMocks: true,
77

88
testMatch: ["**/test/acceptance/**/?(*.)+(spec|test).js?(x)"],
9-
//testMatch: ["**/test/acceptance/main/web-tutorial-files-watch.spec.js"],
9+
//testMatch: ["**/test/acceptance/main/programmatic-cli.spec.js"],
1010

1111
// Indicates whether the coverage information should be collected while executing the test
1212
collectCoverage: false,

lib/ProgrammaticCli.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,28 @@ class ProgrammaticCli {
3737
);
3838
}
3939

40-
async start() {
41-
await this._core.init(this._options);
40+
async _startCore(cliEnabled) {
4241
if (!this._coreStarted) {
4342
this._coreStarted = true;
44-
await this._core.start();
43+
await this._core.init(this._options);
44+
this._core.settings.set("cli", cliEnabled);
45+
return this._core.start();
4546
}
47+
return Promise.resolve();
48+
}
49+
50+
async start() {
51+
await this._startCore(true);
4652
if (!this._cliStarted && !this._core.settings.get("cli")) {
4753
this._core.settings.set("cli", true);
4854
this._cliStarted = true;
49-
this._inquirerCli.start();
55+
return this._inquirerCli.start();
5056
}
57+
return Promise.resolve();
5158
}
5259

5360
async initServer() {
54-
await this._core.init(this._options);
55-
this._core.settings.set("cli", false);
56-
return this._core.start();
61+
return this._startCore(false);
5762
}
5863

5964
stopListeningServerWatch() {

lib/core/server/Server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class Server {
141141
return Promise.resolve();
142142
}
143143

144-
start() {
144+
async start() {
145145
this._initServer();
146146
return new Promise(this._startServer);
147147
}

test/acceptance/main/programmatic-cli.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ describe("programmatic Cli", () => {
176176
});
177177
});
178178

179-
describe("when initializing server manually and start after", () => {
179+
describe.only("when initializing server manually and start after", () => {
180180
it("should start server without cli, then start", async () => {
181181
expect.assertions(3);
182182
cli = new CliRunner("init-server.js", {

test/unit/ProgrammaticCli.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ describe("start method", () => {
114114
await cli.initServer();
115115
expect(coreMocks.stubs.instance.start.callCount).toEqual(1);
116116
});
117+
118+
it("should start core only once after calling start", async () => {
119+
await cli.initServer();
120+
await cli.start();
121+
expect(coreMocks.stubs.instance.start.callCount).toEqual(1);
122+
});
117123
});
118124

119125
describe("stopListeningServerWatch method", () => {

0 commit comments

Comments
 (0)