Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit c8c6772

Browse files
committed
refactor(serve): add if statement around error logging, fix tests
add if statement around error logging, fix tests
1 parent f2262ba commit c8c6772

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/serve.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as network from './util/network';
1313
describe('test serve', () => {
1414
let configResults: ServeConfig;
1515
let context: BuildContext;
16+
let openSpy: jasmine.Spy;
1617

1718
beforeEach(() => {
1819
context = {
@@ -43,7 +44,7 @@ describe('test serve', () => {
4344
spyOn(liveReloadServer, 'createLiveReloadServer');
4445
spyOn(httpServer, 'createHttpServer');
4546
spyOn(watch, 'watch').and.returnValue(Promise.resolve());
46-
spyOn(open, 'default');
47+
openSpy = spyOn(open, 'default');
4748
});
4849

4950
it('should work with no args on a happy path', () => {
@@ -52,7 +53,8 @@ describe('test serve', () => {
5253
expect(notificationServer.createNotificationServer).toHaveBeenCalledWith(configResults);
5354
expect(liveReloadServer.createLiveReloadServer).toHaveBeenCalledWith(configResults);
5455
expect(httpServer.createHttpServer).toHaveBeenCalledWith(configResults);
55-
expect(open.default).toHaveBeenCalledWith('http://localhost:8100', null);
56+
expect(openSpy.calls.mostRecent().args[0]).toEqual('http://localhost:8100');
57+
expect(openSpy.calls.mostRecent().args[1]).toEqual(null);
5658
});
5759
});
5860

@@ -65,7 +67,8 @@ describe('test serve', () => {
6567
expect(notificationServer.createNotificationServer).toHaveBeenCalledWith(configResults);
6668
expect(liveReloadServer.createLiveReloadServer).toHaveBeenCalledWith(configResults);
6769
expect(httpServer.createHttpServer).toHaveBeenCalledWith(configResults);
68-
expect(open.default).toHaveBeenCalledWith('http://localhost:8100?ionicplatform=android', null);
70+
expect(openSpy.calls.mostRecent().args[0]).toEqual('http://localhost:8100?ionicplatform=android');
71+
expect(openSpy.calls.mostRecent().args[1]).toEqual(null);
6972
});
7073
});
7174

@@ -103,7 +106,8 @@ describe('test serve', () => {
103106
expect(notificationServer.createNotificationServer).toHaveBeenCalledWith(configResults);
104107
expect(liveReloadServer.createLiveReloadServer).toHaveBeenCalledWith(configResults);
105108
expect(httpServer.createHttpServer).toHaveBeenCalledWith(configResults);
106-
expect(open.default).toHaveBeenCalledWith('http://127.0.0.1:8101/ionic-lab', 'safari');
109+
expect(openSpy.calls.mostRecent().args[0]).toEqual('http://127.0.0.1:8101/ionic-lab');
110+
expect(openSpy.calls.mostRecent().args[1]).toEqual('safari');
107111
});
108112
});
109113
});

src/serve.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ function onReady(config: ServeConfig, context: BuildContext) {
7777
.concat(platformOption(context) ? ['?ionicplatform=', platformOption(context)] : []);
7878

7979
open(openOptions.join(''), browserToLaunch(context), (error: Error) => {
80-
const errorMessage = error && error.message ? error.message : error.toString();
81-
Logger.warn(`Failed to open the browser: ${errorMessage}`);
80+
if (error) {
81+
const errorMessage = error && error.message ? error.message : error.toString();
82+
Logger.warn(`Failed to open the browser: ${errorMessage}`);
83+
}
8284
});
8385
}
8486
Logger.info(`dev server running: ${config.hostBaseUrl}/`, 'green', true);

0 commit comments

Comments
 (0)