Skip to content

Commit

Permalink
Remove references to Cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
arelra committed Jan 12, 2024
1 parent 9f978f0 commit 90aa830
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 38 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ target
# Test coverage reports
coverage

# Cypress result files
/dotcom-rendering/cypress/screenshots/*
/dotcom-rendering/cypress/videos/*

# Storybook static folder (used if taking snapshots locally)
/storybook-static
**/storybook-static
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/docs/development/ab-testing-in-dcr.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The library docs above explain the integration and the API.
import { useAB } from '../lib/useAB';

// Example usage of AB Tests
// Used in the Cypress tests as smoke test of the AB tests framework integration
// Used in the e2e tests as smoke test of the AB tests framework integration
const ABTestAPI = useAB()?.api;

// We can check if a user is in a variant, returns a boolean
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Test the expected behavior of a component: what it renders, how the props it rec

Look for conditional statements (ternaries, if statements, and switch statements) in the render method for clues about what to test. You should always test your public interface (the props your component takes). For example, if the Component under test takes a prop which is a function that is executed onClick we can test it’s executed by simulating a click on the Component under test.

Alongside jest we use [react-testing-library](https://github.com/kentcdodds/react-testing-library). This a testing utility that allows you to tests against the rendred DOM, output from your component. The utility makes you write tests from a “user-perspective”, asserting against user-facing properties.
Alongside jest we use [react-testing-library](https://github.com/kentcdodds/react-testing-library). This a testing utility that allows you to tests against the rendered DOM, output from your component. The utility makes you write tests from a “user-perspective”, asserting against user-facing properties.

#### Don't test

Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/fixtures/config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 🙏 Only put GLOBAL overrides here 🙏
*
* Any config key value entered here will be used by ALL tests (jest,
* Storybook, Cypress, etc.) and could cause confusing side effects.
* Storybook, Playwright, etc.) and could cause confusing side effects.
*
* If you need to override a value for a specific config property please consider
* doing this locally using a spread operator. Eg.:
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/fixtures/manual/guideAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const defaultStoryExpanded = {
expandCallback: (): null => null,
};

// Non expanded version needed for Cypress
// Non expanded version needed for e2e testing
export const defaultStory = {
id: 'a76d998e-d4b0-4d00-8afb-773eddb4064c',
title: "Wednesday's Hong Kong tips",
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/fixtures/manual/qandaAtom.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Non-expanded version for Cypress tests
// Non-expanded version for e2e tests
export const imageStory = {
id: '78014307-ca67-47dc-b524-d5f24f3dbcd8',
title: 'What is bitcoin?',
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/fixtures/manual/timelineAtom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export const noTimelineEventsStoryExpanded = {
expandCallback: (): null => null,
};

// Non-expanded version for Cypress, it fails if the atom loads already expanded
// Non-expanded version for e2e tests, it fails if the atom loads already expanded
export const noTimelineEventsStory = {
id: '9704dbd0-0273-49d2-8425-c58ccf9a1951',
description:
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/fixtures/switch-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 🙏 Only put GLOBAL overrides here 🙏
*
* Any swtich key value entered here will be used by ALL tests (jest,
* Storybook, Cypress, etc.) and could cause confusing side effects.
* Storybook, Playwright, etc.) and could cause confusing side effects.
*
* If you need to override a value for a specific test please consider doing this
* locally using a spread operator. Eg.:
Expand Down
16 changes: 10 additions & 6 deletions dotcom-rendering/playwright/lib/locators.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { Locator, Page } from '@playwright/test';
import { expect } from '@playwright/test';

const TEN_SECONDS = 10_000;

const expectToBeVisible = async (
page: Page,
selector: string,
nth = 0,
): Promise<void> => {
await expect(page.locator(selector).nth(nth)).toBeVisible({
timeout: 10000,
timeout: TEN_SECONDS,
});
};

Expand All @@ -17,7 +19,7 @@ const expectToNotBeVisible = async (
nth = 0,
): Promise<void> => {
await expect(page.locator(selector).nth(nth)).not.toBeVisible({
timeout: 10000,
timeout: TEN_SECONDS,
});
};

Expand All @@ -27,30 +29,32 @@ const expectToExist = async (
count = 1,
): Promise<void> => {
await expect(page.locator(selector)).toHaveCount(count, {
timeout: 10000,
timeout: TEN_SECONDS,
});
};

const expectToNotExist = async (
page: Page,
selector: string,
): Promise<void> => {
await expect(page.locator(selector)).toHaveCount(0, { timeout: 10000 });
await expect(page.locator(selector)).toHaveCount(0, {
timeout: TEN_SECONDS,
});
};

const expectLocatorToExist = async (
page: Page,
locator: Locator,
count = 1,
): Promise<void> => {
await expect(locator).toHaveCount(count, { timeout: 10000 });
await expect(locator).toHaveCount(count, { timeout: TEN_SECONDS });
};

const expectLocatorToNotExist = async (
page: Page,
locator: Locator,
): Promise<void> => {
await expect(locator).toHaveCount(0, { timeout: 10000 });
await expect(locator).toHaveCount(0, { timeout: TEN_SECONDS });
};

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ test.describe('YouTube Atom', () => {
// Close the sticky video
// A regular click does not work here as the sticky close button requires a hover first
// to make it visible. Even when using hover() Playwright sees the button as invisible and
// Playwright (like Cypress) does not allow clicking on invisible elements. Instead we
// Playwright does not allow clicking on invisible elements. Instead we
// dispatch a click event directly on the element.
await page
.locator(`${stickyCloseSelector}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ test.describe('Commercial E2E tests', () => {

await cmpAcceptAll(page);

// We are excluding survey slot as it only appears via cypress tests and only on frontend.
// Also, we are waiting *up to* 30 seconds here to give the ads time to load. In most
// cases this check will pass much faster
// We are excluding survey slot as they can be switched off
await expectToExist(page, '.js-ad-slot:not([data-name="survey"])', 15);

// Check all inline slots are present
Expand Down
4 changes: 2 additions & 2 deletions dotcom-rendering/src/components/Liveness.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ export const Liveness = ({

useEffect(() => {
/**
* This is a utility used by our Cypress end to end tests
* This is a utility used by our e2e tests
*
* Rather than expect these scripts to depend on polling, we
* expose this function to allow Cypress to manually trigger
* expose this function to allow tests to manually trigger
* updates with whatever html and properties it wants
*
*/
Expand Down
17 changes: 11 additions & 6 deletions dotcom-rendering/src/model/enhance-switches.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { isBoolean } from '@guardian/libs';
import type { Switches } from '../types/config';

export type ABTestSwitches = { [key: `ab${string}`]: boolean };
type ABTestSwitches = { [key: `ab${string}`]: boolean };
type ABTestSwitchesKey = keyof ABTestSwitches;
type ABTestSwitchesValue = ABTestSwitches[ABTestSwitchesKey];

const isValidEntry = (
const isABTestEntry = (
entry: [string, boolean | undefined],
): entry is [string, boolean] => {
): entry is [ABTestSwitchesKey, ABTestSwitchesValue] => {
const [key, value] = entry;
return key.startsWith('ab') && typeof value === 'boolean';
return key.startsWith('ab') && isBoolean(value);
};

/**
Expand All @@ -24,5 +27,7 @@ const isValidEntry = (
* @param {Switches} switches
* @returns {ABTestSwitches} an object containing only AB switches
*/
export const filterABTestSwitches = (switches: Switches): ABTestSwitches =>
Object.fromEntries(Object.entries(switches).filter(isValidEntry));
const filterABTestSwitches = (switches: Switches): ABTestSwitches =>
Object.fromEntries(Object.entries(switches).filter(isABTestEntry));

export { ABTestSwitches, filterABTestSwitches };
9 changes: 1 addition & 8 deletions dotcom-rendering/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,5 @@
},
"preserveConstEnums": true
},
"exclude": [
"cypress",
"./cypress.config.js",
"storybook-static",
"target",
"dist",
"node_modules"
]
"exclude": ["storybook-static", "target", "dist", "node_modules"]
}
1 change: 0 additions & 1 deletion dotcom-rendering/window.guardian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ declare global {
* This gives support across all 3 cases.
*/
guardianPolyfilledImport: (url: string) => Promise<any>; // can't be nested beyond top level
Cypress: any; // for checking if running within cypress
guCmpHotFix: {
initialised?: boolean;
cmp: CMP;
Expand Down

0 comments on commit 90aa830

Please sign in to comment.