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

Angular: Deprecate the story component attribute #13383

Merged
merged 23 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c7dc891
fix(angular): declare only the compatible component
ThibaudAV Dec 8, 2020
acd8104
fix(angular): use @storybook/angular client rendering in storyshots
ThibaudAV Dec 8, 2020
6e6de1b
feat(angular): depreciate the story component attribute
ThibaudAV Dec 5, 2020
05848fe
refactor(angular): take into account the `component` deprecation in a…
ThibaudAV Dec 9, 2020
1b65c45
refactor(angular): take into account the `component` deprecation in a…
ThibaudAV Dec 8, 2020
0f55784
refactor(angular): take into account the `component` deprecation in a…
ThibaudAV Dec 8, 2020
e3dbfa2
MIGRATION: Deprecate Angular story component
shilman Dec 9, 2020
1fe60ca
Fix link
shilman Dec 9, 2020
07f490f
fix(angular): use utc to avoid time zone differences
ThibaudAV Dec 9, 2020
33cd052
Merge branch 'next' into pr/13383
shilman Dec 10, 2020
8b97b77
fixup! feat(angular): depreciate the story component attribute
ThibaudAV Dec 10, 2020
901759a
feat(angular): remove internal storybook properties in storyshot
ThibaudAV Dec 10, 2020
9f92644
Document Angular snapshot migration
shilman Dec 14, 2020
e3b6d28
Merge branch 'next' into pr/13383
shilman Dec 14, 2020
4f87404
Update MIGRATION.md
shilman Dec 14, 2020
9048df8
Merge branch 'next' into angular-parameters-component
ThibaudAV Dec 14, 2020
be939de
Merge branch 'next' into pr/13383
shilman Dec 15, 2020
1dec7c6
Fix angular storyshots
shilman Dec 15, 2020
2a7c9f6
Merge branch 'next' into pr/13383
shilman Dec 16, 2020
d2bd6e5
Angular: Special `renderer` entry for storyshots
shilman Dec 16, 2020
761aad4
Angular: Fix renderer export
shilman Dec 16, 2020
67d0314
Update renderer.js
shilman Dec 16, 2020
6149b14
Update renderer.js
shilman Dec 16, 2020
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
29 changes: 28 additions & 1 deletion MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<h1>Migration</h1>

