-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat(storybook): upgrade to v7 #8342
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
87f58f4
wip upgrade to v7
jtoar dacc5a1
move up for clarity
jtoar 7e4dd57
get smoke-test going, revert most style changes for now
jtoar a333a90
undo more stylistic changes
jtoar cebf300
notes
jtoar 857b67f
update smoke tests
jtoar 914dc2a
Merge branch 'main' into ds-storybook/v7
jtoar b36ebdb
try increasing the timeout
jtoar f3fcdb1
try limiting workers
jtoar 5ecbfce
Merge branch 'main' into ds-storybook/v7
jtoar 6ec6584
fix type error
jtoar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import path from 'path' | ||
|
||
import execa from 'execa' | ||
|
||
import { getPaths } from '@redwoodjs/project-config' | ||
import { errorTelemetry } from '@redwoodjs/telemetry' | ||
|
||
import c from '../lib/colors' | ||
|
||
const redwoodProjectPaths = getPaths() | ||
|
||
export const handler = ({ | ||
build, | ||
buildDirectory, | ||
ci, | ||
open, | ||
port, | ||
smokeTest, | ||
}) => { | ||
const cwd = redwoodProjectPaths.web.base | ||
const staticAssetsFolder = path.join(cwd, 'public') | ||
const execaOptions = { | ||
stdio: 'inherit', | ||
shell: true, | ||
cwd, | ||
} | ||
|
||
// Create the `MockServiceWorker.js` file. See https://mswjs.io/docs/cli/init. | ||
execa.command(`yarn msw init "${staticAssetsFolder}" --no-save`, execaOptions) | ||
|
||
const storybookConfigPath = path.dirname( | ||
require.resolve('@redwoodjs/testing/config/storybook/main.js') | ||
) | ||
|
||
/** @type {string?} */ | ||
let command | ||
const flags = [`--config-dir "${storybookConfigPath}"`] | ||
|
||
if (build) { | ||
command = `yarn storybook build ${[ | ||
...flags, | ||
`--output-dir "${buildDirectory}"`, | ||
] | ||
.filter(Boolean) | ||
.join(' ')}` | ||
} else if (smokeTest) { | ||
command = `yarn storybook dev ${[ | ||
...flags, | ||
`--port ${port}`, | ||
`--smoke-test`, | ||
`--ci`, | ||
`--no-version-updates`, | ||
] | ||
.filter(Boolean) | ||
.join(' ')}` | ||
} else { | ||
command = `yarn storybook dev ${[ | ||
...flags, | ||
`--port ${port}`, | ||
`--no-version-updates`, | ||
ci && '--ci', | ||
!open && `--no-open`, | ||
] | ||
.filter(Boolean) | ||
.join(' ')}` | ||
} | ||
|
||
try { | ||
execa.command(command, execaOptions) | ||
} catch (e) { | ||
console.log(c.error(e.message)) | ||
errorTelemetry(process.argv, e.message) | ||
process.exit(1) | ||
} | ||
} |
This file contains 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,35 +1,24 @@ | ||
# @RedwoodJS/Testing | ||
# @redwoodjs/testing | ||
|
||
<!-- toc --> | ||
- [Purpose and Vision](#Purpose-and-Vision) | ||
- [Package Lead](#Package-Lead) | ||
- [Roadmap](#Roadmap) | ||
- [Contributing](#Contributing) | ||
This package includes Redwood's Jest and Storybook config. | ||
|
||
## Purpose and Vision | ||
## Notes on Storybook | ||
|
||
This package provides helpful defaults when testing a Redwood project's web side. The core of the project is an re-export of `@testing-library/react` with a custom `render` method. | ||
This section contains some working notes on Redwood's Storybook config, mainly the `webpackFinal` prop. | ||
|
||
## Usage | ||
- `staticDirs` | ||
|
||
In a jest test: | ||
```js | ||
import { render, screen } from '@redwoodjs/testing | ||
```js | ||
...(process.env.NODE_ENV !== 'production' && { | ||
staticDirs: [path.join(redwoodProjectPaths.web.base, 'public')], | ||
}), | ||
``` | ||
|
||
it('works as expected', () => { | ||
render(<MyComponent />) | ||
expect(screen.queryByText('Text in my component')).toBeInTheDocument() | ||
} | ||
``` | ||
We only set `staticDirs` when running Storybook process; will fail if set for SB --build. | ||
|
||
## Package Lead | ||
- [@RobertBroersma](https://github.com/RobertBroersma) | ||
- [@peterp](https://github.com/peterp) | ||
- resolve extensions and plugins | ||
|
||
## Roadmap | ||
See [[Testing] Support Jest --config extensibility](https://github.com/redwoodjs/redwood/issues/564) | ||
|
||
## Contributing | ||
Core technologies | ||
- [Jest](https://jestjs.io/docs/en/getting-started) | ||
- [React Testing Library](https://testing-library.com/docs/react-testing-library/intro) | ||
```js | ||
sbConfig.resolve.extensions = rwConfig.resolve.extensions | ||
sbConfig.resolve.plugins = rwConfig.resolve.plugins // Directory Named Plugin | ||
``` |
Oops, something went wrong.
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.
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 need this here to get tests to run correctly; we can remove it after a canary gets published