Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: cleanup poll CLI E2E test #12497

Merged
merged 2 commits into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ describe('Browser Builder poll', () => {
beforeEach(done => host.initialize().toPromise().then(done, done.fail));
afterEach(done => host.restore().toPromise().then(done, done.fail));

xit('works', (done) => {
const overrides = { watch: true, poll: 2000 };
it('works', (done) => {
const overrides = { watch: true, poll: 10000 };
const intervals: number[] = [];
let startTime: number | undefined;
runTargetSpec(host, browserTargetSpec, overrides).pipe(
Expand All @@ -30,12 +30,12 @@ describe('Browser Builder poll', () => {
startTime = Date.now();
host.appendToFile('src/main.ts', 'console.log(1);');
}),
take(6),
take(4),
).subscribe(undefined, done.fail, () => {
intervals.sort();
const median = intervals[Math.trunc(intervals.length / 2)];
expect(median).toBeGreaterThan(1000);
expect(median).toBeLessThan(4000);
expect(median).toBeGreaterThan(3000);
expect(median).toBeLessThan(12000);
done();
});
});
Expand Down
46 changes: 18 additions & 28 deletions tests/legacy-cli/e2e/tests/build/poll.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,32 @@
import { appendToFile } from '../../utils/fs';
import {
killAllProcesses,
waitForAnyProcessOutputToMatch,
execAndWaitForOutputToMatch
} from '../../utils/process';
import {appendToFile} from '../../utils/fs';
import {expectToFail, wait} from '../../utils/utils';
import { ngServe } from '../../utils/project';
import { expectToFail, wait } from '../../utils/utils';

const webpackGoodRegEx = /: Compiled successfully./;

export default function() {
// TODO(architect): This test is behaving oddly both here and in devkit/build-angular.
// It seems to be because of file watchers.
return;
export default async function() {
try {
await ngServe('--poll=10000');


// @filipesilva: This test doesn't work correctly on CircleCI while being ran by the test script.
// Polling time seems to be ignored and several builds are fired per second.
// Debugging showed that webpack things the `src/` directory changed on each rebuild.
// Disabling for now.
if (process.env['CIRCLECI']) {
return;
}


return execAndWaitForOutputToMatch('ng', ['build', '--watch', '--poll=10000'], webpackGoodRegEx)
// Wait before editing a file.
// Editing too soon seems to trigger a rebuild and throw polling out of whack.
.then(() => wait(3000))
.then(() => appendToFile('src/main.ts', 'console.log(1);'))
await wait(3000);
await appendToFile('src/main.ts', 'console.log(1);');

// We have to wait poll time + rebuild build time for the regex match.
.then(() => waitForAnyProcessOutputToMatch(webpackGoodRegEx, 14000))
.then(() => appendToFile('src/main.ts', 'console.log(1);'))
await waitForAnyProcessOutputToMatch(webpackGoodRegEx, 14000);

// No rebuilds should occur for a while
.then(() => expectToFail(() => waitForAnyProcessOutputToMatch(webpackGoodRegEx, 7000)))
await appendToFile('src/main.ts', 'console.log(1);');
await expectToFail(() => waitForAnyProcessOutputToMatch(webpackGoodRegEx, 7000));

// But a rebuild should happen roughly within the 10 second window.
.then(() => waitForAnyProcessOutputToMatch(webpackGoodRegEx, 7000))
.then(() => killAllProcesses(), (err: any) => {
killAllProcesses();
throw err;
});
await waitForAnyProcessOutputToMatch(webpackGoodRegEx, 7000);
} finally {
killAllProcesses();
}
}