Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
5fc702af
Commit
5fc702af
authored
Nov 04, 2021
by
eugielimpin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow "control" and "candidate" function names
parent
a44cff16
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
8 deletions
+24
-8
app/assets/javascripts/experimentation/utils.js
app/assets/javascripts/experimentation/utils.js
+3
-3
spec/frontend/experimentation/utils_spec.js
spec/frontend/experimentation/utils_spec.js
+21
-5
No files found.
app/assets/javascripts/experimentation/utils.js
View file @
5fc702af
...
@@ -26,14 +26,14 @@ export function getExperimentVariant(experimentName) {
...
@@ -26,14 +26,14 @@ export function getExperimentVariant(experimentName) {
return
getExperimentData
(
experimentName
)?.
variant
||
DEFAULT_VARIANT
;
return
getExperimentData
(
experimentName
)?.
variant
||
DEFAULT_VARIANT
;
}
}
export
function
experiment
(
experimentName
,
variants
)
{
export
function
experiment
(
experimentName
,
{
use
,
control
,
candidate
,
...
variants
}
)
{
const
variant
=
getExperimentVariant
(
experimentName
);
const
variant
=
getExperimentVariant
(
experimentName
);
switch
(
variant
)
{
switch
(
variant
)
{
case
DEFAULT_VARIANT
:
case
DEFAULT_VARIANT
:
return
variants
.
use
.
call
();
return
(
use
||
control
)
.
call
();
case
CANDIDATE_VARIANT
:
case
CANDIDATE_VARIANT
:
return
variants
.
try
.
call
();
return
(
variants
.
try
||
candidate
)
.
call
();
default
:
default
:
return
variants
[
variant
].
call
();
return
variants
[
variant
].
call
();
}
}
...
...
spec/frontend/experimentation/utils_spec.js
View file @
5fc702af
...
@@ -85,20 +85,22 @@ describe('experiment Utilities', () => {
...
@@ -85,20 +85,22 @@ describe('experiment Utilities', () => {
});
});
describe
(
'
experiment
'
,
()
=>
{
describe
(
'
experiment
'
,
()
=>
{
const
useSpy
=
jest
.
fn
();
const
controlSpy
=
jest
.
fn
();
const
controlSpy
=
jest
.
fn
();
const
trySpy
=
jest
.
fn
();
const
candidateSpy
=
jest
.
fn
();
const
candidateSpy
=
jest
.
fn
();
const
getUpStandUpSpy
=
jest
.
fn
();
const
getUpStandUpSpy
=
jest
.
fn
();
const
variants
=
{
const
variants
=
{
use
:
control
Spy
,
use
:
use
Spy
,
try
:
candidate
Spy
,
try
:
try
Spy
,
get_up_stand_up
:
getUpStandUpSpy
,
get_up_stand_up
:
getUpStandUpSpy
,
};
};
describe
(
'
when there is no experiment data
'
,
()
=>
{
describe
(
'
when there is no experiment data
'
,
()
=>
{
it
(
'
calls control variant
'
,
()
=>
{
it
(
'
calls control variant
'
,
()
=>
{
experimentUtils
.
experiment
(
'
marley
'
,
variants
);
experimentUtils
.
experiment
(
'
marley
'
,
variants
);
expect
(
control
Spy
).
toHaveBeenCalled
();
expect
(
use
Spy
).
toHaveBeenCalled
();
});
});
});
});
...
@@ -107,7 +109,14 @@ describe('experiment Utilities', () => {
...
@@ -107,7 +109,14 @@ describe('experiment Utilities', () => {
it
(
'
calls the control variant
'
,
()
=>
{
it
(
'
calls the control variant
'
,
()
=>
{
experimentUtils
.
experiment
(
'
marley
'
,
variants
);
experimentUtils
.
experiment
(
'
marley
'
,
variants
);
expect
(
controlSpy
).
toHaveBeenCalled
();
expect
(
useSpy
).
toHaveBeenCalled
();
});
describe
(
"
when 'control' is provided instead of 'use'
"
,
()
=>
{
it
(
'
calls the control variant
'
,
()
=>
{
experimentUtils
.
experiment
(
'
marley
'
,
{
control
:
controlSpy
});
expect
(
controlSpy
).
toHaveBeenCalled
();
});
});
});
});
});
...
@@ -116,7 +125,14 @@ describe('experiment Utilities', () => {
...
@@ -116,7 +125,14 @@ describe('experiment Utilities', () => {
it
(
'
calls the candidate variant
'
,
()
=>
{
it
(
'
calls the candidate variant
'
,
()
=>
{
experimentUtils
.
experiment
(
'
marley
'
,
variants
);
experimentUtils
.
experiment
(
'
marley
'
,
variants
);
expect
(
candidateSpy
).
toHaveBeenCalled
();
expect
(
trySpy
).
toHaveBeenCalled
();
});
describe
(
"
when 'candidate' is provided instead of 'try'
"
,
()
=>
{
it
(
'
calls the control variant
'
,
()
=>
{
experimentUtils
.
experiment
(
'
marley
'
,
{
candidate
:
candidateSpy
});
expect
(
candidateSpy
).
toHaveBeenCalled
();
});
});
});
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment