@storybook/angular 8.0.0-alpha.8 → 8.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builders/build-storybook/index.d.ts +2 -2
- package/dist/builders/build-storybook/index.js +5 -4
- package/dist/builders/build-storybook/index.spec.js +8 -10
- package/dist/builders/start-storybook/index.js +3 -4
- package/dist/builders/start-storybook/index.spec.js +2 -4
- package/dist/builders/utils/run-compodoc.js +2 -2
- package/dist/builders/utils/run-compodoc.spec.js +1 -1
- package/dist/client/angular-beta/AbstractRenderer.d.ts +0 -6
- package/dist/client/angular-beta/AbstractRenderer.js +11 -59
- package/dist/client/angular-beta/CanvasRenderer.d.ts +0 -1
- package/dist/client/angular-beta/CanvasRenderer.js +0 -3
- package/dist/client/angular-beta/ComputesTemplateFromComponent.test.js +65 -66
- package/dist/client/angular-beta/DocsRenderer.d.ts +0 -1
- package/dist/client/angular-beta/DocsRenderer.js +0 -3
- package/dist/client/angular-beta/RendererFactory.test.js +33 -2
- package/dist/client/angular-beta/StorybookModule.test.js +36 -35
- package/dist/client/angular-beta/StorybookWrapperComponent.d.ts +0 -1
- package/dist/client/angular-beta/StorybookWrapperComponent.js +11 -22
- package/dist/client/angular-beta/utils/BootstrapQueue.d.ts +14 -0
- package/dist/client/angular-beta/utils/BootstrapQueue.js +81 -0
- package/dist/client/angular-beta/utils/BootstrapQueue.test.d.ts +1 -0
- package/dist/client/angular-beta/utils/BootstrapQueue.test.js +162 -0
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.test.js +66 -65
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.test.js +8 -7
- package/dist/client/angular-beta/utils/PropertyExtractor.js +0 -1
- package/dist/client/angular-beta/utils/PropertyExtractor.test.js +0 -2
- package/dist/client/argsToTemplate.test.js +20 -19
- package/dist/client/decorateStory.test.js +28 -27
- package/dist/client/docs/__testfixtures__/doc-button/input.js +2 -3
- package/dist/client/docs/angular-properties.test.js +4 -26
- package/dist/client/index.d.ts +0 -1
- package/dist/client/index.js +0 -3
- package/dist/client/public-types.d.ts +1 -11
- package/dist/preset.d.ts +2 -3
- package/dist/preset.js +0 -1
- package/dist/preset.mjs +0 -1
- package/dist/server/angular-cli-webpack.js +0 -1
- package/dist/server/framework-preset-angular-ivy.js +0 -1
- package/package.json +12 -14
- package/dist/client/public-api.d.ts +0 -1
- package/dist/client/public-api.js +0 -17
|
@@ -10,14 +10,15 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const core_1 = require("@angular/core");
|
|
13
|
+
const vitest_1 = require("vitest");
|
|
13
14
|
const testing_1 = require("@angular/core/testing");
|
|
14
15
|
const rxjs_1 = require("rxjs");
|
|
15
16
|
const StorybookModule_1 = require("./StorybookModule");
|
|
16
17
|
const StorybookProvider_1 = require("./StorybookProvider");
|
|
17
18
|
const PropertyExtractor_1 = require("./utils/PropertyExtractor");
|
|
18
|
-
describe('StorybookModule', () => {
|
|
19
|
-
describe('getStorybookModuleMetadata', () => {
|
|
20
|
-
describe('with simple component', () => {
|
|
19
|
+
(0, vitest_1.describe)('StorybookModule', () => {
|
|
20
|
+
(0, vitest_1.describe)('getStorybookModuleMetadata', () => {
|
|
21
|
+
(0, vitest_1.describe)('with simple component', () => {
|
|
21
22
|
let FooComponent = class FooComponent {
|
|
22
23
|
constructor() {
|
|
23
24
|
this.output = new core_1.EventEmitter();
|
|
@@ -64,7 +65,7 @@ describe('StorybookModule', () => {
|
|
|
64
65
|
`,
|
|
65
66
|
})
|
|
66
67
|
], FooComponent);
|
|
67
|
-
it('should initialize inputs', async () => {
|
|
68
|
+
(0, vitest_1.it)('should initialize inputs', async () => {
|
|
68
69
|
const props = {
|
|
69
70
|
input: 'input',
|
|
70
71
|
inputBindingPropertyName: 'inputBindingPropertyName',
|
|
@@ -83,12 +84,12 @@ describe('StorybookModule', () => {
|
|
|
83
84
|
providers: [(0, StorybookProvider_1.storyPropsProvider)(new rxjs_1.BehaviorSubject(props))],
|
|
84
85
|
});
|
|
85
86
|
fixture.detectChanges();
|
|
86
|
-
expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(props.input);
|
|
87
|
-
expect(fixture.nativeElement.querySelector('p#inputBindingPropertyName').innerHTML).toEqual(props.inputBindingPropertyName);
|
|
88
|
-
expect(fixture.nativeElement.querySelector('p#localProperty').innerHTML).toEqual(props.localProperty);
|
|
89
|
-
expect(fixture.nativeElement.querySelector('p#localFunction').innerHTML).toEqual(props.localFunction());
|
|
87
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(props.input);
|
|
88
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#inputBindingPropertyName').innerHTML).toEqual(props.inputBindingPropertyName);
|
|
89
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#localProperty').innerHTML).toEqual(props.localProperty);
|
|
90
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#localFunction').innerHTML).toEqual(props.localFunction());
|
|
90
91
|
});
|
|
91
|
-
it('should initialize outputs', async () => {
|
|
92
|
+
(0, vitest_1.it)('should initialize outputs', async () => {
|
|
92
93
|
let expectedOutputValue;
|
|
93
94
|
let expectedOutputBindingValue;
|
|
94
95
|
const props = {
|
|
@@ -113,10 +114,10 @@ describe('StorybookModule', () => {
|
|
|
113
114
|
fixture.detectChanges();
|
|
114
115
|
fixture.nativeElement.querySelector('p#output').click();
|
|
115
116
|
fixture.nativeElement.querySelector('p#outputBindingPropertyName').click();
|
|
116
|
-
expect(expectedOutputValue).toEqual('outputEmitted');
|
|
117
|
-
expect(expectedOutputBindingValue).toEqual('outputEmitted');
|
|
117
|
+
(0, vitest_1.expect)(expectedOutputValue).toEqual('outputEmitted');
|
|
118
|
+
(0, vitest_1.expect)(expectedOutputBindingValue).toEqual('outputEmitted');
|
|
118
119
|
});
|
|
119
|
-
it('should change inputs if storyProps$ Subject emit', async () => {
|
|
120
|
+
(0, vitest_1.it)('should change inputs if storyProps$ Subject emit', async () => {
|
|
120
121
|
const initialProps = {
|
|
121
122
|
input: 'input',
|
|
122
123
|
inputBindingPropertyName: '',
|
|
@@ -134,8 +135,8 @@ describe('StorybookModule', () => {
|
|
|
134
135
|
providers: [(0, StorybookProvider_1.storyPropsProvider)(storyProps$)],
|
|
135
136
|
});
|
|
136
137
|
fixture.detectChanges();
|
|
137
|
-
expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(initialProps.input);
|
|
138
|
-
expect(fixture.nativeElement.querySelector('p#inputBindingPropertyName').innerHTML).toEqual('');
|
|
138
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(initialProps.input);
|
|
139
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#inputBindingPropertyName').innerHTML).toEqual('');
|
|
139
140
|
const newProps = {
|
|
140
141
|
input: 'new input',
|
|
141
142
|
inputBindingPropertyName: 'new inputBindingPropertyName',
|
|
@@ -144,12 +145,12 @@ describe('StorybookModule', () => {
|
|
|
144
145
|
};
|
|
145
146
|
storyProps$.next(newProps);
|
|
146
147
|
fixture.detectChanges();
|
|
147
|
-
expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(newProps.input);
|
|
148
|
-
expect(fixture.nativeElement.querySelector('p#inputBindingPropertyName').innerHTML).toEqual(newProps.inputBindingPropertyName);
|
|
149
|
-
expect(fixture.nativeElement.querySelector('p#localProperty').innerHTML).toEqual(newProps.localProperty);
|
|
150
|
-
expect(fixture.nativeElement.querySelector('p#localFunction').innerHTML).toEqual(newProps.localFunction());
|
|
148
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(newProps.input);
|
|
149
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#inputBindingPropertyName').innerHTML).toEqual(newProps.inputBindingPropertyName);
|
|
150
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#localProperty').innerHTML).toEqual(newProps.localProperty);
|
|
151
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#localFunction').innerHTML).toEqual(newProps.localFunction());
|
|
151
152
|
});
|
|
152
|
-
it('should override outputs if storyProps$ Subject emit', async () => {
|
|
153
|
+
(0, vitest_1.it)('should override outputs if storyProps$ Subject emit', async () => {
|
|
153
154
|
let expectedOutputValue;
|
|
154
155
|
let expectedOutputBindingValue;
|
|
155
156
|
const initialProps = {
|
|
@@ -187,11 +188,11 @@ describe('StorybookModule', () => {
|
|
|
187
188
|
fixture.detectChanges();
|
|
188
189
|
fixture.nativeElement.querySelector('p#output').click();
|
|
189
190
|
fixture.nativeElement.querySelector('p#outputBindingPropertyName').click();
|
|
190
|
-
expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(newProps.input);
|
|
191
|
-
expect(expectedOutputValue).toEqual('should be called');
|
|
192
|
-
expect(expectedOutputBindingValue).toEqual('should be called');
|
|
191
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(newProps.input);
|
|
192
|
+
(0, vitest_1.expect)(expectedOutputValue).toEqual('should be called');
|
|
193
|
+
(0, vitest_1.expect)(expectedOutputBindingValue).toEqual('should be called');
|
|
193
194
|
});
|
|
194
|
-
it('should change template inputs if storyProps$ Subject emit', async () => {
|
|
195
|
+
(0, vitest_1.it)('should change template inputs if storyProps$ Subject emit', async () => {
|
|
195
196
|
const initialProps = {
|
|
196
197
|
color: 'red',
|
|
197
198
|
input: 'input',
|
|
@@ -212,18 +213,18 @@ describe('StorybookModule', () => {
|
|
|
212
213
|
providers: [(0, StorybookProvider_1.storyPropsProvider)(storyProps$)],
|
|
213
214
|
});
|
|
214
215
|
fixture.detectChanges();
|
|
215
|
-
expect(fixture.nativeElement.querySelector('p').style.color).toEqual('red');
|
|
216
|
-
expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(initialProps.input);
|
|
216
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p').style.color).toEqual('red');
|
|
217
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(initialProps.input);
|
|
217
218
|
const newProps = {
|
|
218
219
|
color: 'black',
|
|
219
220
|
input: 'new input',
|
|
220
221
|
};
|
|
221
222
|
storyProps$.next(newProps);
|
|
222
223
|
fixture.detectChanges();
|
|
223
|
-
expect(fixture.nativeElement.querySelector('p').style.color).toEqual('black');
|
|
224
|
-
expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(newProps.input);
|
|
224
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p').style.color).toEqual('black');
|
|
225
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(newProps.input);
|
|
225
226
|
});
|
|
226
|
-
it('should call the Input() setter the right number of times', async () => {
|
|
227
|
+
(0, vitest_1.it)('should call the Input() setter the right number of times', async () => {
|
|
227
228
|
const initialProps = {
|
|
228
229
|
setter: 'init',
|
|
229
230
|
};
|
|
@@ -240,16 +241,16 @@ describe('StorybookModule', () => {
|
|
|
240
241
|
providers: [(0, StorybookProvider_1.storyPropsProvider)(storyProps$)],
|
|
241
242
|
});
|
|
242
243
|
fixture.detectChanges();
|
|
243
|
-
expect(fixture.nativeElement.querySelector('p#setterCallNb').innerHTML).toEqual('1');
|
|
244
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#setterCallNb').innerHTML).toEqual('1');
|
|
244
245
|
const newProps = {
|
|
245
246
|
setter: 'new setter value',
|
|
246
247
|
};
|
|
247
248
|
storyProps$.next(newProps);
|
|
248
249
|
fixture.detectChanges();
|
|
249
|
-
expect(fixture.nativeElement.querySelector('p#setterCallNb').innerHTML).toEqual('2');
|
|
250
|
+
(0, vitest_1.expect)(fixture.nativeElement.querySelector('p#setterCallNb').innerHTML).toEqual('2');
|
|
250
251
|
});
|
|
251
252
|
});
|
|
252
|
-
describe('with component without selector', () => {
|
|
253
|
+
(0, vitest_1.describe)('with component without selector', () => {
|
|
253
254
|
let WithoutSelectorComponent = class WithoutSelectorComponent {
|
|
254
255
|
};
|
|
255
256
|
WithoutSelectorComponent = __decorate([
|
|
@@ -257,7 +258,7 @@ describe('StorybookModule', () => {
|
|
|
257
258
|
template: `The content`,
|
|
258
259
|
})
|
|
259
260
|
], WithoutSelectorComponent);
|
|
260
|
-
it('should display the component', async () => {
|
|
261
|
+
(0, vitest_1.it)('should display the component', async () => {
|
|
261
262
|
const props = {};
|
|
262
263
|
const analyzedMetadata = new PropertyExtractor_1.PropertyExtractor({ entryComponents: [WithoutSelectorComponent] }, WithoutSelectorComponent);
|
|
263
264
|
const application = (0, StorybookModule_1.getApplication)({
|
|
@@ -274,10 +275,10 @@ describe('StorybookModule', () => {
|
|
|
274
275
|
providers: [(0, StorybookProvider_1.storyPropsProvider)(new rxjs_1.BehaviorSubject(props))],
|
|
275
276
|
});
|
|
276
277
|
fixture.detectChanges();
|
|
277
|
-
expect(fixture.nativeElement.innerHTML).toContain('The content');
|
|
278
|
+
(0, vitest_1.expect)(fixture.nativeElement.innerHTML).toContain('The content');
|
|
278
279
|
});
|
|
279
280
|
});
|
|
280
|
-
it('should keep template with an empty value', async () => {
|
|
281
|
+
(0, vitest_1.it)('should keep template with an empty value', async () => {
|
|
281
282
|
let FooComponent = class FooComponent {
|
|
282
283
|
};
|
|
283
284
|
FooComponent = __decorate([
|
|
@@ -298,7 +299,7 @@ describe('StorybookModule', () => {
|
|
|
298
299
|
providers: [(0, StorybookProvider_1.storyPropsProvider)(new rxjs_1.BehaviorSubject({}))],
|
|
299
300
|
});
|
|
300
301
|
fixture.detectChanges();
|
|
301
|
-
expect(fixture.nativeElement.innerHTML).toEqual('');
|
|
302
|
+
(0, vitest_1.expect)(fixture.nativeElement.innerHTML).toEqual('');
|
|
302
303
|
});
|
|
303
304
|
});
|
|
304
305
|
async function configureTestingModule(ngModule) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Type } from '@angular/core';
|
|
2
2
|
import { ICollection, NgModuleMetadata } from '../types';
|
|
3
3
|
import { PropertyExtractor } from './utils/PropertyExtractor';
|
|
4
|
-
export declare const componentNgModules: Map<any, Type<any>>;
|
|
5
4
|
/**
|
|
6
5
|
* Wraps the story template into a component
|
|
7
6
|
*/
|
|
@@ -12,7 +12,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.createStorybookWrapperComponent =
|
|
15
|
+
exports.createStorybookWrapperComponent = void 0;
|
|
16
16
|
const core_1 = require("@angular/core");
|
|
17
17
|
const rxjs_1 = require("rxjs");
|
|
18
18
|
const operators_1 = require("rxjs/operators");
|
|
@@ -28,8 +28,6 @@ const getNonInputsOutputsProps = (ngComponentInputsOutputs, props = {}) => {
|
|
|
28
28
|
.map((o) => o.templateName);
|
|
29
29
|
return Object.keys(props).filter((k) => ![...inputs, ...outputs].includes(k));
|
|
30
30
|
};
|
|
31
|
-
// component modules cache
|
|
32
|
-
exports.componentNgModules = new Map();
|
|
33
31
|
/**
|
|
34
32
|
* Wraps the story template into a component
|
|
35
33
|
*/
|
|
@@ -38,24 +36,15 @@ const createStorybookWrapperComponent = ({ selector, template, storyComponent, s
|
|
|
38
36
|
// storyComponent was not provided.
|
|
39
37
|
const viewChildSelector = storyComponent ?? '__storybook-noop';
|
|
40
38
|
const { imports, declarations, providers } = analyzedMetadata;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
(0, core_1.NgModule)({
|
|
51
|
-
declarations,
|
|
52
|
-
imports,
|
|
53
|
-
exports: [...declarations, ...imports],
|
|
54
|
-
})
|
|
55
|
-
], StorybookComponentModule);
|
|
56
|
-
exports.componentNgModules.set(storyComponent, StorybookComponentModule);
|
|
57
|
-
ngModule = exports.componentNgModules.get(storyComponent);
|
|
58
|
-
}
|
|
39
|
+
let StorybookComponentModule = class StorybookComponentModule {
|
|
40
|
+
};
|
|
41
|
+
StorybookComponentModule = __decorate([
|
|
42
|
+
(0, core_1.NgModule)({
|
|
43
|
+
declarations,
|
|
44
|
+
imports,
|
|
45
|
+
exports: [...declarations, ...imports],
|
|
46
|
+
})
|
|
47
|
+
], StorybookComponentModule);
|
|
59
48
|
PropertyExtractor_1.PropertyExtractor.warnImportsModuleWithProviders(analyzedMetadata);
|
|
60
49
|
let StorybookWrapperComponent = class StorybookWrapperComponent {
|
|
61
50
|
constructor(storyProps$, changeDetectorRef) {
|
|
@@ -125,7 +114,7 @@ const createStorybookWrapperComponent = ({ selector, template, storyComponent, s
|
|
|
125
114
|
selector,
|
|
126
115
|
template,
|
|
127
116
|
standalone: true,
|
|
128
|
-
imports: [
|
|
117
|
+
imports: [StorybookComponentModule],
|
|
129
118
|
providers,
|
|
130
119
|
styles,
|
|
131
120
|
schemas: moduleMetadata.schemas,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ApplicationRef } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* Queue bootstrapping, so that only one application can be bootstrapped at a
|
|
4
|
+
* time.
|
|
5
|
+
*
|
|
6
|
+
* Bootstrapping multiple applications at once can cause Angular to throw an
|
|
7
|
+
* error that a component is declared in multiple modules. This avoids two
|
|
8
|
+
* stories confusing the Angular compiler, by bootstrapping more that one
|
|
9
|
+
* application at a time.
|
|
10
|
+
*
|
|
11
|
+
* @param fn callback that should complete the bootstrap process
|
|
12
|
+
* @returns ApplicationRef from the completed bootstrap process
|
|
13
|
+
*/
|
|
14
|
+
export declare const queueBootstrapping: (fn: () => Promise<ApplicationRef>) => Promise<ApplicationRef>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.queueBootstrapping = void 0;
|
|
27
|
+
const queue = [];
|
|
28
|
+
let isProcessing = false;
|
|
29
|
+
/**
|
|
30
|
+
* Reset compiled components because we often want to compile the same component with
|
|
31
|
+
* more than one NgModule.
|
|
32
|
+
*/
|
|
33
|
+
const resetCompiledComponents = async () => {
|
|
34
|
+
try {
|
|
35
|
+
// Clear global Angular component cache in order to be able to re-render the same component across multiple stories
|
|
36
|
+
//
|
|
37
|
+
// References:
|
|
38
|
+
// https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_angular/src/webpack/plugins/hmr/hmr-accept.ts#L50
|
|
39
|
+
// https://github.com/angular/angular/blob/2ebe2bcb2fe19bf672316b05f15241fd7fd40803/packages/core/src/render3/jit/module.ts#L377-L384
|
|
40
|
+
const { ɵresetCompiledComponents } = await Promise.resolve().then(() => __importStar(require('@angular/core')));
|
|
41
|
+
ɵresetCompiledComponents();
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
/**
|
|
45
|
+
* noop catch
|
|
46
|
+
* This means angular removed or modified ɵresetCompiledComponents
|
|
47
|
+
*/
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Queue bootstrapping, so that only one application can be bootstrapped at a
|
|
52
|
+
* time.
|
|
53
|
+
*
|
|
54
|
+
* Bootstrapping multiple applications at once can cause Angular to throw an
|
|
55
|
+
* error that a component is declared in multiple modules. This avoids two
|
|
56
|
+
* stories confusing the Angular compiler, by bootstrapping more that one
|
|
57
|
+
* application at a time.
|
|
58
|
+
*
|
|
59
|
+
* @param fn callback that should complete the bootstrap process
|
|
60
|
+
* @returns ApplicationRef from the completed bootstrap process
|
|
61
|
+
*/
|
|
62
|
+
const queueBootstrapping = (fn) => {
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
queue.push(() => fn().then(resolve).catch(reject));
|
|
65
|
+
if (!isProcessing) {
|
|
66
|
+
processQueue();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
exports.queueBootstrapping = queueBootstrapping;
|
|
71
|
+
const processQueue = async () => {
|
|
72
|
+
isProcessing = true;
|
|
73
|
+
while (queue.length > 0) {
|
|
74
|
+
const bootstrappingFn = queue.shift();
|
|
75
|
+
if (bootstrappingFn) {
|
|
76
|
+
await bootstrappingFn();
|
|
77
|
+
await resetCompiledComponents();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
isProcessing = false;
|
|
81
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const rxjs_1 = require("rxjs");
|
|
4
|
+
const vitest_1 = require("vitest");
|
|
5
|
+
const BootstrapQueue_1 = require("./BootstrapQueue");
|
|
6
|
+
const instantWaitFor = (fn) => {
|
|
7
|
+
return vitest_1.vi.waitFor(fn, {
|
|
8
|
+
interval: 0,
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
(0, vitest_1.describe)('BootstrapQueue', () => {
|
|
12
|
+
(0, vitest_1.beforeEach)(async () => {
|
|
13
|
+
vitest_1.vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
14
|
+
});
|
|
15
|
+
(0, vitest_1.afterEach)(() => {
|
|
16
|
+
vitest_1.vi.clearAllMocks();
|
|
17
|
+
});
|
|
18
|
+
(0, vitest_1.it)('should wait until complete', async () => {
|
|
19
|
+
const pendingSubject = new rxjs_1.Subject();
|
|
20
|
+
const bootstrapApp = vitest_1.vi.fn().mockImplementation(async () => {
|
|
21
|
+
return (0, rxjs_1.lastValueFrom)(pendingSubject);
|
|
22
|
+
});
|
|
23
|
+
const bootstrapAppFinished = vitest_1.vi.fn();
|
|
24
|
+
(0, BootstrapQueue_1.queueBootstrapping)(bootstrapApp).then(() => {
|
|
25
|
+
bootstrapAppFinished();
|
|
26
|
+
});
|
|
27
|
+
await instantWaitFor(() => {
|
|
28
|
+
if (bootstrapApp.mock.calls.length !== 1) {
|
|
29
|
+
throw new Error('bootstrapApp should not have been called yet');
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
(0, vitest_1.expect)(bootstrapApp).toHaveBeenCalled();
|
|
33
|
+
(0, vitest_1.expect)(bootstrapAppFinished).not.toHaveBeenCalled();
|
|
34
|
+
pendingSubject.next();
|
|
35
|
+
pendingSubject.complete();
|
|
36
|
+
await instantWaitFor(() => {
|
|
37
|
+
if (bootstrapAppFinished.mock.calls.length !== 1) {
|
|
38
|
+
throw new Error('bootstrapApp should have been called once');
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
(0, vitest_1.expect)(bootstrapAppFinished).toHaveBeenCalled();
|
|
42
|
+
});
|
|
43
|
+
(0, vitest_1.it)('should prevent following tasks, until the preview tasks are complete', async () => {
|
|
44
|
+
const pendingSubject = new rxjs_1.Subject();
|
|
45
|
+
const bootstrapApp = vitest_1.vi.fn().mockImplementation(async () => {
|
|
46
|
+
return (0, rxjs_1.lastValueFrom)(pendingSubject);
|
|
47
|
+
});
|
|
48
|
+
const bootstrapAppFinished = vitest_1.vi.fn();
|
|
49
|
+
const pendingSubject2 = new rxjs_1.Subject();
|
|
50
|
+
const bootstrapApp2 = vitest_1.vi.fn().mockImplementation(async () => {
|
|
51
|
+
return (0, rxjs_1.lastValueFrom)(pendingSubject2);
|
|
52
|
+
});
|
|
53
|
+
const bootstrapAppFinished2 = vitest_1.vi.fn();
|
|
54
|
+
const pendingSubject3 = new rxjs_1.Subject();
|
|
55
|
+
const bootstrapApp3 = vitest_1.vi.fn().mockImplementation(async () => {
|
|
56
|
+
return (0, rxjs_1.lastValueFrom)(pendingSubject3);
|
|
57
|
+
});
|
|
58
|
+
const bootstrapAppFinished3 = vitest_1.vi.fn();
|
|
59
|
+
(0, BootstrapQueue_1.queueBootstrapping)(bootstrapApp).then(bootstrapAppFinished);
|
|
60
|
+
(0, BootstrapQueue_1.queueBootstrapping)(bootstrapApp2).then(bootstrapAppFinished2);
|
|
61
|
+
(0, BootstrapQueue_1.queueBootstrapping)(bootstrapApp3).then(bootstrapAppFinished3);
|
|
62
|
+
await instantWaitFor(() => {
|
|
63
|
+
if (bootstrapApp.mock.calls.length !== 1) {
|
|
64
|
+
throw new Error('bootstrapApp should have been called once');
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
(0, vitest_1.expect)(bootstrapApp).toHaveBeenCalled();
|
|
68
|
+
(0, vitest_1.expect)(bootstrapAppFinished).not.toHaveBeenCalled();
|
|
69
|
+
(0, vitest_1.expect)(bootstrapApp2).not.toHaveBeenCalled();
|
|
70
|
+
(0, vitest_1.expect)(bootstrapAppFinished2).not.toHaveBeenCalled();
|
|
71
|
+
(0, vitest_1.expect)(bootstrapApp3).not.toHaveBeenCalled();
|
|
72
|
+
(0, vitest_1.expect)(bootstrapAppFinished3).not.toHaveBeenCalled();
|
|
73
|
+
pendingSubject.next();
|
|
74
|
+
pendingSubject.complete();
|
|
75
|
+
await instantWaitFor(() => {
|
|
76
|
+
if (bootstrapApp2.mock.calls.length !== 1) {
|
|
77
|
+
throw new Error('bootstrapApp2 should have been called once');
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
(0, vitest_1.expect)(bootstrapApp).toHaveReturnedTimes(1);
|
|
81
|
+
(0, vitest_1.expect)(bootstrapAppFinished).toHaveBeenCalled();
|
|
82
|
+
(0, vitest_1.expect)(bootstrapApp2).toHaveBeenCalled();
|
|
83
|
+
(0, vitest_1.expect)(bootstrapAppFinished2).not.toHaveBeenCalled();
|
|
84
|
+
(0, vitest_1.expect)(bootstrapApp3).not.toHaveBeenCalled();
|
|
85
|
+
(0, vitest_1.expect)(bootstrapAppFinished3).not.toHaveBeenCalled();
|
|
86
|
+
pendingSubject2.next();
|
|
87
|
+
pendingSubject2.complete();
|
|
88
|
+
await instantWaitFor(() => {
|
|
89
|
+
if (bootstrapApp3.mock.calls.length !== 1) {
|
|
90
|
+
throw new Error('bootstrapApp3 should have been called once');
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
(0, vitest_1.expect)(bootstrapApp).toHaveReturnedTimes(1);
|
|
94
|
+
(0, vitest_1.expect)(bootstrapAppFinished).toHaveBeenCalled();
|
|
95
|
+
(0, vitest_1.expect)(bootstrapApp2).toHaveReturnedTimes(1);
|
|
96
|
+
(0, vitest_1.expect)(bootstrapAppFinished2).toHaveBeenCalled();
|
|
97
|
+
(0, vitest_1.expect)(bootstrapApp3).toHaveBeenCalled();
|
|
98
|
+
(0, vitest_1.expect)(bootstrapAppFinished3).not.toHaveBeenCalled();
|
|
99
|
+
pendingSubject3.next();
|
|
100
|
+
pendingSubject3.complete();
|
|
101
|
+
await instantWaitFor(() => {
|
|
102
|
+
if (bootstrapAppFinished3.mock.calls.length !== 1) {
|
|
103
|
+
throw new Error('bootstrapAppFinished3 should have been called once');
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
(0, vitest_1.expect)(bootstrapApp).toHaveReturnedTimes(1);
|
|
107
|
+
(0, vitest_1.expect)(bootstrapAppFinished).toHaveBeenCalled();
|
|
108
|
+
(0, vitest_1.expect)(bootstrapApp2).toHaveReturnedTimes(1);
|
|
109
|
+
(0, vitest_1.expect)(bootstrapAppFinished2).toHaveBeenCalled();
|
|
110
|
+
(0, vitest_1.expect)(bootstrapApp3).toHaveReturnedTimes(1);
|
|
111
|
+
(0, vitest_1.expect)(bootstrapAppFinished3).toHaveBeenCalled();
|
|
112
|
+
});
|
|
113
|
+
(0, vitest_1.it)('should throw and continue next bootstrap on error', async () => {
|
|
114
|
+
const pendingSubject = new rxjs_1.Subject();
|
|
115
|
+
const bootstrapApp = vitest_1.vi.fn().mockImplementation(async () => {
|
|
116
|
+
return (0, rxjs_1.lastValueFrom)(pendingSubject);
|
|
117
|
+
});
|
|
118
|
+
const bootstrapAppFinished = vitest_1.vi.fn();
|
|
119
|
+
const bootstrapAppError = vitest_1.vi.fn();
|
|
120
|
+
const pendingSubject2 = new rxjs_1.Subject();
|
|
121
|
+
const bootstrapApp2 = vitest_1.vi.fn().mockImplementation(async () => {
|
|
122
|
+
return (0, rxjs_1.lastValueFrom)(pendingSubject2);
|
|
123
|
+
});
|
|
124
|
+
const bootstrapAppFinished2 = vitest_1.vi.fn();
|
|
125
|
+
const bootstrapAppError2 = vitest_1.vi.fn();
|
|
126
|
+
(0, BootstrapQueue_1.queueBootstrapping)(bootstrapApp).then(bootstrapAppFinished).catch(bootstrapAppError);
|
|
127
|
+
(0, BootstrapQueue_1.queueBootstrapping)(bootstrapApp2).then(bootstrapAppFinished2).catch(bootstrapAppError2);
|
|
128
|
+
await instantWaitFor(() => {
|
|
129
|
+
if (bootstrapApp.mock.calls.length !== 1) {
|
|
130
|
+
throw new Error('bootstrapApp should have been called once');
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
(0, vitest_1.expect)(bootstrapApp).toHaveBeenCalledTimes(1);
|
|
134
|
+
(0, vitest_1.expect)(bootstrapAppFinished).not.toHaveBeenCalled();
|
|
135
|
+
(0, vitest_1.expect)(bootstrapApp2).not.toHaveBeenCalled();
|
|
136
|
+
pendingSubject.error(new Error('test error'));
|
|
137
|
+
await instantWaitFor(() => {
|
|
138
|
+
if (bootstrapAppError.mock.calls.length !== 1) {
|
|
139
|
+
throw new Error('bootstrapAppError should have been called once');
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
(0, vitest_1.expect)(bootstrapApp).toHaveBeenCalledTimes(1);
|
|
143
|
+
(0, vitest_1.expect)(bootstrapAppFinished).not.toHaveBeenCalled();
|
|
144
|
+
(0, vitest_1.expect)(bootstrapAppError).toHaveBeenCalledTimes(1);
|
|
145
|
+
(0, vitest_1.expect)(bootstrapApp2).toHaveBeenCalledTimes(1);
|
|
146
|
+
(0, vitest_1.expect)(bootstrapAppFinished2).not.toHaveBeenCalled();
|
|
147
|
+
(0, vitest_1.expect)(bootstrapAppError2).not.toHaveBeenCalled();
|
|
148
|
+
pendingSubject2.next();
|
|
149
|
+
pendingSubject2.complete();
|
|
150
|
+
await instantWaitFor(() => {
|
|
151
|
+
if (bootstrapAppFinished2.mock.calls.length !== 1) {
|
|
152
|
+
throw new Error('bootstrapAppFinished2 should have been called once');
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
(0, vitest_1.expect)(bootstrapApp).toHaveBeenCalledTimes(1);
|
|
156
|
+
(0, vitest_1.expect)(bootstrapAppFinished).not.toHaveBeenCalled();
|
|
157
|
+
(0, vitest_1.expect)(bootstrapAppError).toHaveBeenCalledTimes(1);
|
|
158
|
+
(0, vitest_1.expect)(bootstrapApp2).toHaveBeenCalledTimes(1);
|
|
159
|
+
(0, vitest_1.expect)(bootstrapAppFinished2).toHaveBeenCalledTimes(1);
|
|
160
|
+
(0, vitest_1.expect)(bootstrapAppError2).not.toHaveBeenCalled();
|
|
161
|
+
});
|
|
162
|
+
});
|