-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Upgrade to storybook v8 #44041
Upgrade to storybook v8 #44041
Conversation
I still need to resolve this error (which makes no sense to me yet. its talking about some other name?)
|
🤖 Vercel preview here: https://docs-1udnodud2-goteleport.vercel.app/docs/ver/preview |
🤖 Vercel preview here: https://docs-p8zhhqtag-goteleport.vercel.app/docs/ver/preview |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Geez, that's a ton of work with those msw
changes. 🥵 Thanks a ton for doing this.
web/.storybook/main.ts
Outdated
@@ -63,7 +63,8 @@ const config: StorybookConfig = { | |||
if (plugin && 'name' in plugin) { | |||
return ( | |||
plugin.name !== 'teleport-html-plugin' && | |||
plugin.name !== 'teleport-transform-html-plugin' | |||
plugin.name !== 'teleport-transform-html-plugin' && | |||
plugin.name !== 'storybook:react-docgen-plugin' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you leave a comment explaining why we need to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have to disable this plugin. It didn't work because Storybook still uses babel for the Vite framework and our babel config wasn't fully configured.
After I added typescript preset to it, the errors gone away (I have it in the patch above).
web/packages/teleport/src/Discover/ConnectMyComputer/SetupConnect/SetupConnect.story.tsx
Outdated
Show resolved
Hide resolved
@@ -105,11 +105,11 @@ export const PollingSuccess = () => ( | |||
PollingSuccess.parameters = { | |||
msw: { | |||
handlers: [ | |||
rest.get(cfg.api.nodesPath, (req, res, ctx) => { | |||
return res.once(ctx.json({ items: [] })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PollingSuccess
was not the only story that was supposed to use res.once
. AFAIK, at the time of the upgrade to v7, all of the uses of res.once
in teleport.e were unnecessary (see https://github.com/gravitational/teleport.e/pull/3256/commits/5d0367d6cceedc71a62f7fe425873820ca6df1c0), but there was a couple of places in OSS that actually do needed it.
Could you go through them on master and add { once: true }
where necessary? I found that just going to the web
dir and grepping for res.once
is good enough.
@@ -30,6 +30,9 @@ module.exports = { | |||
transformIgnorePatterns: [`/node_modules/(?!${esModules})`], | |||
coverageReporters: ['text-summary', 'lcov'], | |||
testPathIgnorePatterns: ['e2e'], | |||
testEnvironmentOptions: { | |||
customExportConditions: [''], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it had to do with the setupServer
from msw but, I never got that working anyway. I'll fiddle around with those tests some more and if this is needed, I'll add a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we do still need it for setupServer
in our tests. More info here in migration guide
https://mswjs.io/docs/migrations/1.x-to-2.x/#cannot-find-module-mswnode-jsdom
I think I'll need another set of eyes on this So far, everything seems to match the migration guide. I'm sure it's a small config issue I'm not seeing |
package.json
Outdated
@@ -41,7 +41,9 @@ | |||
"x-default-browser": "^0.5.2" | |||
}, | |||
"devDependencies": { | |||
"@storybook/react": "^6.5.16", | |||
"@storybook/components": "^8.2.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need this package.
package.json
Outdated
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing new line.
web/.storybook/main.ts
Outdated
const config: StorybookConfig = { | ||
stories: createStoriesPaths(), | ||
framework: { | ||
name: getAbsolutePath('@storybook/react-vite'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works without getAbsolutePath
too.
web/.storybook/main.ts
Outdated
@@ -63,7 +63,8 @@ const config: StorybookConfig = { | |||
if (plugin && 'name' in plugin) { | |||
return ( | |||
plugin.name !== 'teleport-html-plugin' && | |||
plugin.name !== 'teleport-transform-html-plugin' | |||
plugin.name !== 'teleport-transform-html-plugin' && | |||
plugin.name !== 'storybook:react-docgen-plugin' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have to disable this plugin. It didn't work because Storybook still uses babel for the Vite framework and our babel config wasn't fully configured.
After I added typescript preset to it, the errors gone away (I have it in the patch above).
Applied and patch and removed the extra loaders/initialize callsites. the rest of the stories are much smoother/work more reliably but the SetupConnect/PollingSuccess still breaks horrendously and then any story used after is broke. Diving in more |
I still need to fix the
|
package.json
Outdated
"@storybook/react": "^8.2.2", | ||
"@storybook/react-vite": "^8.2.2", | ||
"@storybook/components": "^8.2.3", | ||
"@storybook/addon-toolbars": "^8.2.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was required to make the theme switcher work again
@@ -26,11 +26,11 @@ const enterpriseTeleportExists = fs.existsSync( | |||
); | |||
|
|||
function createStoriesPaths() { | |||
const stories = ['../packages/**/*.story.@(ts|tsx)']; | |||
const stories = ['../packages/**/*.story.@(ts|tsx|js|jsx)']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also have really old files that end in jsx
, i put js
just in case?
fa6fb1b
to
abb94e4
Compare
i clicked through every story and fixed almost everything (EXCEPT teleterm... i couldn't handle it anymore, so i'll leave those to rafal or gz): see abb94e4 and https://github.com/gravitational/teleport.e/pull/3256/commits/ba1271c6faff653308e03292dcaacef918c8a1be
Here are some things i noticed:
|
web/.storybook/vite.config.mts
Outdated
|
||
export default defineConfig(() => ({ | ||
// We don't use `reactPlugin` (which imports @vitejs/plugin-react-swc under the hood) | ||
// because Storybook doesn't support SWC compilter in Vite-based projects. | ||
// Once it's available, migrate from babel. | ||
plugins: [tsconfigPathsPlugin()], | ||
plugins: [tsconfigPathsPlugin(), reactPlugin('')], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was required for the styled-component css
attribute to work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, the comment says we don't use reactPlugin
, yet it's clearly used here. What don't I understand?
(Also: would you mind putting this statement directly into the code comment?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this happens. Looks like babel-plugin-styled-components
is not transforming the css prop (but I believe it should). I couldn't find anything useful in the storybook docs and issues, but I will keeping looking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't understand it either, i just removed the comment for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave up on that, I don't know why it doesn't work with the babel plugin alone. I only corrected the mode passed to the react plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get this when I open http://localhost:9002/?path=/story/teleport-discover-connectmycomputer-setupconnect--polling
(which is a completely different story).
[MSW] Uncaught exception in the request handler for "GET http://localhost:9002/packages/teleport/src/Discover/ConnectMyComputer/TestConnection/TestConnection.story.tsx":
(bunch of indecipherable stacktrace)
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/recipes/mocking-error-responses
This seems like Vite failing when Storybook asks for that file. @gzdunek I believe not importing the general vite config might be a good idea, but it looks like we're missing something still.
web/packages/teleport/src/Discover/ConnectMyComputer/SetupConnect/SetupConnect.story.tsx
Outdated
Show resolved
Hide resolved
web/packages/teleport/src/Discover/ConnectMyComputer/SetupConnect/SetupConnect.story.tsx
Outdated
Show resolved
Hide resolved
web/packages/teleport/src/Discover/Database/DeployService/AutoDeploy/AutoDeploy.tsx
Outdated
Show resolved
Hide resolved
@@ -40,6 +40,7 @@ import { | |||
import { EnrollRdsDatabase } from './EnrollRdsDatabase'; | |||
|
|||
const defaultIsCloud = cfg.isCloud; | |||
const databasesPathWithoutQuery = cfg.api.databasesPath.split('?')[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an api path with query params (with a question mark), makes stories break (and it starts breaking other stories). i found this issue which i took it to mean it's not supported (how did it work before)? i worked around this by stripping the affected path anything after the
?
It might have been something related to msw 1.x, I vaguely remember getting this error in v7 update but I'm not sure.
Currently, I see this when I open http://localhost:9002/?path=/story/teleporte-accesslists-list--list-unlimited
.
[MSW] Found a redundant usage of query parameters in the request handler URL for "GET /v1/webapi/roles?startKey=&search=&limit=". Please match against a path instead and access query parameters using "new URL(request.url).searchParams" instead. Learn more: https://mswjs.io/docs/recipes/query-parameters
It comes from e/web/teleport/src/AccessListManagement/CreateAccessList/CreateAccessList.story.tsx
.
I believe we should figure out why it was working, why it got broken, and how we're going to address this. Manually splitting the path in each story might not be the best way long term.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it'd be possible to override cfg.api
within storybook so that it returns some kind of a proxy object with a custom getter that always strips the query params?
Maybe there's a simpler way to replace the whole cfg.api
in storybook with a version that doesn't use query params. We probably don't want to touch teleport/src/config.ts
itself that much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we can setup something that will remove query params. i saw it somewhere in the msw docs, I'll look around again today
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if the query params weren't in the cfg, it's one of the things blocking the upgrade to react-router 6 😔
Completely out of scope for this PR though of course
Removing the query param made most of the stories ( The next step is finding out how to handle missing web assets?
althought it isn't really breaking stories for me. I go to the locked access requests story and the images are there and works. It's actually all running for me quite well now. I'll happily update all the stories that use query param urls if we are ok with this solution. i was hoping that we'd be able to somehow update the handler to do it for us automatically but then i realized that some stories might want access to the unfiltered query params so, i think just doing it manual is fine. |
I'll rebase this onto the pnpm master today |
In general, stories seem to work now. stories with I disabled one test because jest gets rid of a bunch of globals that |
b999365
to
619fdf2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -17,6 +17,7 @@ | |||
*/ | |||
|
|||
import React from 'react'; | |||
import 'whatwg-fetch'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
documenting here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned on Slack, it might be better to move that to the patched JSDOM env. If that doesn't work, the file with test setup for Jest would be another good candidate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the patched JSDOM didn't work, but putting into setup test for jest did
web/packages/build/storybook.ts
Outdated
@@ -1,6 +1,6 @@ | |||
/* | |||
* Teleport | |||
* Copyright (C) 2024 Gravitational, Inc. | |||
* Copyright (C) 2023 Gravitational, Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't have been changed
@@ -11,8 +11,8 @@ | |||
"build-term": "pnpm --filter=@gravitational/teleterm build", | |||
"start-term": "pnpm --filter=@gravitational/teleterm start", | |||
"package-term": "pnpm --filter=@gravitational/teleterm package", | |||
"storybook": "start-storybook -p 9002 -c web/.storybook -s web/.storybook/public", | |||
"storybook-smoke-test": "pnpm storybook --ci --smoke-test", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pnpm
web/.storybook/preview.tsx
Outdated
import { bblpTheme, darkTheme, lightTheme } from '../packages/design/src/theme'; | ||
import DefaultThemeProvider from '../packages/design/src/ThemeProvider'; | ||
import Box from '../packages/design/src/Box'; | ||
import '../packages/teleport/src/lib/polyfillRandomUuid'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this polyfill.
web/packages/build/package.json
Outdated
"typescript-eslint": "^7.14.1", | ||
"vite-plugin-wasm": "^3.3.0", | ||
"vite-tsconfig-paths": "^4.3.2" | ||
}, | ||
"devDependencies": { | ||
"memfs": "^4.9.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's used in an external script but perhaps it can be removed from here
web/packages/build/vite/config.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can rollback all changes in this file? We no longer have VITE_NO_PROXY
.
web/.storybook/vite.config.mts
Outdated
|
||
export default defineConfig(() => ({ | ||
// We don't use `reactPlugin` (which imports @vitejs/plugin-react-swc under the hood) | ||
// because Storybook doesn't support SWC compilter in Vite-based projects. | ||
// Once it's available, migrate from babel. | ||
plugins: [tsconfigPathsPlugin()], | ||
plugins: [tsconfigPathsPlugin(), reactPlugin('')], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave up on that, I don't know why it doesn't work with the babel plugin alone. I only corrected the mode passed to the react plugin.
web/packages/teleport/src/Discover/ConnectMyComputer/TestConnection/TestConnection.story.tsx
Show resolved
Hide resolved
web/packages/teleport/src/Discover/Kubernetes/HelmChart/HelmChart.story.tsx
Show resolved
Hide resolved
web/packages/teleport/src/Discover/Kubernetes/HelmChart/HelmChart.story.tsx
Outdated
Show resolved
Hide resolved
@@ -17,6 +17,7 @@ | |||
*/ | |||
|
|||
import React from 'react'; | |||
import 'whatwg-fetch'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned on Slack, it might be better to move that to the patched JSDOM env. If that doesn't work, the file with test setup for Jest would be another good candidate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
@@ -36,12 +36,16 @@ | |||
} | |||
}, | |||
"devDependencies": { | |||
"@storybook/react": "^6.5.16", | |||
"@gravitational/build": "workspace:*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this needs to be here. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the vite config filein storybook wasn't able to find this package without having this here. i could use relative paths but i wanted to keep the import cleaner
f0ac6fa
to
43589b1
Compare
New branch which brings in the changes from #37331 . It was easier to do it this way over a rebase since the OG pr is a bit out of date
enterprise: https://github.com/gravitational/teleport.e/pull/3256
Closes gravitational/teleport-private#1494