From 5a86bdde0ff985ff1475a76a6f254a2552aeebb9 Mon Sep 17 00:00:00 2001 From: Sem Bauke Date: Wed, 5 Jun 2024 18:53:21 +0200 Subject: [PATCH] feat: convert all redirect tests to Playwright (#55031) --- .../workflows/temporary-container-checks.yml | 2 +- .../redirects/es6-to-basic-javascript.ts | 25 ---- .../learn/redirects/heading-challenge.ts | 13 -- .../default/legacy/redirects/challenges.ts | 52 -------- e2e/redirect.spec.ts | 125 +++++++++--------- 5 files changed, 66 insertions(+), 151 deletions(-) delete mode 100644 cypress/e2e/default/learn/redirects/es6-to-basic-javascript.ts delete mode 100644 cypress/e2e/default/learn/redirects/heading-challenge.ts delete mode 100644 cypress/e2e/default/legacy/redirects/challenges.ts diff --git a/.github/workflows/temporary-container-checks.yml b/.github/workflows/temporary-container-checks.yml index 249069eff77..1a1e3da6b66 100644 --- a/.github/workflows/temporary-container-checks.yml +++ b/.github/workflows/temporary-container-checks.yml @@ -158,4 +158,4 @@ jobs: config: baseUrl=http://localhost:8000 browser: ${{ matrix.browsers }} # Only run one test to keep the run time down. - spec: 'cypress/e2e/default/learn/redirects/es6-to-basic-javascript.ts' + spec: 'cypress/e2e/default/learn/challenges/failed-updates.ts' diff --git a/cypress/e2e/default/learn/redirects/es6-to-basic-javascript.ts b/cypress/e2e/default/learn/redirects/es6-to-basic-javascript.ts deleted file mode 100644 index e92c4c6e96c..00000000000 --- a/cypress/e2e/default/learn/redirects/es6-to-basic-javascript.ts +++ /dev/null @@ -1,25 +0,0 @@ -describe('ES6 to Basic JavaScript redirects', () => { - const basePath = '/learn/javascript-algorithms-and-data-structures'; - - it(`should redirect from ${basePath}/es6/explore-differences-between-the-var-and-let-keywords to ${basePath}/basic-javascript/explore-differences-between-the-var-and-let-keywords`, () => { - cy.visit( - `${basePath}/es6/explore-differences-between-the-var-and-let-keywords` - ); - cy.location().should(loc => { - expect(loc.pathname).to.eq( - `${basePath}/basic-javascript/explore-differences-between-the-var-and-let-keywords` - ); - }); - }); - - it(`should redirect from ${basePath}/es6/declare-a-read-only-variable-with-the-const-keyword to ${basePath}/basic-javascript/declare-a-read-only-variable-with-the-const-keyword`, () => { - cy.visit( - `${basePath}/es6/declare-a-read-only-variable-with-the-const-keyword` - ); - cy.location().should(loc => { - expect(loc.pathname).to.eq( - `${basePath}/basic-javascript/declare-a-read-only-variable-with-the-const-keyword` - ); - }); - }); -}); diff --git a/cypress/e2e/default/learn/redirects/heading-challenge.ts b/cypress/e2e/default/learn/redirects/heading-challenge.ts deleted file mode 100644 index 47035a56bb9..00000000000 --- a/cypress/e2e/default/learn/redirects/heading-challenge.ts +++ /dev/null @@ -1,13 +0,0 @@ -describe('Header to heading element redirect', () => { - const basePath = '/learn/responsive-web-design/applied-visual-design'; - - it(`should redirect from ${basePath}/adjust-the-size-of-a-header-versus-a-paragraph-tag to ${basePath}/adjust-the-size-of-a-heading-element-versus-a-paragraph-element`, () => { - cy.visit(`${basePath}/adjust-the-size-of-a-header-versus-a-paragraph-tag`); - - cy.location().should(loc => { - expect(loc.pathname).to.eq( - `${basePath}/adjust-the-size-of-a-heading-element-versus-a-paragraph-element` - ); - }); - }); -}); diff --git a/cypress/e2e/default/legacy/redirects/challenges.ts b/cypress/e2e/default/legacy/redirects/challenges.ts deleted file mode 100644 index 154efda8878..00000000000 --- a/cypress/e2e/default/legacy/redirects/challenges.ts +++ /dev/null @@ -1,52 +0,0 @@ -const testLocations = { - chalSuper: '/challenges/responsive-web-design', - chalBlock: '/challenges/responsive-web-design/basic-html-and-html5', - chalChallenge: - // eslint-disable-next-line max-len - '/challenges/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements', - learnSuper: '/learn/responsive-web-design/', - learnBlock: '/learn/responsive-web-design/basic-html-and-html5/', - learnChallenge: - // eslint-disable-next-line max-len - '/learn/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements' -}; - -describe('challenges/superblock redirect', function () { - it('redirects to learn/superblock', () => { - cy.visit(testLocations.chalSuper); - - cy.title().should( - 'eq', - 'Legacy Responsive Web Design Challenges | freeCodeCamp.org' - ); - cy.location().should(loc => { - expect(loc.pathname).to.eq(testLocations.learnSuper); - }); - }); -}); - -describe('challenges/superblock/block redirect', function () { - it('redirects to learn/superblock/block', () => { - cy.visit(testLocations.chalBlock); - - cy.title().should('eq', 'Basic HTML and HTML5 | freeCodeCamp.org'); - cy.location().should(loc => { - expect(loc.pathname).to.eq(testLocations.learnBlock); - }); - }); -}); - -describe('challenges/superblock/block/challenge redirect', function () { - it('redirects to learn/superblock/block/challenge', () => { - cy.visit(testLocations.chalChallenge); - - cy.title().should( - 'eq', - // eslint-disable-next-line max-len - 'Basic HTML and HTML5: Say Hello to HTML Elements | freeCodeCamp.org' - ); - cy.location().should(loc => { - expect(loc.pathname).to.eq(testLocations.learnChallenge); - }); - }); -}); diff --git a/e2e/redirect.spec.ts b/e2e/redirect.spec.ts index 88a3d9f57b0..3c15b80cea9 100644 --- a/e2e/redirect.spec.ts +++ b/e2e/redirect.spec.ts @@ -4,69 +4,74 @@ import { test, expect } from '@playwright/test'; // Also, make sure that you have pm2 installed globally via: pnpm install -g pm2 const pathsToTest = [ - { input: '/challenges', expected: '/learn' }, - { - input: '/learn/front-end-libraries', - expected: 'learn/front-end-development-libraries' - }, - { - input: '/learn/front-end-libraries/bootstrap', - expected: 'learn/front-end-development-libraries/bootstrap' - }, - { - input: '/learn/front-end-libraries/front-end-libraries-projects', - expected: - 'learn/front-end-development-libraries/front-end-development-libraries-projects' - }, - { - input: - '/learn/front-end-libraries/front-end-libraries-projects/build-a-random-quote-machine', - expected: - 'learn/front-end-development-libraries/front-end-development-libraries-projects/build-a-random-quote-machine' - }, - { - input: '/certification/certifieduser/front-end-libraries', - expected: 'certification/certifieduser/front-end-development-libraries' - }, - { - input: - '/learn/front-end-libraries/bootstrap/use-responsive-design-with-bootstrap-fluid-containers', - expected: - 'learn/front-end-development-libraries/bootstrap/use-responsive-design-with-bootstrap-fluid-containers' - }, - { - input: '/learn/apis-and-microservices', - expected: 'learn/back-end-development-and-apis' - }, - { - input: '/learn/apis-and-microservices/managing-packages-with-npm', - expected: 'learn/back-end-development-and-apis/managing-packages-with-npm' - }, - { - input: - '/learn/apis-and-microservices/managing-packages-with-npm/how-to-use-package-json-the-core-of-any-node-js-project-or-npm-package', - expected: - 'learn/back-end-development-and-apis/managing-packages-with-npm/how-to-use-package-json-the-core-of-any-node-js-project-or-npm-package' - }, - { - input: '/learn/apis-and-microservices/apis-and-microservices-projects', - expected: - 'learn/back-end-development-and-apis/back-end-development-and-apis-projects' - }, - { - input: - '/learn/apis-and-microservices/apis-and-microservices-projects/timestamp-microservice', - expected: - 'learn/back-end-development-and-apis/back-end-development-and-apis-projects/timestamp-microservice' - }, - { - input: '/certification/certifieduser/apis-and-microservices', - expected: 'certification/certifieduser/back-end-development-and-apis' - } + ['/challenges', '/learn'], + ['/learn/front-end-libraries', 'learn/front-end-development-libraries'], + [ + '/learn/front-end-libraries/bootstrap', + '/learn/front-end-development-libraries/bootstrap' + ], + [ + '/learn/front-end-libraries/front-end-libraries-projects', + '/learn/front-end-development-libraries/front-end-development-libraries-projects' + ], + [ + '/learn/front-end-libraries/front-end-libraries-projects/build-a-random-quote-machine', + '/learn/front-end-development-libraries/front-end-development-libraries-projects/build-a-random-quote-machine' + ], + [ + '/certification/certifieduser/front-end-libraries', + '/certification/certifieduser/front-end-development-libraries' + ], + [ + '/learn/front-end-libraries/bootstrap/use-responsive-design-with-bootstrap-fluid-containers', + '/learn/front-end-development-libraries/bootstrap/use-responsive-design-with-bootstrap-fluid-containers' + ], + ['/learn/apis-and-microservices', 'learn/back-end-development-and-apis'], + [ + '/learn/apis-and-microservices/managing-packages-with-npm', + '/learn/back-end-development-and-apis/managing-packages-with-npm' + ], + [ + '/learn/apis-and-microservices/managing-packages-with-npm/how-to-use-package-json-the-core-of-any-node-js-project-or-npm-package', + '/learn/back-end-development-and-apis/managing-packages-with-npm/how-to-use-package-json-the-core-of-any-node-js-project-or-npm-package' + ], + [ + '/learn/apis-and-microservices/apis-and-microservices-projects', + '/learn/back-end-development-and-apis/back-end-development-and-apis-projects' + ], + [ + '/learn/apis-and-microservices/apis-and-microservices-projects/timestamp-microservice', + '/learn/back-end-development-and-apis/back-end-development-and-apis-projects/timestamp-microservice' + ], + [ + '/certification/certifieduser/apis-and-microservices', + '/certification/certifieduser/back-end-development-and-apis' + ], + [ + '/learn/responsive-web-design/applied-visual-design/adjust-the-size-of-a-header-versus-a-paragraph-tag', + '/learn/responsive-web-design/applied-visual-design/adjust-the-size-of-a-heading-element-versus-a-paragraph-element' + ], + [ + '/learn/javascript-algorithms-and-data-structures/es6/explore-differences-between-the-var-and-let-keywords', + '/learn/javascript-algorithms-and-data-structures/basic-javascript/explore-differences-between-the-var-and-let-keywords' + ], + [ + '/learn/javascript-algorithms-and-data-structures/es6/declare-a-read-only-variable-with-the-const-keyword', + '/learn/javascript-algorithms-and-data-structures/basic-javascript/declare-a-read-only-variable-with-the-const-keyword' + ], + ['/challenges/responsive-web-design', '/learn/responsive-web-design'], + [ + '/challenges/responsive-web-design/basic-html-and-html5', + '/learn/responsive-web-design/basic-html-and-html5' + ], + [ + '/challenges/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements', + '/learn/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements' + ] ]; test.describe('Legacy Challenge Path Redirection Tests', () => { - for (const { input, expected } of pathsToTest) { + for (const [input, expected] of pathsToTest) { test(`should redirect from ${input} to ${expected}`, async ({ page }) => { await page.goto(input); await expect(page).toHaveURL(new RegExp(`${expected}/?`));