Skip to content

Commit

Permalink
Remove cypress-switches
Browse files Browse the repository at this point in the history
  • Loading branch information
arelra committed Jan 12, 2024
1 parent d5c4923 commit 7b7cec8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 38 deletions.
12 changes: 2 additions & 10 deletions dotcom-rendering/src/components/SetABTests.importable.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { AB } from '@guardian/ab-core';
import type { CoreAPIConfig } from '@guardian/ab-core';
import { AB } from '@guardian/ab-core';
import { getCookie, log } from '@guardian/libs';
import { useEffect, useState } from 'react';
import { getOphan } from '../client/ophan/ophan';
import { tests } from '../experiments/ab-tests';
import { getCypressSwitches } from '../experiments/cypress-switches';
import { runnableTestsToParticipations } from '../experiments/lib/ab-participations';
import { getForcedParticipationsFromUrl } from '../lib/getAbUrlHash';
import { setABTests } from '../lib/useAB';
Expand Down Expand Up @@ -67,10 +66,6 @@ export const SetABTests = ({
);
}

// Get the forced switches to use for when running within cypress
// Is empty object if not in cypress
const cypressAbSwitches = getCypressSwitches();

const allForcedTestVariants = {
...forcedTestVariants,
...getForcedParticipationsFromUrl(window.location.hash),
Expand All @@ -79,10 +74,7 @@ export const SetABTests = ({
const ab = new AB({
mvtId,
pageIsSensitive,
abTestSwitches: {
...abTestSwitches,
...cypressAbSwitches, // by adding cypress switches below CAPI, we can override any production switch in Cypress
},
abTestSwitches,
arrayOfTestObjects: tests,
forcedTestVariants: allForcedTestVariants,
ophanRecord: ophan.record,
Expand Down
24 changes: 0 additions & 24 deletions dotcom-rendering/src/experiments/cypress-switches.ts

This file was deleted.

13 changes: 9 additions & 4 deletions dotcom-rendering/src/model/enhance-switches.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import type { Switches } from '../types/config';

export type ABTestSwitches = { [key: `ab${string}`]: boolean | undefined };
export type ABTestSwitches = { [key: `ab${string}`]: boolean };

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

/**
* Switches that start with "ab" are used for AB tests.
Expand All @@ -18,6 +25,4 @@ export type ABTestSwitches = { [key: `ab${string}`]: boolean | undefined };
* @returns {ABTestSwitches} an object containing only AB switches
*/
export const filterABTestSwitches = (switches: Switches): ABTestSwitches =>
Object.fromEntries(
Object.entries(switches).filter(([key]) => key.startsWith('ab')),
);
Object.fromEntries(Object.entries(switches).filter(isValidEntry));

0 comments on commit 7b7cec8

Please sign in to comment.