From 04ab5edf651d252b76496c18f4b969762aaaa724 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Mon, 10 May 2021 16:57:42 +0300 Subject: [PATCH] test(docs-infra): correctly test URL redirects when the destination URL is also redirected (#42018) Since #41625, `/guide/updating-to-version-10` is being redirected to `https://v11.angular.io/guide/updating-to-version-11`. However, `v11.angular.io` itself is being redirected to `angular.io`, while v11 is the latest stable version. As a result, `/guide/updating-to-version-10` ends up being redirected to `https://angular.io/guide/updating-to-version-11`. Currently, this causes a CI failure in the `aio_monidoting` job ([example failure][1]). This will change once v12 is released as the new stable version. Alternatively, we could update the config and tests to expected `/guide/updating-to-version-10` to be redirected to `https://angular.io/guide/updating-to-version-11`, but that would end up being redirected to `https://angular.io/guide/updating-to-version-12` once v12 would be released, which is different behavior. This commit provides a way to test for redirects when the destination URL is itself redirected to a different URL. This allows us to use the intended URL (for example, `https://v11.angular.io/...`), which will continue to work as expected regardless of what is the latest stable version without causing CI failures. [1]: https://circleci.com/gh/angular/angular/983738 PR Close #42018 --- aio/tests/deployment/e2e/redirection.e2e-spec.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/aio/tests/deployment/e2e/redirection.e2e-spec.ts b/aio/tests/deployment/e2e/redirection.e2e-spec.ts index 7d9b7acaeb..7b64b968e7 100644 --- a/aio/tests/deployment/e2e/redirection.e2e-spec.ts +++ b/aio/tests/deployment/e2e/redirection.e2e-spec.ts @@ -34,9 +34,20 @@ describe(browser.baseUrl, () => { it(`should redirect '${fromUrl}' to '${toUrl}' (${i + 1}/${page.legacyUrls.length})`, async () => { await page.goTo(fromUrl); - const expectedUrl = stripTrailingSlash(/^https?:/.test(toUrl) ? toUrl : page.baseUrl + toUrl); + let expectedUrl = stripTrailingSlash(/^https?:/.test(toUrl) ? toUrl : page.baseUrl + toUrl); const actualUrl = await getCurrentUrl(); + if (actualUrl !== expectedUrl) { + // If the actual URL does not match the expected URL, check whether the expected URL + // itself is also redirected to the actual URL. + await page.goTo(expectedUrl); + const redirectedExpectedUrl = await getCurrentUrl(); + + if (actualUrl === redirectedExpectedUrl) { + expectedUrl = redirectedExpectedUrl; + } + } + expect(actualUrl).toBe(expectedUrl); }, 120000); });