diff --git a/tasks/smoke-test/playwright-fixtures/storybook.fixture.ts b/tasks/smoke-test/playwright-fixtures/storybook.fixture.ts index cdfc87d23d5d..2a6fe16ed846 100644 --- a/tasks/smoke-test/playwright-fixtures/storybook.fixture.ts +++ b/tasks/smoke-test/playwright-fixtures/storybook.fixture.ts @@ -1,4 +1,7 @@ /* eslint-disable no-empty-pattern */ +import fs from 'fs' +import path from 'path' + import { test as base } from '@playwright/test' import execa from 'execa' import isPortReachable from 'is-port-reachable' @@ -23,6 +26,30 @@ const test = base.extend({ async ({ port }, use) => { console.log('Starting storybook server.....') + const profileStoryPath = path.join( + process.env.PROJECT_PATH, + 'web/src/pages/ProfilePage/ProfilePage.stories.tsx' + ) + + // Modify profile page stories to mockCurrentUser + const profilePageStoryContent = fs.readFileSync(profileStoryPath, 'utf-8') + + if (!profilePageStoryContent.includes('mockCurrentUser')) { + fs.writeFileSync( + profileStoryPath, + profilePageStoryContent.replace( + 'export const generated = () => {', + `export const generated = () => { + mockCurrentUser({ + email: 'ba@zinga.com', + id: 55, + roles: 'ADMIN', + }) + ` + ) + ) + } + const projectPath = process.env.PROJECT_PATH if (!projectPath) { @@ -46,7 +73,7 @@ const test = base.extend({ // Don't wait for this to finish, because it doens't const serverHandler = execa( `yarn rw storybook`, - ['--port', port, '--no-open', '--ci'], + ['--port', `${port}`, '--no-open', '--ci'], { cwd: projectPath, shell: true, diff --git a/tasks/smoke-test/tests/storybook.spec.ts b/tasks/smoke-test/tests/storybook.spec.ts index 7368476e2f5c..4f36516aaf28 100644 --- a/tasks/smoke-test/tests/storybook.spec.ts +++ b/tasks/smoke-test/tests/storybook.spec.ts @@ -92,32 +92,8 @@ storybookTest( ) storybookTest( - 'Mocks current user, and updates UI while dev server is running', + 'Mocks current user, and displays within story', async ({ port, page, server }: PlaywrightTestArgs & StorybookFixture) => { - const profileStoryPath = path.join( - process.env.PROJECT_PATH, - 'web/src/pages/ProfilePage/ProfilePage.stories.tsx' - ) - - // Modify profile page stories to mockCurrentUser - const profilePageStoryContent = fs.readFileSync(profileStoryPath, 'utf-8') - - if (!profilePageStoryContent.includes('mockCurrentUser')) { - fs.writeFileSync( - profileStoryPath, - profilePageStoryContent.replace( - 'export const generated = () => {', - `export const generated = () => { - mockCurrentUser({ - email: 'ba@zinga.com', - id: 55, - roles: 'ADMIN', - }) - ` - ) - ) - } - // We do this to make sure playwright doesn't bring the server down console.log(server) const STORYBOOK_URL = `http://localhost:${port}/`