Skip to content

Commit

Permalink
test: add tests to ensure that document.location is populated (#1112)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Wiles authored and CaerusKaru committed Dec 25, 2018
1 parent 77e298a commit 04a3e27
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
8 changes: 8 additions & 0 deletions integration/express-engine/e2e/helloworld-spec.ts
Expand Up @@ -35,4 +35,12 @@ describe('Hello world E2E Tests', function() {
// Make sure there were no client side errors.
verifyNoBrowserErrors();
});
it('should populate window.location', () => {
// Load the page without waiting for Angular since it is not bootstrapped automatically.
browser.driver.get(browser.baseUrl + 'helloworld');

// Test the contents from the server.
const serverDiv = browser.driver.findElement(by.css('span.href-check'));
expect(serverDiv.getText()).toMatch('http://localhost:9876/helloworld');
});
});
Expand Up @@ -6,12 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Component} from '@angular/core';
import {Component, Inject} from '@angular/core';
import {DOCUMENT} from '@angular/common';

@Component({
selector: 'hello-world-app',
template: `
<div>Hello {{ name }}!</div>
<span class="href-check">{{href}}</span>
`,
styles: [`
div {
Expand All @@ -21,4 +23,10 @@ import {Component} from '@angular/core';
})
export class HelloWorldComponent {
name: string = 'world';
href: string;

constructor(@Inject(DOCUMENT) doc: Document) {
this.href = doc.location.href;
}

}
1 change: 0 additions & 1 deletion integration/express-engine/src/server.ts
Expand Up @@ -33,7 +33,6 @@ app.get('/helloworld', (req: Request, res) =>
bootstrap: HelloWorldServerModuleNgFactory,
req,
document: helloworld,
url: req.url
}, (err, html) => res.send(html))
);

Expand Down
8 changes: 8 additions & 0 deletions integration/hapi-engine/e2e/helloworld-spec.ts
Expand Up @@ -35,4 +35,12 @@ describe('Hello world E2E Tests', function() {
// Make sure there were no client side errors.
verifyNoBrowserErrors();
});
it('should populate window.location', () => {
// Load the page without waiting for Angular since it is not bootstrapped automatically.
browser.driver.get(browser.baseUrl + 'helloworld');

// Test the contents from the server.
const serverDiv = browser.driver.findElement(by.css('span.href-check'));
expect(serverDiv.getText()).toMatch('http://localhost:9876/helloworld');
});
});
10 changes: 9 additions & 1 deletion integration/hapi-engine/src/helloworld/hello-world.component.ts
Expand Up @@ -6,12 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Component} from '@angular/core';
import {Component, Inject} from '@angular/core';
import {DOCUMENT} from '@angular/common';

@Component({
selector: 'hello-world-app',
template: `
<div>Hello {{ name }}!</div>
<span class="href-check">{{href}}</span>
`,
styles: [`
div {
Expand All @@ -21,4 +23,10 @@ import {Component} from '@angular/core';
})
export class HelloWorldComponent {
name: string = 'world';
href: string;

constructor(@Inject(DOCUMENT) doc: Document) {
this.href = doc.location.href;
}

}
4 changes: 2 additions & 2 deletions modules/hapi-engine/src/main.ts
Expand Up @@ -66,9 +66,9 @@ export function ngHapiEngine(options: RenderOptions) {
return Promise.reject(new Error('url is undefined'));
}

const rawUrl = req.url;
const protocol = req.server.info.protocol;
const filePath = <string> req.raw.req.url;
const url = `${rawUrl.protocol || ''}://${rawUrl.host || ''}${rawUrl.path || ''}`;
const url = `${protocol}://${req.info.host}${req.path}`;

options.providers = options.providers || [];

Expand Down

0 comments on commit 04a3e27

Please sign in to comment.