Skip to content
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

refactor(Blankslate): add support for css modules to Blankslate #4810

Merged
merged 16 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(e2e): add support for feature flags in globals
  • Loading branch information
joshblack committed Aug 1, 2024
commit 099cac3d60e21d4ad07af2673aa13783080b897e
8 changes: 8 additions & 0 deletions e2e/components/Blankslate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ test.describe('Blankslate', () => {
id: story.id,
globals: {
colorScheme: theme,
featureFlags: {
primer_react_css_modules: true,
},
},
})

Expand All @@ -75,6 +78,11 @@ test.describe('Blankslate', () => {
test(`${name} @vrt`, async ({page}) => {
await visit(page, {
id: story.id,
globals: {
featureFlags: {
primer_react_css_modules: true,
},
},
})
const width = viewports[name]

Expand Down
44 changes: 18 additions & 26 deletions e2e/test-helpers/storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,10 @@ export async function visit(page: Page, options: Options) {
let params = ''
for (const [key, value] of Object.entries(globals)) {
if (params !== '') {
params += '&'
params += ';'
}
if (typeof value === 'object') {
const serialized = Object.entries(value)
.map(([key, value]) => {
if (typeof value === 'boolean') {
return [key, `!${!value}`]
}
return [key, value]
})
.join(';')
params += `${key}:${serialized}`
params += serializeObject(value, key)
} else {
params += `${key}:${value}`
}
Expand All @@ -67,21 +59,21 @@ export async function visit(page: Page, options: Options) {
await waitForImages(page)
}

// function serialize(value: Value): string {
// if (typeof value === 'string') {
// return value
// }

// if (typeof value === 'number') {
// return `${value}`;
// }

// if (typeof value === 'boolean') {
// return `!${!value}`;
// }
function serializeObject<T extends {[Key: string]: Value}>(object: T, parentPath: string): string {
return Object.entries(object)
.map(([key, value]) => {
if (typeof value === 'object') {
return serializeObject(value, `${parentPath}.${key}`)
}
return `${parentPath}.${key}:${serialize(value)}`
})
.join(';')
}

// if (typeof value === 'object') {
// }
function serialize(value: Value): string {
if (typeof value === 'boolean') {
return `!${value}`
}

// return value.toString();
// }
return `${value}`
}