Skip to content

Commit

Permalink
Dont modify src during tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dac09 committed May 2, 2022
1 parent 9de17b2 commit 343c156
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
29 changes: 28 additions & 1 deletion tasks/smoke-test/playwright-fixtures/storybook.fixture.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -23,6 +26,30 @@ const test = base.extend<any, StorybookFixture>({
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) {
Expand All @@ -46,7 +73,7 @@ const test = base.extend<any, StorybookFixture>({
// 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,
Expand Down
26 changes: 1 addition & 25 deletions tasks/smoke-test/tests/storybook.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}/`
Expand Down

0 comments on commit 343c156

Please sign in to comment.