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
6376115e
Commit
6376115e
authored
Apr 22, 2021
by
jejacks0n
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fetch snowplow contexts for the named experiments
parent
f2aa20ca
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
app/assets/javascripts/experimentation/utils.js
app/assets/javascripts/experimentation/utils.js
+10
-1
spec/frontend/experimentation/utils_spec.js
spec/frontend/experimentation/utils_spec.js
+19
-1
No files found.
app/assets/javascripts/experimentation/utils.js
View file @
6376115e
// This file only applies to use of experiments through https://gitlab.com/gitlab-org/gitlab-experiment
import
{
get
}
from
'
lodash
'
;
import
{
DEFAULT_VARIANT
,
CANDIDATE_VARIANT
}
from
'
./constants
'
;
import
{
DEFAULT_VARIANT
,
CANDIDATE_VARIANT
,
TRACKING_CONTEXT_SCHEMA
}
from
'
./constants
'
;
export
function
getExperimentData
(
experimentName
)
{
return
get
(
window
,
[
'
gon
'
,
'
experiment
'
,
experimentName
]);
}
export
function
getExperimentContexts
(...
experimentNames
)
{
return
experimentNames
.
map
((
name
)
=>
{
const
data
=
getExperimentData
(
name
);
return
data
&&
{
schema
:
TRACKING_CONTEXT_SCHEMA
,
data
};
})
.
filter
((
context
)
=>
context
);
}
export
function
isExperimentVariant
(
experimentName
,
variantName
)
{
return
getExperimentData
(
experimentName
)?.
variant
===
variantName
;
}
...
...
spec/frontend/experimentation/utils_spec.js
View file @
6376115e
import
{
assignGitlabExperiment
}
from
'
helpers/experimentation_helper
'
;
import
{
DEFAULT_VARIANT
,
CANDIDATE_VARIANT
}
from
'
~/experimentation/constants
'
;
import
{
DEFAULT_VARIANT
,
CANDIDATE_VARIANT
,
TRACKING_CONTEXT_SCHEMA
,
}
from
'
~/experimentation/constants
'
;
import
*
as
experimentUtils
from
'
~/experimentation/utils
'
;
describe
(
'
experiment Utilities
'
,
()
=>
{
...
...
@@ -19,6 +23,20 @@ describe('experiment Utilities', () => {
});
});
describe
(
'
getExperimentContexts
'
,
()
=>
{
describe
.
each
`
gon | input | output
${[
TEST_KEY
,
'
_data_
'
]}
|
${[
TEST_KEY
]}
|
${[{
schema
:
TRACKING_CONTEXT_SCHEMA
,
data
:
{
variant
:
'
_data_
'
}
}]}
$
{[]}
|
${[
TEST_KEY
]}
|
${[]}
`
(
'
with input=$input and gon=$gon
'
,
({
gon
,
input
,
output
})
=>
{
assignGitlabExperiment
(...
gon
);
it
(
`returns
${
output
}
`
,
()
=>
{
expect
(
experimentUtils
.
getExperimentContexts
(...
input
)).
toEqual
(
output
);
});
});
});
describe
(
'
isExperimentVariant
'
,
()
=>
{
describe
.
each
`
gon | input | output
...
...
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