forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlive-reload.ts
More file actions
172 lines (160 loc) · 5.99 KB
/
live-reload.ts
File metadata and controls
172 lines (160 loc) · 5.99 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
export default function temporarilyDisabledTest() { return Promise.resolve(); }
// import * as os from 'os';
// import * as _ from 'lodash';
// import * as express from 'express';
// import * as http from 'http';
// import {appendToFile, writeMultipleFiles, writeFile} from '../../utils/fs';
// import {
// killAllProcesses,
// execAndWaitForOutputToMatch,
// waitForAnyProcessOutputToMatch
// } from '../../utils/process';
// import { wait } from '../../utils/utils';
// export default function () {
// const protractorGoodRegEx = /Jasmine started/;
// const webpackGoodRegEx = /: Compiled successfully./;
// // Create an express api for the Angular app to call.
// const app = express();
// const server = http.createServer(app);
// let liveReloadCount = 0;
// function resetApiVars() {
// liveReloadCount = 0;
// }
// server.listen(0);
// app.set('port', server.address().port);
// const firstLocalIp = _(os.networkInterfaces())
// .values()
// .flatten()
// .filter({ family: 'IPv4', internal: false })
// .map('address')
// .first();
// const publicHost = `${firstLocalIp}:4200`;
// const apiUrl = `http://localhost:${server.address().port}`;
// // This endpoint will be pinged by the main app on each reload.
// app.get('/live-reload-count', _ => liveReloadCount++);
// const proxyConfigFile = 'proxy.config.json';
// const proxyConfig = {
// '/live-reload-count': {
// target: apiUrl
// }
// };
// return Promise.resolve()
// .then(_ => writeMultipleFiles({
// 'src/app/app.module.ts': `
// import { BrowserModule } from '@angular/platform-browser';
// import { NgModule } from '@angular/core';
// import { FormsModule } from '@angular/forms';
// import { HttpModule } from '@angular/http';
// import { AppComponent } from './app.component';
// @NgModule({
// declarations: [
// AppComponent
// ],
// imports: [
// BrowserModule,
// FormsModule,
// HttpModule
// ],
// providers: [],
// bootstrap: [AppComponent]
// })
// export class AppModule { }
// `,
// // e2e test that just opens the page and waits, so that the app runs.
// './e2e/app.e2e-spec.ts': `
// import { browser } from 'protractor';
// describe('master-project App', function() {
// it('should wait', _ => {
// browser.get('/');
// browser.sleep(30000);
// });
// });
// `,
// // App that calls the express server once.
// './src/app/app.component.ts': `
// import { Component } from '@angular/core';
// import { Http } from '@angular/http';
// @Component({
// selector: 'app-root',
// template: '<h1>Live reload test</h1>'
// })
// export class AppComponent {
// constructor(private http: Http) {
// http.get('${apiUrl + '/live-reload-count'}').subscribe(res => null);
// }
// }
// `
// }))
// .then(_ => execAndWaitForOutputToMatch(
// 'ng',
// ['e2e', '--watch', '--live-reload'],
// protractorGoodRegEx
// ))
// // Let app run.
// .then(_ => wait(2000))
// .then(_ => appendToFile('src/main.ts', 'console.log(1);'))
// .then(_ => waitForAnyProcessOutputToMatch(webpackGoodRegEx, 10000))
// .then(_ => wait(2000))
// .then(_ => {
// if (liveReloadCount != 2) {
// throw new Error(
// `Expected API to have been called 2 times but it was called ${liveReloadCount} times.`
// );
// }
// })
// .then(_ => killAllProcesses(), (err) => { killAllProcesses(); throw err; })
// .then(_ => resetApiVars())
// // Serve with live reload off should call api only once.
// .then(_ => execAndWaitForOutputToMatch(
// 'ng',
// ['e2e', '--watch', '--no-live-reload'],
// protractorGoodRegEx
// ))
// .then(_ => wait(2000))
// .then(_ => appendToFile('src/main.ts', 'console.log(1);'))
// .then(_ => waitForAnyProcessOutputToMatch(webpackGoodRegEx, 10000))
// .then(_ => wait(2000))
// .then(_ => {
// if (liveReloadCount != 1) {
// throw new Error(
// `Expected API to have been called 1 time but it was called ${liveReloadCount} times.`
// );
// }
// })
// .then(_ => killAllProcesses(), (err) => { killAllProcesses(); throw err; })
// .then(_ => resetApiVars())
// // Serve with live reload client set to api should call api.
// .then(() => writeFile(proxyConfigFile, JSON.stringify(proxyConfig, null, 2)))
// // Update the component to call the webserver
// .then(() => writeFile('./src/app/app.component.ts',
// `
// import { Component } from '@angular/core';
// import { Http } from '@angular/http';
// @Component({
// selector: 'app-root',
// template: '<h1>Live reload test</h1>'
// })
// export class AppComponent {
// constructor(private http: Http) {
// http.get('http://${publicHost + '/live-reload-count'}').subscribe(res => null);
// }
// }`))
// .then(_ => execAndWaitForOutputToMatch(
// 'ng',
// ['e2e', '--watch', '--host=0.0.0.0', '--port=4200', `--public-host=${publicHost}`, '--proxy', proxyConfigFile],
// protractorGoodRegEx
// ))
// .then(_ => wait(2000))
// .then(_ => appendToFile('src/main.ts', 'console.log(1);'))
// .then(_ => waitForAnyProcessOutputToMatch(webpackGoodRegEx, 10000))
// .then(_ => wait(2000))
// .then(_ => {
// if (liveReloadCount != 2) {
// throw new Error(
// `Expected API to have been called 2 times but it was called ${liveReloadCount} times.`
// );
// }
// })
// .then(_ => killAllProcesses(), (err) => { killAllProcesses(); throw err; })
// .then(_ => server.close(), (err) => { server.close(); throw err; });
// }