Merge pull request #15410 from Marklb/marklb/fix-circular-ref-in-module-metadata

Angular: Fix circular reference not being handled in moduleMetadata
This commit is contained in:
Michael Shilman 2021-07-03 01:26:49 +08:00 committed by GitHub
commit 913ae3b80e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 2 deletions

View File

@ -65,6 +65,7 @@
"regenerator-runtime": "^0.13.7",
"sass-loader": "^10.1.0",
"strip-json-comments": "3.1.1",
"telejson": "^5.3.2",
"ts-dedent": "^2.0.0",
"ts-loader": "^8.0.14",
"tsconfig-paths-webpack-plugin": "^3.3.0",

View File

@ -3,6 +3,7 @@ import { enableProdMode, NgModule, PlatformRef } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { BehaviorSubject, Subject } from 'rxjs';
import { stringify } from 'telejson';
import { ICollection, StoryFnAngularReturnType } from '../types';
import { Parameters } from '../types-6-0';
import { createStorybookModule, getStorybookModuleMetadata } from './StorybookModule';
@ -160,7 +161,7 @@ export abstract class AbstractRenderer {
const currentStoryRender = {
storyFnAngular,
moduleMetadataSnapshot: JSON.stringify(moduleMetadata),
moduleMetadataSnapshot: stringify(moduleMetadata),
};
this.previousStoryRenderInfo = currentStoryRender;

View File

@ -57,6 +57,29 @@ describe('RendererService', () => {
);
});
it('should handle circular reference in moduleMetadata', async () => {
class Thing {
token: Thing;
constructor() {
this.token = this;
}
}
const token = new Thing();
await rendererService.render({
storyFnAngular: {
template: '🦊',
props: {},
moduleMetadata: { providers: [{ provide: 'foo', useValue: token }] },
},
forced: false,
parameters: {} as any,
});
expect(document.body.getElementsByTagName('storybook-wrapper')[0].innerHTML).toBe('🦊');
});
describe('when forced=true', () => {
beforeEach(async () => {
// Init first render

View File

@ -3,6 +3,7 @@ import { enableProdMode, NgModule, PlatformRef } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { BehaviorSubject, Subject } from 'rxjs';
import { stringify } from 'telejson';
import { ICollection, StoryFnAngularReturnType } from '../types';
import { Parameters } from '../types-6-0';
import { createStorybookModule, getStorybookModuleMetadata } from './StorybookModule';
@ -154,7 +155,7 @@ export class RendererService {
this.currentStoryRender = {
storyFnAngular,
moduleMetadataSnapshot: JSON.stringify(moduleMetadata),
moduleMetadataSnapshot: stringify(moduleMetadata),
};
if (

View File

@ -6170,6 +6170,7 @@ __metadata:
regenerator-runtime: ^0.13.7
sass-loader: ^10.1.0
strip-json-comments: 3.1.1
telejson: ^5.3.2
ts-dedent: ^2.0.0
ts-jest: ^26.4.4
ts-loader: ^8.0.14