Commit 7eac93f8 authored by tom's avatar tom

[skip ci] simplify mock for feature testing

parent 75d3e3c3
......@@ -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);
......
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 };
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment