Skip to content

Commit c726608

Browse files
Slashgearphilibea
andauthored
feat(growthbook): add new package to mutualise GrowthBook init (#1416)
* feat(abtest): add new package to mutualise GrowthBook init * docs(changeset): add changeset * fix(naming): change naming of the package and add missing files * fix(package): rename package to match others * test(growthbook): add test with jest on provider and hook * feat(growthbook): review comment on typings * docs(growthbook): add doc of package in global Readme * docs(growthbook): fixup typo in package readme * test(provider): add missing test case on init * fix(typings): fix typescript issues on mock --------- Co-authored-by: Antoine Caron <[email protected]> Co-authored-by: philibeaux <[email protected]>
1 parent 83d4ede commit c726608

File tree

24 files changed

+467
-67
lines changed

24 files changed

+467
-67
lines changed

.changeset/funny-mayflies-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@scaleway/ab-test': major
3+
---
4+
5+
Initialize the AB test common package for integration of GrowthBook inside Scaleway frontend apps

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ scaleway-lib is a set of NPM packages used at Scaleway.
7272
![npm bundle size](https://img.shields.io/bundlephobia/min/@scaleway/use-segment)
7373
![npm](https://img.shields.io/npm/v/@scaleway/use-segment)
7474

75+
- [`@scaleway/use-growthbok`](./packages/use-growthbok/README.md):
76+
A tiny hook to handle Growthbook Feature flag and A/B test tool.
77+
78+
![npm](https://img.shields.io/npm/dm/@scaleway/use-growthbok)
79+
![npm bundle size](https://img.shields.io/bundlephobia/min/@scaleway/use-growthbok)
80+
![npm](https://img.shields.io/npm/v/@scaleway/use-growthbok)
81+
7582
- [`@scaleway/use-gtm`](./packages/use-gtm/README.md):
7683
A tiny hook to handle gtm.
7784

packages/jest-helpers/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ Internally it uses the `renderWithTheme` generated from above.
7878
```tsx
7979
const shouldMatchEmotionSnapshot = (
8080
component: ReactNode, // The component to render
81-
options: { // In an object to make it backward-compatible and don't introduce any API breaking changes
81+
options: {
82+
// In an object to make it backward-compatible and don't introduce any API breaking changes
8283
options?: RenderOptions // RenderOptions from @testing-library/react
8384
transform?: (node: ReturnType<typeof render>) => Promise<void> | void // (a)sync function execute between the render and the expect. You can use this if you need mockAllIsIntersecting
8485
theme?: Theme // Optional theme to use which will be passed to the Wrapper above

packages/outdated-browser/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This package is intended to be used in tandem with a bundler
1616
Only one parameter is required, a regex of accepted browser user agents
1717

1818
Example with webpack:
19+
1920
```js
2021
import { getUserAgentRegExp } from 'browserslist-useragent-regexp'
2122

packages/tsconfig/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ Add to your `.tsconfig.json`
1212

1313
```json
1414
{
15-
"extends": "@scaleway/tsconfig"
15+
"extends": "@scaleway/tsconfig"
1616
}
1717
```

packages/use-dataloader/src/__tests__/useDataLoader.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ const wrapperWithCacheKey = ({ children }: { children?: ReactNode }) => (
3737

3838
const wrapperWithOnError =
3939
(onError: (err: Error) => void) =>
40-
({ children }: { children?: ReactNode }) =>
40+
({ children }: { children?: ReactNode }) => (
4141
<DataLoaderProvider onError={onError}>{children}</DataLoaderProvider>
42+
)
4243

4344
describe('useDataLoader', () => {
4445
test('should render correctly without options', async () => {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { join } = require('path')
2+
3+
module.exports = {
4+
rules: {
5+
'import/no-extraneous-dependencies': [
6+
'error',
7+
{ packageDir: [__dirname, join(__dirname, '../../')] },
8+
],
9+
},
10+
}

packages/use-growthbook/.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**/__tests__/**
2+
examples/
3+
src
4+
.eslintrc.cjs
5+
!.npmignore

packages/use-growthbook/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# `@scaleway/use-growthbook`
2+
3+
Tiny adapter to easily add [GrowthBook](https://www.growthbook.io/) to your React Application.
4+
The idea of this package is to propose a _facade pattern_ above GrowthBook React SDK.
5+
6+
## Install
7+
8+
```bash
9+
$ pnpm add @scaleway/use-growthbook
10+
```
11+
12+
## How to use
13+
14+
### First add the provider to your application roots
15+
16+
```js
17+
import { AbTestProvider } from '@scaleway/use-growthbook'
18+
import React from 'react'
19+
import ReactDOM from 'react-dom'
20+
import App from './App'
21+
22+
ReactDOM.render(
23+
<React.StrictMode>
24+
<AbTestProvider
25+
config={{ apiHost: 'string', clientKey: 'string', enableDevMode: true }}
26+
anonymousId="123456789"
27+
trackingCallback={(experiment, result) => console.log(experiment, result)}
28+
errorCallback={console.error}
29+
>
30+
<App />
31+
</AbTestProvider>
32+
</React.StrictMode>,
33+
document.getElementById('root'),
34+
)
35+
```
36+
37+
### Attributes
38+
39+
A hook `useAbTestAttributes` is available to get currentAttributes and to set new ones dynamically.
40+
41+
### API
42+
43+
Exported utils from GrowthBook React are listed here:
44+
45+
- FeatureString
46+
- FeaturesReady
47+
- IfFeatureEnabled
48+
- useExperiment
49+
- useFeature
50+
- withRunExperiment
51+
- useFeatureIsOn
52+
- useFeatureValue
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "@scaleway/use-growthbook",
3+
"version": "0.0.0",
4+
"description": "Utility package to expose AB test tool",
5+
"type": "module",
6+
"engines": {
7+
"node": ">=14.x"
8+
},
9+
"exports": {
10+
"types": "./dist/index.d.ts",
11+
"default": "./dist/index.js"
12+
},
13+
"sideEffects": false,
14+
"publishConfig": {
15+
"access": "public"
16+
},
17+
"repository": {
18+
"type": "git",
19+
"url": "https://github.com/scaleway/scaleway-lib",
20+
"directory": "packages/growthbook"
21+
},
22+
"license": "MIT",
23+
"keywords": [
24+
"ab",
25+
"feature flags"
26+
],
27+
"dependencies": {
28+
"@growthbook/growthbook-react": "0.17.0"
29+
},
30+
"devDependencies": {
31+
"react": "18.2.0"
32+
},
33+
"peerDependencies": {
34+
"react": "18.x"
35+
}
36+
}

0 commit comments

Comments
 (0)