Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions aio/tests/deployment/e2e/redirection.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { SitePage } from './site.po';

describe(browser.baseUrl, () => {
const page = new SitePage();
const getCurrentUrl = async () => (await browser.getCurrentUrl()).replace(/\?.*$/, '');
const prependBaseUrl = (url: string) => browser.baseUrl.replace(/\/$/, '') + url;
const getCurrentUrl = () => browser.getCurrentUrl().then(stripQuery).then(stripTrailingSlash);
const stripQuery = (url: string) => url.replace(/\?.*$/, '');
const stripTrailingSlash = (url: string) => url.replace(/\/$/, '');

beforeAll(done => page.init().then(done));

Expand All @@ -16,7 +17,7 @@ describe(browser.baseUrl, () => {
it(`should not redirect '${url}' (${i + 1}/${page.sitemapUrls.length})`, async () => {
await page.goTo(url);

const expectedUrl = prependBaseUrl(url);
const expectedUrl = stripTrailingSlash(page.baseUrl + url);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not use path.join(page.baseUrl, url) here? That would prevent double slashes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if we used canonical-path (to avoid http:\\foo\bar), path.join() would normalize http://foo to http:/foo 😁

const actualUrl = await getCurrentUrl();

expect(actualUrl).toBe(expectedUrl);
Expand All @@ -29,7 +30,7 @@ describe(browser.baseUrl, () => {
it(`should redirect '${fromUrl}' to '${toUrl}' (${i + 1}/${page.legacyUrls.length})`, async () => {
await page.goTo(fromUrl);

const expectedUrl = /^http/.test(toUrl) ? toUrl : prependBaseUrl(toUrl);
const expectedUrl = stripTrailingSlash(/^http/.test(toUrl) ? toUrl : page.baseUrl + toUrl);
const actualUrl = await getCurrentUrl();

expect(actualUrl).toBe(expectedUrl);
Expand Down Expand Up @@ -66,8 +67,8 @@ describe(browser.baseUrl, () => {
expect(homeNavLink.isPresent()).toBe(true);

await homeNavLink.click();
const expectedUrl = browser.baseUrl;
const actualUrl = await browser.getCurrentUrl();
const expectedUrl = page.baseUrl;
const actualUrl = await getCurrentUrl();

expect(actualUrl).toBe(expectedUrl);
});
Expand Down
5 changes: 4 additions & 1 deletion aio/tests/deployment/e2e/site.po.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { browser, by, element, ExpectedConditions } from 'protractor';

export class SitePage {
/** The base URL with the trailing `/` stripped off (if any). */
baseUrl = browser.baseUrl.replace(/\/$/, '');

/** All URLs found in the app's `sitemap.xml` (i.e. valid URLs tha should not be redirected). */
sitemapUrls: string[] = browser.params.sitemapUrls;

Expand Down Expand Up @@ -44,7 +47,7 @@ export class SitePage {
.then(regs => Promise.all(regs.map(reg => reg.unregister())))
.then(cb);

await browser.get(url || browser.baseUrl);
await browser.get(url || this.baseUrl);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So accessing the browser.baseUrl when it ends in a forward slash errors?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but I want to be consistent 😁

await browser.executeScript('document.body.classList.add(\'no-animations\')');
await browser.executeAsyncScript(unregisterServiceWorker);
await browser.waitForAngular();
Expand Down
1 change: 1 addition & 0 deletions aio/tests/deployment/shared/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function loadLocalSitemapUrls() {
}

export async function loadRemoteSitemapUrls(host: string) {
host = host.replace(/\/$/, '');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could just use path.join(host, 'generated/sitemap.xml') on the following line instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const urlToSiteMap = `${host}/generated/sitemap.xml`;
const get = /^https:/.test(host) ? httpsGet : httpGet;

Expand Down