diff --git a/.env.development b/.env.development
index fcf7ceaa..f78972a5 100644
--- a/.env.development
+++ b/.env.development
@@ -68,4 +68,8 @@ NEXT_PUBLIC_URLS_BASE_PATH=/newtab
NEXT_PUBLIC_URLS_USE_TRAILING_SLASH=true
# Media Endpoint
-NEXT_PUBLIC_MEDIA_ENDPOINT=https://dev-tab2017-media.gladly.io
\ No newline at end of file
+NEXT_PUBLIC_MEDIA_ENDPOINT=https://dev-tab2017-media.gladly.io
+
+########## Growthbook ##########
+
+NEXT_PUBLIC_GROWTHBOOK_ENV=dev
\ No newline at end of file
diff --git a/.env.local.info b/.env.local.info
index f0324549..efd9cc4d 100644
--- a/.env.local.info
+++ b/.env.local.info
@@ -26,3 +26,5 @@
##########################################
# As needed, override .env.development
# values here.
+
+NEXT_PUBLIC_GROWTHBOOK_ENV=local
\ No newline at end of file
diff --git a/.env.preview.info b/.env.preview.info
index 2619be16..442b231a 100644
--- a/.env.preview.info
+++ b/.env.preview.info
@@ -67,3 +67,6 @@ COOKIE_SECURE_SAME_SITE_NONE=true
NEXT_PUBLIC_URLS_BASE_PATH=/newtab
NEXT_PUBLIC_URLS_USE_TRAILING_SLASH=true
+########## Growthbook ##########
+
+NEXT_PUBLIC_GROWTHBOOK_ENV=qa
\ No newline at end of file
diff --git a/.env.production.info b/.env.production.info
index bc39310d..d0052d9d 100644
--- a/.env.production.info
+++ b/.env.production.info
@@ -68,3 +68,7 @@ NEXT_PUBLIC_URLS_BASE_PATH=/newtab
NEXT_PUBLIC_URLS_USE_TRAILING_SLASH=true
# Media Endpoint
NEXT_PUBLIC_MEDIA_ENDPOINT=https://prod-tab2017-media.gladly.io
+
+########## Growthbook ##########
+
+NEXT_PUBLIC_GROWTHBOOK_ENV=production
\ No newline at end of file
diff --git a/package.json b/package.json
index 9103a513..5ab5aec2 100644
--- a/package.json
+++ b/package.json
@@ -22,6 +22,7 @@
},
"dependencies": {
"@fontsource/poppins": "^4.5.0",
+ "@growthbook/growthbook-react": "^0.7.0",
"@material-ui/core": "^4.11.2",
"@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^4.11.3-deprecations.1",
diff --git a/src/__mocks__/@growthbook/growthbook-react.js b/src/__mocks__/@growthbook/growthbook-react.js
new file mode 100644
index 00000000..0972f661
--- /dev/null
+++ b/src/__mocks__/@growthbook/growthbook-react.js
@@ -0,0 +1,17 @@
+import features from 'src/features/features.json'
+
+const { GrowthBook, GrowthBookProvider } = jest.requireActual(
+ '@growthbook/growthbook-react'
+)
+const mockGrowthBook = jest.createMockFromModule('@growthbook/growthbook-react')
+
+mockGrowthBook.useGrowthBook = jest.fn(() => {
+ const growthbook = new GrowthBook()
+ growthbook.setFeatures(features)
+ return growthbook
+})
+
+mockGrowthBook.GrowthBook = jest.fn(() => new GrowthBook())
+mockGrowthBook.GrowthBookProvider = GrowthBookProvider
+
+module.exports = mockGrowthBook
diff --git a/src/__tests__/pages/_app.moduleLoad.test.js b/src/__tests__/pages/_app.moduleLoad.test.js
index 8e2d4044..54137660 100644
--- a/src/__tests__/pages/_app.moduleLoad.test.js
+++ b/src/__tests__/pages/_app.moduleLoad.test.js
@@ -268,3 +268,19 @@ describe('_app: router overrides', () => {
})
})
})
+
+describe('_app: GrowthBook', () => {
+ it('initializes app with Growthbook and calls it with features', () => {
+ expect.assertions(1)
+ const { GrowthBook } = require('@growthbook/growthbook-react')
+ const features = require('src/features/features.json')
+ const mockGrowthbook = {
+ setFeatures: jest.fn(),
+ }
+ GrowthBook.mockImplementation(() => mockGrowthbook)
+
+ // eslint-disable-next-line no-unused-expressions
+ require('src/pages/_app').default
+ expect(mockGrowthbook.setFeatures).toHaveBeenCalledWith(features)
+ })
+})
diff --git a/src/__tests__/pages/index.test.js b/src/__tests__/pages/index.test.js
index 613d4da8..e7b7dda2 100644
--- a/src/__tests__/pages/index.test.js
+++ b/src/__tests__/pages/index.test.js
@@ -10,6 +10,7 @@ import {
showMockAchievements,
showBackgroundImages,
showDevelopmentOnlyMissionsFeature,
+ showInternalOnly,
} from 'src/utils/featureFlags'
import flushAllPromises from 'src/utils/testHelpers/flushAllPromises'
import Achievement from 'src/components/Achievement'
@@ -31,6 +32,7 @@ import InviteFriendsIconContainer from 'src/components/InviteFriendsIconContaine
import SquadCounter from 'src/components/SquadCounter'
import UserImpactContainer from 'src/components/UserImpactContainer'
import useCustomTheming from 'src/utils/hooks/useCustomTheming'
+import { useGrowthBook } from '@growthbook/growthbook-react'
jest.mock('uuid')
uuid.mockReturnValue('some-uuid')
@@ -74,6 +76,7 @@ jest.mock('src/components/SquadCounter')
jest.mock('src/components/UserImpactContainer')
jest.mock('src/utils/pageWrappers/CustomThemeHOC')
jest.mock('src/utils/hooks/useCustomTheming')
+jest.mock('@growthbook/growthbook-react')
const setUpAds = () => {
isClientSide.mockReturnValue(true)
@@ -852,4 +855,25 @@ describe('index.js', () => {
'testSetMe'
)
})
+
+ it('calls setFeatures on growthbook with correct values', async () => {
+ expect.assertions(1)
+ const IndexPage = require('src/pages/index').default
+ const mockProps = getMockProps()
+ const mockGrowthbook = {
+ feature: jest.fn().mockReturnValue({ value: true }),
+ setAttributes: jest.fn(),
+ }
+ useGrowthBook.mockReturnValue(mockGrowthbook)
+ mount(
Welcome to our site!
+ ) : null}