Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13.3k
chore(playwright): combine test configs for themes and modes#29206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fcd51fe
chore(playwright): combine test configs for themes and modes
sean-perkins eb9f5d6
chore: address feedback
sean-perkins c62e19a
fix: make the code 0.0000000000001% faster
sean-perkins 737fbfc
Merge remote-tracking branch 'origin/next' into sp/test-configs
sean-perkins b9215ae
fix: apply test config changes
sean-perkins 00eaaea
Merge branch 'next' into sp/test-configs
sean-perkins 656c744
chore: update palette documentation for test generator
sean-perkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,6 +1,4 @@ | ||
| import { isModeValidForTheme } from '../../../global/ionic-global'; | ||
| export type Mode = 'ios' | 'md'; | ||
| export type Mode = 'ios' | 'md' | 'ionic-ios' | 'ionic-md'; | ||
| export type Direction = 'ltr' | 'rtl'; | ||
| export type Theme = 'ios' | 'md' | 'ionic'; | ||
| @@ -19,9 +17,9 @@ export type ScreenshotFn = (fileName: string) => string; | ||
| export interface TestConfig { | ||
| direction: Direction; | ||
| theme: Theme; | ||
| palette: Palette; | ||
| mode: Mode; | ||
| theme: Theme; | ||
| } | ||
| interface TestUtilities { | ||
| @@ -31,14 +29,36 @@ interface TestUtilities { | ||
| } | ||
| interface TestConfigOption { | ||
| /** | ||
| * The available options to test against. | ||
| * - "ios": Test against iOS theme on iOS mode. | ||
| * - "md": Test against Material Design theme on Material Design mode. | ||
| * - "ionic-ios": Test against Ionic theme on iOS mode. | ||
| * - "ionic-md": Test against Ionic theme on Material Design mode. | ||
| * | ||
| * If unspecified, tests will run against "ios" and "md". | ||
| */ | ||
| modes?: Mode[]; | ||
| /** | ||
| * The text direction to test against. | ||
| * | ||
| * - "ltr": Test against left-to-right direction. | ||
| * - "rtl": Test against right-to-left direction. | ||
| * | ||
| * If unspecified, tests will run against both directions. | ||
| */ | ||
| directions?: Direction[]; | ||
| palettes?: Palette[]; | ||
| /** | ||
| * The individual themes (iOS, Material Design and Ionic) to test | ||
| * against. If unspecified, defaults iOS and Material Design | ||
| * The color palette to test against. | ||
| * | ||
| * - "light": Test against light palette. | ||
| * - "dark": Test against dark palette. | ||
| * - "high-contrast": Test against high contrast light palette. | ||
| * - "high-contrast-dark": Test against high contrast dark palette. | ||
| * | ||
| * If unspecified, tests will run against light theme. | ||
| */ | ||
| themes?: Theme[]; | ||
| palettes?: Palette[]; | ||
| } | ||
| /** | ||
| @@ -48,25 +68,27 @@ interface TestConfigOption { | ||
| * each test title is unique. | ||
| */ | ||
| const generateTitle = (title: string, config: TestConfig): string => { | ||
| const { direction, palette, theme, mode } = config; | ||
| if (theme === mode) { | ||
| /** | ||
| * Fallback to the old test title naming convention | ||
| * when the theme and mode are the same. | ||
| */ | ||
| const { direction, palette, mode, theme } = config; | ||
| /** | ||
| * The iOS theme can only be used with the iOS mode, | ||
| * and the MD theme can only be used with the MD mode. | ||
| * | ||
| * This logic enables the fallback behavior for existing tests, | ||
| * where we only tested against a mode, which accounted for both | ||
| * the theme and mode. | ||
| */ | ||
| if (theme === 'ios' || theme === 'md') { | ||
| if (palette === 'light') { | ||
| /** | ||
| * Ionic has many existing tests that existed prior to | ||
| * the introduction of theme testing. To maintain backwards | ||
| * compatibility, we will not include the theme in the test | ||
| * title if the theme is set to light. | ||
| */ | ||
| return `${title} - ${theme}/${direction}`; | ||
| return `${title} - ${mode}/${direction}`; | ||
| } | ||
| return `${title} - ${theme}/${direction}/${palette}`; | ||
| return `${title} - ${mode}/${direction}/${palette}`; | ||
| } | ||
| return `${title} - ${theme}/${mode}/${direction}/${palette}`; | ||
| @@ -77,24 +99,26 @@ const generateTitle = (title: string, config: TestConfig): string => { | ||
| * and a test config. | ||
| */ | ||
| const generateScreenshotName = (fileName: string, config: TestConfig): string => { | ||
| const { theme, direction, palette, mode } = config; | ||
| if (theme === mode) { | ||
| /** | ||
| * Fallback to the old screenshot naming convention | ||
| * when the theme and mode are the same. | ||
| */ | ||
| const { direction, palette, mode, theme } = config; | ||
| /** | ||
| * The iOS theme can only be used with the iOS mode, | ||
| * and the MD theme can only be used with the MD mode. | ||
| * | ||
| * This logic enables the fallback behavior for existing tests, | ||
| * where we only tested against a mode, which accounted for both | ||
| * the theme and mode. | ||
| */ | ||
| if (theme === 'ios' || theme === 'md') { | ||
liamdebeasi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (palette === 'light') { | ||
| /** | ||
| * Ionic has many existing tests that existed prior to | ||
| * the introduction of theme testing. To maintain backwards | ||
| * compatibility, we will not include the theme in the screenshot | ||
| * name if the theme is set to light. | ||
| */ | ||
| return `${fileName}-${theme}-${direction}.png`; | ||
| return `${fileName}-${mode}-${direction}.png`; | ||
| } | ||
| return `${fileName}-${theme}-${direction}-${palette}.png`; | ||
| return `${fileName}-${mode}-${direction}-${palette}.png`; | ||
| } | ||
| return `${fileName}-${theme}-${mode}-${direction}-${palette}.png`; | ||
| @@ -104,7 +128,7 @@ const generateScreenshotName = (fileName: string, config: TestConfig): string => | ||
| * Given a config generate an array of test variants. | ||
| */ | ||
| export const configs = (testConfig: TestConfigOption = DEFAULT_TEST_CONFIG_OPTION): TestUtilities[] => { | ||
| const { modes, themes, directions } = testConfig; | ||
| const { modes, directions } = testConfig; | ||
| const configs: TestConfig[] = []; | ||
| @@ -113,19 +137,17 @@ export const configs = (testConfig: TestConfigOption = DEFAULT_TEST_CONFIG_OPTIO | ||
| * fall back to the defaults. | ||
| */ | ||
| const processedModes = modes ?? DEFAULT_MODES; | ||
| const processedTheme = themes ?? DEFAULT_THEMES; | ||
| const processedDirection = directions ?? DEFAULT_DIRECTIONS; | ||
| const processedPalette = testConfig.palettes ?? DEFAULT_PALETTES; | ||
| processedModes.forEach((mode) => { | ||
| processedTheme.forEach((theme) => { | ||
| if (!isModeValidForTheme(mode, theme)) { | ||
| return; | ||
| } | ||
| processedDirection.forEach((direction) => { | ||
| processedPalette.forEach((palette) => { | ||
| configs.push({ theme, direction, palette, mode }); | ||
| }); | ||
| const [themeOrCombinedMode, modeName] = mode.split('-') as [Theme, Mode]; | ||
| const parsedTheme = themeOrCombinedMode; | ||
| const parsedMode = modeName ?? themeOrCombinedMode; | ||
| processedDirection.forEach((direction) => { | ||
| processedPalette.forEach((palette) => { | ||
| configs.push({ direction, palette, mode: parsedMode, theme: parsedTheme }); | ||
| }); | ||
| }); | ||
| }); | ||
| @@ -140,13 +162,11 @@ export const configs = (testConfig: TestConfigOption = DEFAULT_TEST_CONFIG_OPTIO | ||
| }; | ||
| const DEFAULT_MODES: Mode[] = ['ios', 'md']; | ||
| const DEFAULT_THEMES: Theme[] = ['ios', 'md']; | ||
| const DEFAULT_DIRECTIONS: Direction[] = ['ltr', 'rtl']; | ||
| const DEFAULT_PALETTES: Palette[] = ['light']; | ||
| const DEFAULT_TEST_CONFIG_OPTION = { | ||
| modes: DEFAULT_MODES, | ||
| themes: DEFAULT_THEMES, | ||
| directions: DEFAULT_DIRECTIONS, | ||
| palettes: DEFAULT_PALETTES, | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.