Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide disableTimer option for testing #23

Merged
merged 1 commit into from
Sep 20, 2024
Merged
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
2 changes: 1 addition & 1 deletion apps/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@coinbase/cookie-banner": "1.0.4",
"@coinbase/cookie-manager": "1.1.7",
"@coinbase/cookie-manager": "1.1.8",
"next": "14.1.1",
"react": "^18",
"react-dom": "^18"
Expand Down
2 changes: 1 addition & 1 deletion packages/cookie-banner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"react-dom": "^18.1.0"
},
"dependencies": {
"@coinbase/cookie-manager": "^1.1.7",
"@coinbase/cookie-manager": "^1.1.8",
"react-intl": "^6.5.1",
"styled-components": "^5.3.6"
}
Expand Down
4 changes: 4 additions & 0 deletions packages/cookie-manager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.1.8 (09/18/2024)

- Introduce an optional `disableTimer` prop in `CookieProvider` to enhance testing flexibility and prevent conflicts with frequently used functions such as `runAllTimers` and `advanceTimersByTime`.

## 1.1.7 (07/17/2024)

- Include Tracker in the list of exported types
Expand Down
2 changes: 1 addition & 1 deletion packages/cookie-manager/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coinbase/cookie-manager",
"version": "1.1.7",
"version": "1.1.8",
"description": "Coinbase Cookie Manager",
"main": "dist/index.js",
"license": "Apache-2.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/cookie-manager/src/CookieContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const CookieProvider = ({ children }: Props) => {
onPreferenceChange,
initialCookieValues,
initialGPCValue,
disableTimer,
} = useTrackingManager();

const POLL_INTERVAL = 500;
Expand Down Expand Up @@ -109,6 +110,12 @@ export const CookieProvider = ({ children }: Props) => {
}
};

// We provide a disableTimer option to avoid setting the interval and potentially introducing issues in timer related tests.
// This is meant to be used in testing only!
if (disableTimer == true) {
return () => {};
}

checkCookies();
// Call the function once before setting the interval
const intervalId = setInterval(checkCookies, POLL_INTERVAL);
Expand All @@ -118,6 +125,7 @@ export const CookieProvider = ({ children }: Props) => {
};
}
}, []);

useEffect(() => {
if (onPreferenceChange) {
onPreferenceChange(trackingPreference);
Expand Down
4 changes: 4 additions & 0 deletions packages/cookie-manager/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export type TrackingManagerDependencies = {
log: LogFunction;
initialCookieValues?: Record<string, string>;
initialGPCValue?: boolean;
// We provide a disableTimer option to avoid setting an interval for
// periodically checking cookies. This is meant to be used in testing only to
// avoid issues with timer related tests.
disableTimer?: boolean;
};

export type AdTrackingPreference = {
Expand Down
Loading