Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
7eac93f8
Commit
7eac93f8
authored
Jan 31, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[skip ci] simplify mock for feature testing
parent
75d3e3c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
18 deletions
+3
-18
contextWithFeatures.ts
playwright/fixtures/contextWithFeatures.ts
+1
-1
useFeatureValue.js
playwright/mocks/lib/growthbook/useFeatureValue.js
+2
-17
No files found.
playwright/fixtures/contextWithFeatures.ts
View file @
7eac93f8
...
...
@@ -9,7 +9,7 @@ interface Feature {
export
default
function
contextWithFeaturesFixture
(
envs
:
Array
<
Feature
>
):
Parameters
<
typeof
test
.
extend
>
[
0
][
'
context
'
]
{
return
async
({
browser
},
use
)
=>
{
const
storageItems
=
envs
.
map
(({
id
,
value
})
=>
({
name
:
`pw_feature:
${
id
}
`
,
value
:
JSON
.
stringify
(
{
value
,
type
:
typeof
value
}
)
}));
const
storageItems
=
envs
.
map
(({
id
,
value
})
=>
({
name
:
`pw_feature:
${
id
}
`
,
value
:
JSON
.
stringify
(
value
)
}));
const
context
=
await
createContextWithStorage
(
browser
,
storageItems
);
await
use
(
context
);
...
...
playwright/mocks/lib/growthbook/useFeatureValue.js
View file @
7eac93f8
const
useFeatureValue
=
(
name
,
fallback
)
=>
{
try
{
const
{
value
,
type
}
=
JSON
.
parse
(
localStorage
.
getItem
(
`pw_feature:
${
name
}
`
));
const
formattedValue
=
(()
=>
{
switch
(
type
)
{
case
'
boolean
'
:
{
return
value
===
'
true
'
;
}
case
'
number
'
:
{
return
Number
(
value
);
}
default
:
return
value
;
}
})();
return
{
isLoading
:
false
,
value
:
formattedValue
};
const
value
=
JSON
.
parse
(
localStorage
.
getItem
(
`pw_feature:
${
name
}
`
));
return
{
isLoading
:
false
,
value
};
}
catch
(
error
)
{
return
{
isLoading
:
false
,
value
:
fallback
};
}
...
...
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