fix(aio): simplify GaService to avoid e2e test failures
The GaService and the E2E specs were unnecessarily complicated and had arbitrary async timeouts to ensure that the interplay between the GA library code and the rest of the app worked correctly. This resulted in potential flaky tests if the timeouts were not adequate; this was experienced when Travis upgraded to Chrome 62. The new approach is to block loading of the Analytics library altogether if there is a `__e2e__` flag set in the `SessionStorage` of the browser. It doesn't appear to be enough just to set the flag directly on the window. I think this is because the window gets cleaned when navigation occurs (but I am not certain). The downside of this is that we had to add a small piece of extra logic to the GA snippet in index.html; and we also had to switch from using `<script async ...>` to a programmatic approach to loading the GA library which prevents the browser from eagerly fetching the library. This may be mitigated by adding it to the HTTP/2 push configuration of the Firebase hosting. Re-enables the test that was disabled in https://github.com/angular/angular/pull/19784 Closes #19785
This commit is contained in:

committed by
Alex Rickabaugh

parent
14380ff086
commit
441e01c568
@ -68,30 +68,33 @@ describe('site App', function() {
|
||||
|
||||
// TODO(https://github.com/angular/angular/issues/19785): Activate this again
|
||||
// once it is no more flaky.
|
||||
xdescribe('google analytics', () => {
|
||||
beforeEach(done => page.gaReady.then(done));
|
||||
|
||||
it('should call ga', done => {
|
||||
page.ga()
|
||||
.then(calls => {
|
||||
expect(calls.length).toBeGreaterThan(2, 'ga calls');
|
||||
done();
|
||||
});
|
||||
});
|
||||
describe('google analytics', () => {
|
||||
|
||||
it('should call ga with initial URL', done => {
|
||||
let path: string;
|
||||
|
||||
page.navigateTo('api');
|
||||
page.locationPath()
|
||||
.then(p => path = p)
|
||||
.then(() => page.ga().then(calls => {
|
||||
expect(calls.length).toBeGreaterThan(2, 'ga calls');
|
||||
expect(calls[1]).toEqual(['set', 'page', path]);
|
||||
// The last call (length-1) will be the `send` command
|
||||
// The second to last call (length-2) will be the command to `set` the page url
|
||||
expect(calls[calls.length - 2]).toEqual(['set', 'page', path]);
|
||||
done();
|
||||
}));
|
||||
});
|
||||
|
||||
// Todo: add test to confirm tracking URL when navigate.
|
||||
it('should call ga with new URL on navigation', done => {
|
||||
let path: string;
|
||||
page.getLink('features').click();
|
||||
page.locationPath()
|
||||
.then(p => path = p)
|
||||
.then(() => page.ga().then(calls => {
|
||||
// The last call (length-1) will be the `send` command
|
||||
// The second to last call (length-2) will be the command to `set` the page url
|
||||
expect(calls[calls.length - 2]).toEqual(['set', 'page', path]);
|
||||
done();
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('search', () => {
|
||||
|
Reference in New Issue
Block a user