- [From version 6.1.x to 6.2.0](#from-version-61x-to-620)
- [Deprecated Angular story component](#deprecated-angular-story-component)
- [New Angular renderer](#new-angular-renderer)
- [From version 6.0.x to 6.1.0](#from-version-60x-to-610)
- [Addon-backgrounds preset](#addon-backgrounds-preset)
Expand Down Expand Up @@ -143,9 +144,34 @@

## From version 6.1.x to 6.2.0

### Deprecated Angular story component

Storybook 6.2 for Angular uses `parameters.component` as the preferred way to specify your stories' components. The previous method, in which the component was a return value of the story, has been deprecated.

Consider the existing story from 6.1 or earlier:

```ts
export default { title: 'Button' };
export const Basic = () => ({
component: Button,
props: { label: 'Label' },
});
```

From 6.2 this should be rewritten as:

```ts
export default { title: 'Button', component: Button };
export const Basic = () => ({
props: { label: 'Label' },
});
```

The new convention is consistent with how other frameworks and addons work in Storybook. The old way will be supported until 7.0. For a full discussion see https://github.com/storybookjs/storybook/issues/8673.

### New Angular renderer

We've rewritten the Angular renderer in Storybook 6.1. It's meant to be entirely backwards compatible, but if you need to use the legacy renderer it's still available via a [parameter](https://storybook.js.org/docs/react/writing-stories/parameters). To opt out of the new renderer, add the following to `.storybook/preview.ts`:
We've rewritten the Angular renderer in Storybook 6.2. It's meant to be entirely backwards compatible, but if you need to use the legacy renderer it's still available via a [parameter](https://storybook.js.org/docs/react/writing-stories/parameters). To opt out of the new renderer, add the following to `.storybook/preview.ts`:
shilman marked this conversation as resolved.
Show resolved Hide resolved

```ts
export const parameters = {
Expand All @@ -162,6 +188,7 @@ Please also file an issue if you need to opt out. We plan to remove the legacy r
In 6.1 we introduced an unintentional breaking change to `addon-backgrounds`.

The addon uses decorators which are set up automatically by a preset. The required preset is ignored if you register the addon in `main.js` withe the the `/register` entry point. This used to be valid in `v6.0.x` and earlier:

```js
module.exports = {
stories: ['../**/*.stories.js'],
Expand Down
6 changes: 6 additions & 0 deletions addons/storyshots/storyshots-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@
"react-test-renderer": "^16.8.0 || ^17.0.0",
"read-pkg-up": "^7.0.0",
"regenerator-runtime": "^0.13.7",
"rxjs": "^6.6.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rxjs should be a peerDep too as non Angular users don't need this dep

"ts-dedent": "^2.0.0"
},
"devDependencies": {
"@storybook/addon-docs": "6.2.0-alpha.5",
"@storybook/angular": "6.2.0-alpha.5",
"@storybook/react": "6.2.0-alpha.5",
"babel-loader": "^8.0.6",
"enzyme": "^3.11.0",
Expand All @@ -68,6 +70,7 @@
"jest-vue-preprocessor": "^1.5.0"
},
"peerDependencies": {
"@storybook/angular": "*",
"@storybook/react": "*",
"@storybook/vue": "*",
"jest-preset-angular": "*",
Expand All @@ -80,6 +83,9 @@
"@storybook/vue": {
"optional": true
},
"@storybook/angular": {
"optional": true
},
"jest-preset-angular": {
"optional": true
},
Expand Down

This file was deleted.

This file was deleted.

121 changes: 0 additions & 121 deletions addons/storyshots/storyshots-core/src/frameworks/angular/helpers.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,36 @@ import HTMLCommentSerializer from 'jest-preset-angular/build/HTMLCommentSerializ
import { TestBed } from '@angular/core/testing';
// eslint-disable-next-line import/no-extraneous-dependencies
import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
// eslint-disable-next-line import/no-extraneous-dependencies
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { addSerializer } from 'jest-specific-snapshot';
import { initModuleData } from './helpers';
import { RenderNgAppService } from '@storybook/angular/dist/client/preview/angular-beta/RenderNgAppService';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoids redefining the rendering like before.
if you have a (simple) idea to avoid the /dist/ tell me :)

import { BehaviorSubject } from 'rxjs';

addSerializer(HTMLCommentSerializer);
addSerializer(AngularSnapshotSerializer);

function getRenderedTree(story: any) {
const currentStory = story.render();

const { moduleMeta, AppComponent } = initModuleData(currentStory);

TestBed.configureTestingModule(
// TODO: take a look at `bootstrap` because it looks it does not exists in TestModuleMetadata
{
imports: [...moduleMeta.imports],
declarations: [...moduleMeta.declarations],
providers: [...moduleMeta.providers],
schemas: [NO_ERRORS_SCHEMA, ...moduleMeta.schemas],
bootstrap: [...moduleMeta.bootstrap],
} as any
const moduleMeta = RenderNgAppService.getNgModuleMetadata(
{ storyFnAngular: currentStory, parameters: story.parameters },
new BehaviorSubject(currentStory.props)
);

TestBed.configureTestingModule({
imports: [...moduleMeta.imports],
declarations: [...moduleMeta.declarations],
providers: [...moduleMeta.providers],
schemas: [...moduleMeta.schemas],
});

TestBed.overrideModule(BrowserDynamicTestingModule, {
set: {
entryComponents: [...moduleMeta.entryComponents],
},
});

return TestBed.compileComponents().then(() => {
const tree = TestBed.createComponent(AppComponent);
const tree = TestBed.createComponent(moduleMeta.bootstrap[0] as any);
tree.detectChanges();

return tree;
Expand Down
2 changes: 2 additions & 0 deletions app/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@
"regenerator-runtime": "^0.13.7",
"sass-loader": "^8.0.0",
"strip-json-comments": "3.1.1",
"ts-dedent": "^2.0.0",
"ts-loader": "^6.0.1",
"tsconfig-paths-webpack-plugin": "^3.2.0",
"util-deprecate": "^1.0.2",
"webpack": "^4.44.2"
},
"devDependencies": {
Expand Down
Loading