-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'latest' into switch-to-rambda
- Loading branch information
Showing
50 changed files
with
1,099 additions
and
240 deletions.
There are no files selected for viewing
Binary file renamed
BIN
+43.5 KB
...quest-npm-3.0.1-7528f5a10a-bf48bed6d6.zip → ...quest-npm-3.0.5-ca40027f33-41ea0de43c.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+1.53 MB
...ess-npm-13.10.0-fb5477ef47-d3dbce9a00.zip → ...ess-npm-13.15.0-e45179f623-eb10122347.zip
Binary file not shown.
Binary file removed
BIN
-48.1 KB
.yarn/cache/cypress-terminal-report-npm-6.1.2-304a4d32ad-d8eaaecad3.zip
Binary file not shown.
Binary file added
BIN
+63.2 KB
.yarn/cache/cypress-terminal-report-npm-7.0.4-102b760cbf-253e01855e.zip
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+64.4 KB
...ress-npm-4.20.0-a4b76bf3f8-4131f566cf.zip → ...ress-npm-4.21.1-f1cd48000b-5d4a36dd03.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+14.2 KB
...ature-npm-1.3.6-5b2eff4373-5f08e0c821.zip → ...ature-npm-1.4.0-086af1c8e9-f9f5eed4ac.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+9.55 KB
...atic-npm-1.16.0-88462a5f62-29a01f67e8.zip → ...atic-npm-1.16.2-5d8e560aec-7fa9d9c680.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React from 'react'; | ||
import { render, waitFor } from '../react-testing-library-with-providers'; | ||
import AmpExperiment from './index'; | ||
|
||
const experimentConfig = { | ||
someExperiment: { | ||
variants: { | ||
control: 33, | ||
variant_1: 33, | ||
variant_2: 33, | ||
}, | ||
}, | ||
}; | ||
|
||
const multipleExperimentConfig = { | ||
aExperiment: { | ||
variants: { | ||
control: 33, | ||
variant_1: 33, | ||
variant_2: 33, | ||
}, | ||
}, | ||
bExperiment: { | ||
variants: { | ||
control: 33, | ||
variant_1: 33, | ||
variant_2: 33, | ||
}, | ||
}, | ||
}; | ||
|
||
describe('Amp experiment container on Amp pages', () => { | ||
it('should render an amp-experiment with the expected config', async () => { | ||
const { container } = render( | ||
<AmpExperiment experimentConfig={experimentConfig} />, | ||
); | ||
expect(container.querySelector('amp-experiment')).toBeInTheDocument(); | ||
expect(container).toMatchInlineSnapshot(` | ||
<div> | ||
<amp-experiment> | ||
<script | ||
type="application/json" | ||
> | ||
{"someExperiment":{"variants":{"control":33,"variant_1":33,"variant_2":33}}} | ||
</script> | ||
</amp-experiment> | ||
</div> | ||
`); | ||
}); | ||
|
||
it('should render an amp-experiment with the expected config when multiple experiments are running at the same time', async () => { | ||
const { container } = render( | ||
<AmpExperiment experimentConfig={multipleExperimentConfig} />, | ||
); | ||
expect(container.querySelector('amp-experiment')).toBeInTheDocument(); | ||
expect(container).toMatchInlineSnapshot(` | ||
<div> | ||
<amp-experiment> | ||
<script | ||
type="application/json" | ||
> | ||
{"aExperiment":{"variants":{"control":33,"variant_1":33,"variant_2":33}},"bExperiment":{"variants":{"control":33,"variant_1":33,"variant_2":33}}} | ||
</script> | ||
</amp-experiment> | ||
</div> | ||
`); | ||
}); | ||
|
||
it(`should add amp-experiment extension script to page head`, async () => { | ||
render(<AmpExperiment experimentConfig={experimentConfig} />); | ||
|
||
await waitFor(() => { | ||
const scripts = Array.from(document.querySelectorAll('head script')); | ||
|
||
expect(scripts).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
src: `https://cdn.ampproject.org/v0/amp-experiment-0.1.js`, | ||
}), | ||
]), | ||
); | ||
|
||
expect(scripts).toHaveLength(1); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** @jsx jsx */ | ||
/* @jsxFrag React.Fragment */ | ||
import { jsx } from '@emotion/react'; | ||
import React from 'react'; | ||
import { Helmet } from 'react-helmet'; | ||
|
||
type Variant = string; | ||
type Experiment = string; | ||
type TrafficAllocationPercentage = number; | ||
|
||
type AmpExperimentConfig = { | ||
[key: Experiment]: { | ||
sticky?: boolean; | ||
consentNotificationId?: string; | ||
variants: { | ||
[key: Variant]: TrafficAllocationPercentage; | ||
}; | ||
}; | ||
}; | ||
|
||
type AmpExperimentProps = { | ||
[key: Experiment]: AmpExperimentConfig; | ||
}; | ||
|
||
const AmpHead = () => ( | ||
<Helmet> | ||
<script | ||
async | ||
custom-element="amp-experiment" | ||
src="https://cdn.ampproject.org/v0/amp-experiment-0.1.js" | ||
/> | ||
</Helmet> | ||
); | ||
|
||
const AmpExperiment = ({ experimentConfig }: AmpExperimentProps) => { | ||
return ( | ||
<> | ||
<AmpHead /> | ||
<amp-experiment> | ||
<script | ||
type="application/json" | ||
/* eslint-disable-next-line react/no-danger */ | ||
dangerouslySetInnerHTML={{ __html: JSON.stringify(experimentConfig) }} | ||
/> | ||
</amp-experiment> | ||
</> | ||
); | ||
}; | ||
|
||
export default AmpExperiment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
declare namespace JSX { | ||
interface IntrinsicElements { | ||
'amp-experiment': React.PropsWithChildren< | ||
ScriptHTMLAttributes<HTMLScriptElement> | ||
>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.