-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
97 additions
and
21 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { test } from '@playwright/experimental-ct-react'; | ||
|
||
import createContextWithStorage from './createContextWithStorage'; | ||
|
||
interface Feature { | ||
id: string; | ||
value: unknown; | ||
} | ||
|
||
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 context = await createContextWithStorage(browser, storageItems); | ||
|
||
await use(context); | ||
await context.close(); | ||
}; | ||
} |
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,14 @@ | ||
import type { Browser } from '@playwright/test'; | ||
|
||
import * as app from 'playwright/utils/app'; | ||
|
||
export default async function createContextWithEnvs(browser: Browser, localStorage: Array<{ name: string; value: string }>) { | ||
return browser.newContext({ | ||
storageState: { | ||
origins: [ | ||
{ origin: app.url, localStorage }, | ||
], | ||
cookies: [], | ||
}, | ||
}); | ||
} |
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,25 @@ | ||
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 }; | ||
|
||
} catch (error) { | ||
return { isLoading: false, value: fallback }; | ||
} | ||
}; | ||
|
||
export default useFeatureValue; |
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,25 @@ | ||
import { test as base, expect } from '@playwright/experimental-ct-react'; | ||
import React from 'react'; | ||
|
||
import contextWithFeatures from 'playwright/fixtures/contextWithFeatures'; | ||
import TestApp from 'playwright/TestApp'; | ||
|
||
import Login from './Login'; | ||
|
||
const testWithFeature = base.extend({ | ||
context: contextWithFeatures([ | ||
{ id: 'test_value', value: 'kitty' }, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
]) as any, | ||
}); | ||
|
||
testWithFeature('has feature text', async({ mount }) => { | ||
const component = await mount( | ||
<TestApp> | ||
<Login/> | ||
</TestApp>, | ||
); | ||
|
||
const featureText = component.getByText('kitty'); | ||
await expect(featureText).toBeVisible(); | ||
}); |
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