UNPKG

5.03 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var serve = require("./serve");
4var config = require("./util/config");
5var watch = require("./watch");
6var open = require("./util/open");
7var notificationServer = require("./dev-server/notification-server");
8var httpServer = require("./dev-server/http-server");
9var liveReloadServer = require("./dev-server/live-reload");
10var network = require("./util/network");
11describe('test serve', function () {
12 var configResults;
13 var context;
14 var openSpy;
15 beforeEach(function () {
16 context = {
17 rootDir: '/',
18 wwwDir: '/www',
19 buildDir: '/build',
20 };
21 configResults = {
22 httpPort: 8100,
23 hostBaseUrl: 'http://localhost:8100',
24 host: '0.0.0.0',
25 rootDir: '/',
26 wwwDir: '/www',
27 buildDir: '/build',
28 isCordovaServe: false,
29 launchBrowser: true,
30 launchLab: false,
31 browserToLaunch: null,
32 useLiveReload: true,
33 liveReloadPort: 35729,
34 notificationPort: 53703,
35 useServerLogs: false,
36 useProxy: true,
37 notifyOnConsoleLog: false,
38 devapp: false
39 };
40 spyOn(network, 'findClosestOpenPorts').and.callFake(function (host, ports) { return Promise.resolve(ports); });
41 spyOn(notificationServer, 'createNotificationServer');
42 spyOn(liveReloadServer, 'createLiveReloadServer');
43 spyOn(httpServer, 'createHttpServer');
44 spyOn(watch, 'watch').and.returnValue(Promise.resolve());
45 openSpy = spyOn(open, 'default');
46 });
47 it('should work with no args on a happy path', function () {
48 return serve.serve(context).then(function () {
49 expect(network.findClosestOpenPorts).toHaveBeenCalledWith('0.0.0.0', [53703, 35729, 8100]);
50 expect(notificationServer.createNotificationServer).toHaveBeenCalledWith(configResults);
51 expect(liveReloadServer.createLiveReloadServer).toHaveBeenCalledWith(configResults);
52 expect(httpServer.createHttpServer).toHaveBeenCalledWith(configResults);
53 expect(openSpy.calls.mostRecent().args[0]).toEqual('http://localhost:8100');
54 expect(openSpy.calls.mostRecent().args[1]).toEqual(null);
55 });
56 });
57 it('should include ionicplatform in the browser url if platform is passed', function () {
58 config.addArgv('--platform');
59 config.addArgv('android');
60 return serve.serve(context).then(function () {
61 expect(network.findClosestOpenPorts).toHaveBeenCalledWith('0.0.0.0', [53703, 35729, 8100]);
62 expect(notificationServer.createNotificationServer).toHaveBeenCalledWith(configResults);
63 expect(liveReloadServer.createLiveReloadServer).toHaveBeenCalledWith(configResults);
64 expect(httpServer.createHttpServer).toHaveBeenCalledWith(configResults);
65 expect(openSpy.calls.mostRecent().args[0]).toEqual('http://localhost:8100?ionicplatform=android');
66 expect(openSpy.calls.mostRecent().args[1]).toEqual(null);
67 });
68 });
69 it('all args should be set in the config object and should be passed on to server functions', function () {
70 config.setProcessArgs([]);
71 config.addArgv('--serverlogs');
72 configResults.useServerLogs = true;
73 config.addArgv('--consolelogs');
74 configResults.notifyOnConsoleLog = true;
75 config.addArgv('--noproxy');
76 configResults.useProxy = false;
77 config.addArgv('--nolivereload');
78 configResults.useLiveReload = false;
79 config.addArgv('--lab');
80 configResults.launchLab = true;
81 config.addArgv('--browser');
82 config.addArgv('safari');
83 configResults.browserToLaunch = 'safari';
84 config.addArgv('--port');
85 config.addArgv('8101');
86 configResults.httpPort = 8101;
87 config.addArgv('--address');
88 config.addArgv('127.0.0.1');
89 configResults.host = '127.0.0.1';
90 configResults.hostBaseUrl = 'http://127.0.0.1:8101';
91 config.addArgv('--livereload-port');
92 config.addArgv('35730');
93 configResults.liveReloadPort = 35730;
94 config.addArgv('--dev-logger-port');
95 config.addArgv('53704');
96 configResults.notificationPort = 53704;
97 return serve.serve(context).then(function () {
98 expect(network.findClosestOpenPorts).toHaveBeenCalledWith('127.0.0.1', [53704, 35730, 8101]);
99 expect(notificationServer.createNotificationServer).toHaveBeenCalledWith(configResults);
100 expect(liveReloadServer.createLiveReloadServer).toHaveBeenCalledWith(configResults);
101 expect(httpServer.createHttpServer).toHaveBeenCalledWith(configResults);
102 expect(openSpy.calls.mostRecent().args[0]).toEqual('http://127.0.0.1:8101/ionic-lab');
103 expect(openSpy.calls.mostRecent().args[1]).toEqual('safari');
104 });
105 });
106});