-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathpoll_spec.ts
49 lines (42 loc) · 1.52 KB
/
poll_spec.ts
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
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Architect } from '@angular-devkit/architect';
import { debounceTime, take, tap } from 'rxjs/operators';
import { createArchitect, host } from '../../test-utils';
describe('Browser Builder poll', () => {
const target = { project: 'app', target: 'build' };
let architect: Architect;
beforeEach(async () => {
await host.initialize().toPromise();
architect = (await createArchitect(host.root())).architect;
});
afterEach(async () => host.restore().toPromise());
it('works', async () => {
const overrides = { watch: true, poll: 10000 };
const intervals: number[] = [];
let startTime: number | undefined;
const run = await architect.scheduleTarget(target, overrides);
await run.output.pipe(
// Debounce 1s, otherwise changes are too close together and polling doesn't work.
debounceTime(1000),
tap((buildEvent) => {
expect(buildEvent.success).toBe(true);
if (startTime != undefined) {
intervals.push(Date.now() - startTime - 1000);
}
startTime = Date.now();
host.appendToFile('src/main.ts', 'console.log(1);');
}),
take(4),
).toPromise();
intervals.sort();
const median = intervals[Math.trunc(intervals.length / 2)];
expect(median).toBeGreaterThan(3000);
expect(median).toBeLessThan(12000);
});
});