@storybook/angular 7.0.11 → 7.0.13
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 +1 -1
- package/dist/builders/build-storybook/index.spec.js +39 -41
- package/dist/builders/start-storybook/index.d.ts +1 -1
- package/dist/builders/start-storybook/index.spec.js +35 -34
- package/dist/builders/utils/run-compodoc.js +1 -1
- package/dist/builders/utils/run-compodoc.spec.js +6 -29
- package/dist/client/angular-beta/AbstractRenderer.d.ts +3 -6
- package/dist/client/angular-beta/AbstractRenderer.js +2 -4
- package/dist/client/angular-beta/RendererFactory.d.ts +1 -1
- package/dist/client/angular-beta/RendererFactory.js +6 -5
- package/dist/client/angular-beta/RendererFactory.test.js +23 -156
- package/dist/client/angular-beta/utils/PropertyExtractor.test.js +1 -0
- package/dist/client/docs/angular-properties.test.js +17 -11
- package/dist/client/docs/compodoc.test.js +11 -11
- package/dist/client/docs/sourceDecorator.js +2 -2
- package/dist/client/render.d.ts +1 -1
- package/dist/client/render.js +2 -3
- package/jest.config.js +8 -8
- package/package.json +30 -30
- package/dist/server/framework-preset-angular-cli.test.d.ts +0 -1
- package/dist/server/framework-preset-angular-cli.test.js +0 -698
|
@@ -1,698 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const path_1 = __importDefault(require("path"));
|
|
7
|
-
const node_logger_1 = require("@storybook/node-logger");
|
|
8
|
-
const core_1 = require("@angular-devkit/core");
|
|
9
|
-
const framework_preset_angular_cli_1 = require("./framework-preset-angular-cli");
|
|
10
|
-
const testPath = __dirname;
|
|
11
|
-
let workspaceRoot = testPath;
|
|
12
|
-
let cwdSpy;
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
cwdSpy = jest.spyOn(process, 'cwd');
|
|
15
|
-
jest.spyOn(node_logger_1.logger, 'error').mockImplementation();
|
|
16
|
-
jest.spyOn(node_logger_1.logger, 'info').mockImplementation();
|
|
17
|
-
});
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
jest.clearAllMocks();
|
|
20
|
-
});
|
|
21
|
-
function initMockWorkspace(name) {
|
|
22
|
-
workspaceRoot = path_1.default.join(__dirname, '__mocks-ng-workspace__', name);
|
|
23
|
-
cwdSpy.mockReturnValue(workspaceRoot);
|
|
24
|
-
}
|
|
25
|
-
describe('framework-preset-angular-cli', () => {
|
|
26
|
-
let options;
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
options = {};
|
|
29
|
-
});
|
|
30
|
-
describe('without angular.json', () => {
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
initMockWorkspace('');
|
|
33
|
-
});
|
|
34
|
-
it('should return webpack base config and display log error', async () => {
|
|
35
|
-
const webpackBaseConfig = newWebpackConfiguration();
|
|
36
|
-
const config = await (0, framework_preset_angular_cli_1.webpackFinal)(webpackBaseConfig, options);
|
|
37
|
-
expect(node_logger_1.logger.info).toHaveBeenCalledWith('=> Loading angular-cli config for angular lower than 12.2.0');
|
|
38
|
-
expect(node_logger_1.logger.error).toHaveBeenCalledWith(`=> Could not find angular workspace config (angular.json) on this path "${workspaceRoot}"`);
|
|
39
|
-
expect(config).toEqual(webpackBaseConfig);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
describe("when angular.json haven't projects entry", () => {
|
|
43
|
-
beforeEach(() => {
|
|
44
|
-
initMockWorkspace('without-projects-entry');
|
|
45
|
-
});
|
|
46
|
-
it('should return webpack base config and display log error', async () => {
|
|
47
|
-
const webpackBaseConfig = newWebpackConfiguration();
|
|
48
|
-
const config = await (0, framework_preset_angular_cli_1.webpackFinal)(webpackBaseConfig, options);
|
|
49
|
-
expect(node_logger_1.logger.info).toHaveBeenCalledWith('=> Loading angular-cli config for angular lower than 12.2.0');
|
|
50
|
-
expect(node_logger_1.logger.error).toHaveBeenCalledWith('=> Could not find angular project: No angular projects found');
|
|
51
|
-
expect(node_logger_1.logger.info).toHaveBeenCalledWith('=> Fail to load angular-cli config. Using base config');
|
|
52
|
-
expect(config).toEqual(webpackBaseConfig);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
describe('when angular.json have empty projects entry', () => {
|
|
56
|
-
beforeEach(() => {
|
|
57
|
-
initMockWorkspace('empty-projects-entry');
|
|
58
|
-
});
|
|
59
|
-
it('should return webpack base config and display log error', async () => {
|
|
60
|
-
const webpackBaseConfig = newWebpackConfiguration();
|
|
61
|
-
const config = await (0, framework_preset_angular_cli_1.webpackFinal)(webpackBaseConfig, options);
|
|
62
|
-
expect(node_logger_1.logger.info).toHaveBeenCalledWith('=> Loading angular-cli config for angular lower than 12.2.0');
|
|
63
|
-
expect(node_logger_1.logger.error).toHaveBeenCalledWith('=> Could not find angular project: No angular projects found');
|
|
64
|
-
expect(node_logger_1.logger.info).toHaveBeenCalledWith('=> Fail to load angular-cli config. Using base config');
|
|
65
|
-
expect(config).toEqual(webpackBaseConfig);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
describe('when angular.json does not have a compatible project', () => {
|
|
69
|
-
beforeEach(() => {
|
|
70
|
-
initMockWorkspace('without-compatible-projects');
|
|
71
|
-
});
|
|
72
|
-
it('should return webpack base config and display log error', async () => {
|
|
73
|
-
const webpackBaseConfig = newWebpackConfiguration();
|
|
74
|
-
const config = await (0, framework_preset_angular_cli_1.webpackFinal)(webpackBaseConfig, options);
|
|
75
|
-
expect(node_logger_1.logger.info).toHaveBeenCalledWith('=> Loading angular-cli config for angular lower than 12.2.0');
|
|
76
|
-
expect(node_logger_1.logger.error).toHaveBeenCalledWith('=> Could not find angular project: "missing-project" project is not found in angular.json');
|
|
77
|
-
expect(node_logger_1.logger.info).toHaveBeenCalledWith('=> Fail to load angular-cli config. Using base config');
|
|
78
|
-
expect(config).toEqual(webpackBaseConfig);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
describe('when angular.json have projects without architect.build', () => {
|
|
82
|
-
beforeEach(() => {
|
|
83
|
-
initMockWorkspace('without-architect-build');
|
|
84
|
-
});
|
|
85
|
-
it('should return webpack base config and display log error', async () => {
|
|
86
|
-
const webpackBaseConfig = newWebpackConfiguration();
|
|
87
|
-
const config = await (0, framework_preset_angular_cli_1.webpackFinal)(webpackBaseConfig, options);
|
|
88
|
-
expect(node_logger_1.logger.info).toHaveBeenCalledWith('=> Loading angular-cli config for angular lower than 12.2.0');
|
|
89
|
-
expect(node_logger_1.logger.error).toHaveBeenCalledWith('=> Could not find angular project: "build" target is not found in "foo-project" project');
|
|
90
|
-
expect(node_logger_1.logger.info).toHaveBeenCalledWith('=> Fail to load angular-cli config. Using base config');
|
|
91
|
-
expect(config).toEqual(webpackBaseConfig);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
describe('when angular.json have projects without architect.build.options', () => {
|
|
95
|
-
beforeEach(() => {
|
|
96
|
-
initMockWorkspace('without-architect-build-options');
|
|
97
|
-
});
|
|
98
|
-
it('throws error', async () => {
|
|
99
|
-
await expect(() => (0, framework_preset_angular_cli_1.webpackFinal)(newWebpackConfiguration(), options)).rejects.toThrowError('Missing required options in project target. Check "tsConfig"');
|
|
100
|
-
expect(node_logger_1.logger.error).toHaveBeenCalledWith(`=> Could not get angular cli webpack config`);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
describe('when angular.json have minimal config', () => {
|
|
104
|
-
beforeEach(() => {
|
|
105
|
-
initMockWorkspace('minimal-config');
|
|
106
|
-
});
|
|
107
|
-
it('should log', async () => {
|
|
108
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
109
|
-
await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
110
|
-
expect(node_logger_1.logger.info).toHaveBeenCalledTimes(3);
|
|
111
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(1, '=> Loading angular-cli config for angular lower than 12.2.0');
|
|
112
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(2, '=> Using angular project "foo-project:build" for configuring Storybook');
|
|
113
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(3, '=> Using angular-cli webpack config');
|
|
114
|
-
});
|
|
115
|
-
it('should extends webpack base config', async () => {
|
|
116
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
117
|
-
const webpackFinalConfig = await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
118
|
-
expect(webpackFinalConfig).toEqual({
|
|
119
|
-
...baseWebpackConfig,
|
|
120
|
-
module: { ...baseWebpackConfig.module, rules: expect.anything() },
|
|
121
|
-
plugins: expect.anything(),
|
|
122
|
-
resolve: {
|
|
123
|
-
...baseWebpackConfig.resolve,
|
|
124
|
-
modules: expect.arrayContaining(baseWebpackConfig.resolve.modules),
|
|
125
|
-
// the base resolve.plugins are not kept 🤷♂️
|
|
126
|
-
plugins: expect.arrayContaining([
|
|
127
|
-
expect.objectContaining({
|
|
128
|
-
absoluteBaseUrl: expect.any(String),
|
|
129
|
-
}),
|
|
130
|
-
]),
|
|
131
|
-
},
|
|
132
|
-
resolveLoader: expect.anything(),
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
it('should set webpack "module.rules"', async () => {
|
|
136
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
137
|
-
const webpackFinalConfig = await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
138
|
-
const expectedRules = [
|
|
139
|
-
{
|
|
140
|
-
oneOf: [
|
|
141
|
-
{
|
|
142
|
-
exclude: [],
|
|
143
|
-
use: expect.anything(),
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
include: [],
|
|
147
|
-
use: expect.anything(),
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
},
|
|
151
|
-
{ use: expect.anything() },
|
|
152
|
-
];
|
|
153
|
-
expect(webpackFinalConfig.module.rules).toEqual([
|
|
154
|
-
{
|
|
155
|
-
test: /\.(?:css)$/i,
|
|
156
|
-
rules: expectedRules,
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
test: /\.(?:scss)$/i,
|
|
160
|
-
rules: expectedRules,
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
test: /\.(?:sass)$/i,
|
|
164
|
-
rules: expectedRules,
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
test: /\.(?:less)$/i,
|
|
168
|
-
rules: expectedRules,
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
test: /\.(?:styl)$/i,
|
|
172
|
-
rules: expectedRules,
|
|
173
|
-
},
|
|
174
|
-
{ mimetype: 'text/css', use: expect.anything() },
|
|
175
|
-
{ mimetype: 'text/x-scss', use: expect.anything() },
|
|
176
|
-
{ mimetype: 'text/x-sass', use: expect.anything() },
|
|
177
|
-
{ mimetype: 'text/x-less', use: expect.anything() },
|
|
178
|
-
{ mimetype: 'text/x-stylus', use: expect.anything() },
|
|
179
|
-
...baseWebpackConfig.module.rules,
|
|
180
|
-
]);
|
|
181
|
-
});
|
|
182
|
-
it('should set webpack "plugins"', async () => {
|
|
183
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
184
|
-
const webpackFinalConfig = await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
185
|
-
expect(webpackFinalConfig.plugins).toMatchInlineSnapshot(`
|
|
186
|
-
Array [
|
|
187
|
-
AnyComponentStyleBudgetChecker {
|
|
188
|
-
"budgets": Array [],
|
|
189
|
-
},
|
|
190
|
-
Object {
|
|
191
|
-
"apply": [Function],
|
|
192
|
-
},
|
|
193
|
-
ContextReplacementPlugin {
|
|
194
|
-
"newContentCreateContextMap": [Function],
|
|
195
|
-
"newContentResource": "/Users/shilman/projects/baseline/storybook/app/angular/src/server/__mocks-ng-workspace__/minimal-config/$_lazy_route_resources",
|
|
196
|
-
"resourceRegExp": /\\\\@angular\\(\\\\\\\\\\|\\\\/\\)core\\(\\\\\\\\\\|\\\\/\\)/,
|
|
197
|
-
},
|
|
198
|
-
DedupeModuleResolvePlugin {
|
|
199
|
-
"modules": Map {},
|
|
200
|
-
"options": Object {
|
|
201
|
-
"verbose": undefined,
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
Object {
|
|
205
|
-
"keepBasePlugin": true,
|
|
206
|
-
},
|
|
207
|
-
]
|
|
208
|
-
`);
|
|
209
|
-
});
|
|
210
|
-
it('should set webpack "resolve.modules"', async () => {
|
|
211
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
212
|
-
const webpackFinalConfig = await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
213
|
-
expect(webpackFinalConfig.resolve.modules).toEqual([
|
|
214
|
-
...baseWebpackConfig.resolve.modules,
|
|
215
|
-
(0, core_1.getSystemPath)((0, core_1.normalize)(path_1.default.join(workspaceRoot, 'src'))).replace(/\\/g, '/'),
|
|
216
|
-
]);
|
|
217
|
-
});
|
|
218
|
-
it('should replace webpack "resolve.plugins"', async () => {
|
|
219
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
220
|
-
const webpackFinalConfig = await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
221
|
-
expect(webpackFinalConfig.resolve.plugins).toMatchInlineSnapshot(`
|
|
222
|
-
Array [
|
|
223
|
-
TsconfigPathsPlugin {
|
|
224
|
-
"absoluteBaseUrl": "`);
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
describe('when angular.json have "options.styles" config', () => {
|
|
228
|
-
beforeEach(() => {
|
|
229
|
-
initMockWorkspace('with-options-styles');
|
|
230
|
-
});
|
|
231
|
-
it('should extends webpack base config', async () => {
|
|
232
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
233
|
-
const webpackFinalConfig = await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
234
|
-
expect(webpackFinalConfig).toEqual({
|
|
235
|
-
...baseWebpackConfig,
|
|
236
|
-
entry: [
|
|
237
|
-
...baseWebpackConfig.entry,
|
|
238
|
-
path_1.default.join(workspaceRoot, 'src', 'styles.css'),
|
|
239
|
-
path_1.default.join(workspaceRoot, 'src', 'styles.scss'),
|
|
240
|
-
],
|
|
241
|
-
module: { ...baseWebpackConfig.module, rules: expect.anything() },
|
|
242
|
-
plugins: expect.anything(),
|
|
243
|
-
resolve: {
|
|
244
|
-
...baseWebpackConfig.resolve,
|
|
245
|
-
modules: expect.arrayContaining(baseWebpackConfig.resolve.modules),
|
|
246
|
-
// the base resolve.plugins are not kept 🤷♂️
|
|
247
|
-
plugins: expect.not.arrayContaining(baseWebpackConfig.resolve.plugins),
|
|
248
|
-
},
|
|
249
|
-
resolveLoader: expect.anything(),
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
it('should set webpack "module.rules"', async () => {
|
|
253
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
254
|
-
const webpackFinalConfig = await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
255
|
-
const expectedRules = [
|
|
256
|
-
{
|
|
257
|
-
oneOf: [
|
|
258
|
-
{
|
|
259
|
-
exclude: [`${workspaceRoot}/src/styles.css`, `${workspaceRoot}/src/styles.scss`],
|
|
260
|
-
use: expect.anything(),
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
include: [`${workspaceRoot}/src/styles.css`, `${workspaceRoot}/src/styles.scss`],
|
|
264
|
-
use: expect.anything(),
|
|
265
|
-
},
|
|
266
|
-
],
|
|
267
|
-
},
|
|
268
|
-
{ use: expect.anything() },
|
|
269
|
-
];
|
|
270
|
-
expect(webpackFinalConfig.module.rules).toEqual([
|
|
271
|
-
{
|
|
272
|
-
test: /\.(?:css)$/i,
|
|
273
|
-
rules: expectedRules,
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
test: /\.(?:scss)$/i,
|
|
277
|
-
rules: expectedRules,
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
test: /\.(?:sass)$/i,
|
|
281
|
-
rules: expectedRules,
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
test: /\.(?:less)$/i,
|
|
285
|
-
rules: expectedRules,
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
test: /\.(?:styl)$/i,
|
|
289
|
-
rules: expectedRules,
|
|
290
|
-
},
|
|
291
|
-
{ mimetype: 'text/css', use: expect.anything() },
|
|
292
|
-
{ mimetype: 'text/x-scss', use: expect.anything() },
|
|
293
|
-
{ mimetype: 'text/x-sass', use: expect.anything() },
|
|
294
|
-
{ mimetype: 'text/x-less', use: expect.anything() },
|
|
295
|
-
{ mimetype: 'text/x-stylus', use: expect.anything() },
|
|
296
|
-
...baseWebpackConfig.module.rules,
|
|
297
|
-
]);
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
describe('when angular.json haven\'t "options.tsConfig" config', () => {
|
|
301
|
-
beforeEach(() => {
|
|
302
|
-
initMockWorkspace('without-tsConfig');
|
|
303
|
-
});
|
|
304
|
-
it('throws error', async () => {
|
|
305
|
-
await expect(() => (0, framework_preset_angular_cli_1.webpackFinal)(newWebpackConfiguration(), options)).rejects.toThrowError('Missing required options in project target. Check "tsConfig"');
|
|
306
|
-
expect(node_logger_1.logger.error).toHaveBeenCalledWith(`=> Could not get angular cli webpack config`);
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
describe('when is a nx with angular.json', () => {
|
|
310
|
-
beforeEach(() => {
|
|
311
|
-
initMockWorkspace('with-nx');
|
|
312
|
-
});
|
|
313
|
-
it('should extends webpack base config', async () => {
|
|
314
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
315
|
-
const webpackFinalConfig = await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
316
|
-
expect(webpackFinalConfig).toEqual({
|
|
317
|
-
...baseWebpackConfig,
|
|
318
|
-
entry: [
|
|
319
|
-
...baseWebpackConfig.entry,
|
|
320
|
-
path_1.default.join(workspaceRoot, 'src', 'styles.css'),
|
|
321
|
-
path_1.default.join(workspaceRoot, 'src', 'styles.scss'),
|
|
322
|
-
],
|
|
323
|
-
module: { ...baseWebpackConfig.module, rules: expect.anything() },
|
|
324
|
-
plugins: expect.anything(),
|
|
325
|
-
resolve: {
|
|
326
|
-
...baseWebpackConfig.resolve,
|
|
327
|
-
modules: expect.arrayContaining(baseWebpackConfig.resolve.modules),
|
|
328
|
-
// the base resolve.plugins are not kept 🤷♂️
|
|
329
|
-
plugins: expect.not.arrayContaining(baseWebpackConfig.resolve.plugins),
|
|
330
|
-
},
|
|
331
|
-
resolveLoader: expect.anything(),
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
it('should set webpack "module.rules"', async () => {
|
|
335
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
336
|
-
const webpackFinalConfig = await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
337
|
-
const expectedRules = [
|
|
338
|
-
{
|
|
339
|
-
oneOf: [
|
|
340
|
-
{
|
|
341
|
-
exclude: [`${workspaceRoot}/src/styles.css`, `${workspaceRoot}/src/styles.scss`],
|
|
342
|
-
use: expect.anything(),
|
|
343
|
-
},
|
|
344
|
-
{
|
|
345
|
-
include: [`${workspaceRoot}/src/styles.css`, `${workspaceRoot}/src/styles.scss`],
|
|
346
|
-
use: expect.anything(),
|
|
347
|
-
},
|
|
348
|
-
],
|
|
349
|
-
},
|
|
350
|
-
{ use: expect.anything() },
|
|
351
|
-
];
|
|
352
|
-
expect(webpackFinalConfig.module.rules).toEqual([
|
|
353
|
-
{
|
|
354
|
-
test: /\.(?:css)$/i,
|
|
355
|
-
rules: expectedRules,
|
|
356
|
-
},
|
|
357
|
-
{
|
|
358
|
-
test: /\.(?:scss)$/i,
|
|
359
|
-
rules: expectedRules,
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
test: /\.(?:sass)$/i,
|
|
363
|
-
rules: expectedRules,
|
|
364
|
-
},
|
|
365
|
-
{
|
|
366
|
-
test: /\.(?:less)$/i,
|
|
367
|
-
rules: expectedRules,
|
|
368
|
-
},
|
|
369
|
-
{
|
|
370
|
-
test: /\.(?:styl)$/i,
|
|
371
|
-
rules: expectedRules,
|
|
372
|
-
},
|
|
373
|
-
{ mimetype: 'text/css', use: expect.anything() },
|
|
374
|
-
{ mimetype: 'text/x-scss', use: expect.anything() },
|
|
375
|
-
{ mimetype: 'text/x-sass', use: expect.anything() },
|
|
376
|
-
{ mimetype: 'text/x-less', use: expect.anything() },
|
|
377
|
-
{ mimetype: 'text/x-stylus', use: expect.anything() },
|
|
378
|
-
...baseWebpackConfig.module.rules,
|
|
379
|
-
]);
|
|
380
|
-
});
|
|
381
|
-
});
|
|
382
|
-
describe('when is a nx with workspace.json', () => {
|
|
383
|
-
beforeEach(() => {
|
|
384
|
-
initMockWorkspace('with-nx-workspace');
|
|
385
|
-
});
|
|
386
|
-
it('should extends webpack base config', async () => {
|
|
387
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
388
|
-
const webpackFinalConfig = await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
389
|
-
expect(webpackFinalConfig).toEqual({
|
|
390
|
-
...baseWebpackConfig,
|
|
391
|
-
entry: [
|
|
392
|
-
...baseWebpackConfig.entry,
|
|
393
|
-
path_1.default.join(workspaceRoot, 'src', 'styles.css'),
|
|
394
|
-
path_1.default.join(workspaceRoot, 'src', 'styles.scss'),
|
|
395
|
-
],
|
|
396
|
-
module: { ...baseWebpackConfig.module, rules: expect.anything() },
|
|
397
|
-
plugins: expect.anything(),
|
|
398
|
-
resolve: {
|
|
399
|
-
...baseWebpackConfig.resolve,
|
|
400
|
-
modules: expect.arrayContaining(baseWebpackConfig.resolve.modules),
|
|
401
|
-
// the base resolve.plugins are not kept 🤷♂️
|
|
402
|
-
plugins: expect.arrayContaining([
|
|
403
|
-
expect.objectContaining({
|
|
404
|
-
absoluteBaseUrl: expect.any(String),
|
|
405
|
-
}),
|
|
406
|
-
]),
|
|
407
|
-
},
|
|
408
|
-
resolveLoader: expect.anything(),
|
|
409
|
-
});
|
|
410
|
-
});
|
|
411
|
-
it('should set webpack "module.rules"', async () => {
|
|
412
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
413
|
-
const webpackFinalConfig = await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
414
|
-
const expectedRules = [
|
|
415
|
-
{
|
|
416
|
-
oneOf: [
|
|
417
|
-
{
|
|
418
|
-
exclude: [`${workspaceRoot}/src/styles.css`, `${workspaceRoot}/src/styles.scss`],
|
|
419
|
-
use: expect.anything(),
|
|
420
|
-
},
|
|
421
|
-
{
|
|
422
|
-
include: [`${workspaceRoot}/src/styles.css`, `${workspaceRoot}/src/styles.scss`],
|
|
423
|
-
use: expect.anything(),
|
|
424
|
-
},
|
|
425
|
-
],
|
|
426
|
-
},
|
|
427
|
-
{ use: expect.anything() },
|
|
428
|
-
];
|
|
429
|
-
expect(webpackFinalConfig.module.rules).toEqual([
|
|
430
|
-
{
|
|
431
|
-
test: /\.(?:css)$/i,
|
|
432
|
-
rules: expectedRules,
|
|
433
|
-
},
|
|
434
|
-
{
|
|
435
|
-
test: /\.(?:scss)$/i,
|
|
436
|
-
rules: expectedRules,
|
|
437
|
-
},
|
|
438
|
-
{
|
|
439
|
-
test: /\.(?:sass)$/i,
|
|
440
|
-
rules: expectedRules,
|
|
441
|
-
},
|
|
442
|
-
{
|
|
443
|
-
test: /\.(?:less)$/i,
|
|
444
|
-
rules: expectedRules,
|
|
445
|
-
},
|
|
446
|
-
{
|
|
447
|
-
test: /\.(?:styl)$/i,
|
|
448
|
-
rules: expectedRules,
|
|
449
|
-
},
|
|
450
|
-
{ mimetype: 'text/css', use: expect.anything() },
|
|
451
|
-
{ mimetype: 'text/x-scss', use: expect.anything() },
|
|
452
|
-
{ mimetype: 'text/x-sass', use: expect.anything() },
|
|
453
|
-
{ mimetype: 'text/x-less', use: expect.anything() },
|
|
454
|
-
{ mimetype: 'text/x-stylus', use: expect.anything() },
|
|
455
|
-
...baseWebpackConfig.module.rules,
|
|
456
|
-
]);
|
|
457
|
-
});
|
|
458
|
-
});
|
|
459
|
-
describe('when angular.json have only one lib project', () => {
|
|
460
|
-
beforeEach(() => {
|
|
461
|
-
initMockWorkspace('with-lib');
|
|
462
|
-
});
|
|
463
|
-
it('should extends webpack base config', async () => {
|
|
464
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
465
|
-
const webpackFinalConfig = await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
466
|
-
expect(webpackFinalConfig).toEqual({
|
|
467
|
-
...baseWebpackConfig,
|
|
468
|
-
entry: [...baseWebpackConfig.entry],
|
|
469
|
-
module: { ...baseWebpackConfig.module, rules: expect.anything() },
|
|
470
|
-
plugins: expect.anything(),
|
|
471
|
-
resolve: {
|
|
472
|
-
...baseWebpackConfig.resolve,
|
|
473
|
-
modules: expect.arrayContaining(baseWebpackConfig.resolve.modules),
|
|
474
|
-
// the base resolve.plugins are not kept 🤷♂️
|
|
475
|
-
plugins: expect.not.arrayContaining(baseWebpackConfig.resolve.plugins),
|
|
476
|
-
},
|
|
477
|
-
resolveLoader: expect.anything(),
|
|
478
|
-
});
|
|
479
|
-
});
|
|
480
|
-
it('should set webpack "module.rules"', async () => {
|
|
481
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
482
|
-
const webpackFinalConfig = await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
483
|
-
const expectedRules = [
|
|
484
|
-
{
|
|
485
|
-
oneOf: [
|
|
486
|
-
{
|
|
487
|
-
exclude: [],
|
|
488
|
-
use: expect.anything(),
|
|
489
|
-
},
|
|
490
|
-
{
|
|
491
|
-
include: [],
|
|
492
|
-
use: expect.anything(),
|
|
493
|
-
},
|
|
494
|
-
],
|
|
495
|
-
},
|
|
496
|
-
{ use: expect.anything() },
|
|
497
|
-
];
|
|
498
|
-
expect(webpackFinalConfig.module.rules).toEqual([
|
|
499
|
-
{
|
|
500
|
-
test: /\.(?:css)$/i,
|
|
501
|
-
rules: expectedRules,
|
|
502
|
-
},
|
|
503
|
-
{
|
|
504
|
-
test: /\.(?:scss)$/i,
|
|
505
|
-
rules: expectedRules,
|
|
506
|
-
},
|
|
507
|
-
{
|
|
508
|
-
test: /\.(?:sass)$/i,
|
|
509
|
-
rules: expectedRules,
|
|
510
|
-
},
|
|
511
|
-
{
|
|
512
|
-
test: /\.(?:less)$/i,
|
|
513
|
-
rules: expectedRules,
|
|
514
|
-
},
|
|
515
|
-
{
|
|
516
|
-
test: /\.(?:styl)$/i,
|
|
517
|
-
rules: expectedRules,
|
|
518
|
-
},
|
|
519
|
-
{ mimetype: 'text/css', use: expect.anything() },
|
|
520
|
-
{ mimetype: 'text/x-scss', use: expect.anything() },
|
|
521
|
-
{ mimetype: 'text/x-sass', use: expect.anything() },
|
|
522
|
-
{ mimetype: 'text/x-less', use: expect.anything() },
|
|
523
|
-
{ mimetype: 'text/x-stylus', use: expect.anything() },
|
|
524
|
-
...baseWebpackConfig.module.rules,
|
|
525
|
-
]);
|
|
526
|
-
});
|
|
527
|
-
});
|
|
528
|
-
describe('when angular.json have some config', () => {
|
|
529
|
-
beforeEach(() => {
|
|
530
|
-
initMockWorkspace('some-config');
|
|
531
|
-
});
|
|
532
|
-
it('should log', async () => {
|
|
533
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
534
|
-
await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
535
|
-
expect(node_logger_1.logger.info).toHaveBeenCalledTimes(3);
|
|
536
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(1, '=> Loading angular-cli config for angular lower than 12.2.0');
|
|
537
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(2, '=> Using angular project "foo-project:build" for configuring Storybook');
|
|
538
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(3, '=> Using angular-cli webpack config');
|
|
539
|
-
});
|
|
540
|
-
});
|
|
541
|
-
describe('with angularBrowserTarget option', () => {
|
|
542
|
-
beforeEach(() => {
|
|
543
|
-
initMockWorkspace('with-angularBrowserTarget');
|
|
544
|
-
options = { angularBrowserTarget: 'target-project:target-build' };
|
|
545
|
-
});
|
|
546
|
-
it('should log', async () => {
|
|
547
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
548
|
-
await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
549
|
-
expect(node_logger_1.logger.info).toHaveBeenCalledTimes(3);
|
|
550
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(1, '=> Loading angular-cli config for angular lower than 12.2.0');
|
|
551
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(2, '=> Using angular project "target-project:target-build" for configuring Storybook');
|
|
552
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(3, '=> Using angular-cli webpack config');
|
|
553
|
-
});
|
|
554
|
-
});
|
|
555
|
-
describe('with angularBrowserTarget option with configuration', () => {
|
|
556
|
-
beforeEach(() => {
|
|
557
|
-
initMockWorkspace('with-angularBrowserTarget');
|
|
558
|
-
});
|
|
559
|
-
describe('when angular.json have the target without "configurations" section', () => {
|
|
560
|
-
beforeEach(() => {
|
|
561
|
-
options = {
|
|
562
|
-
angularBrowserTarget: 'no-confs-project:target-build:target-conf',
|
|
563
|
-
};
|
|
564
|
-
});
|
|
565
|
-
it('throws error', async () => {
|
|
566
|
-
await expect(() => (0, framework_preset_angular_cli_1.webpackFinal)(newWebpackConfiguration(), options)).rejects.toThrowError('Missing "configurations" section in project target');
|
|
567
|
-
expect(node_logger_1.logger.error).toHaveBeenCalledWith(`=> Could not get angular cli webpack config`);
|
|
568
|
-
});
|
|
569
|
-
});
|
|
570
|
-
describe('when angular.json have the target without required configuration', () => {
|
|
571
|
-
beforeEach(() => {
|
|
572
|
-
options = {
|
|
573
|
-
angularBrowserTarget: 'no-target-conf-project:target-build:target-conf',
|
|
574
|
-
};
|
|
575
|
-
});
|
|
576
|
-
it('throws error', async () => {
|
|
577
|
-
await expect(() => (0, framework_preset_angular_cli_1.webpackFinal)(newWebpackConfiguration(), options)).rejects.toThrowError('Missing required configuration in project target. Check "target-conf"');
|
|
578
|
-
expect(node_logger_1.logger.error).toHaveBeenCalledWith(`=> Could not get angular cli webpack config`);
|
|
579
|
-
});
|
|
580
|
-
});
|
|
581
|
-
describe('when angular.json have the target with required configuration', () => {
|
|
582
|
-
beforeEach(() => {
|
|
583
|
-
options = {
|
|
584
|
-
angularBrowserTarget: 'target-project:target-build:target-conf',
|
|
585
|
-
};
|
|
586
|
-
});
|
|
587
|
-
it('should log', async () => {
|
|
588
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
589
|
-
await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
590
|
-
expect(node_logger_1.logger.info).toHaveBeenCalledTimes(3);
|
|
591
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(1, '=> Loading angular-cli config for angular lower than 12.2.0');
|
|
592
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(2, '=> Using angular project "target-project:target-build:target-conf" for configuring Storybook');
|
|
593
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(3, '=> Using angular-cli webpack config');
|
|
594
|
-
});
|
|
595
|
-
it('should extends webpack base config', async () => {
|
|
596
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
597
|
-
const webpackFinalConfig = await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
598
|
-
expect(webpackFinalConfig).toEqual({
|
|
599
|
-
...baseWebpackConfig,
|
|
600
|
-
entry: [
|
|
601
|
-
...baseWebpackConfig.entry,
|
|
602
|
-
path_1.default.join(workspaceRoot, 'src', 'styles.css'),
|
|
603
|
-
],
|
|
604
|
-
module: { ...baseWebpackConfig.module, rules: expect.anything() },
|
|
605
|
-
plugins: expect.anything(),
|
|
606
|
-
resolve: {
|
|
607
|
-
...baseWebpackConfig.resolve,
|
|
608
|
-
modules: expect.arrayContaining(baseWebpackConfig.resolve.modules),
|
|
609
|
-
// the base resolve.plugins are not kept 🤷♂️
|
|
610
|
-
plugins: expect.not.arrayContaining(baseWebpackConfig.resolve.plugins),
|
|
611
|
-
},
|
|
612
|
-
resolveLoader: expect.anything(),
|
|
613
|
-
});
|
|
614
|
-
});
|
|
615
|
-
});
|
|
616
|
-
});
|
|
617
|
-
describe('with only tsConfig option', () => {
|
|
618
|
-
beforeEach(() => {
|
|
619
|
-
initMockWorkspace('without-projects-entry');
|
|
620
|
-
options = {
|
|
621
|
-
tsConfig: 'projects/pattern-lib/tsconfig.lib.json',
|
|
622
|
-
angularBrowserTarget: null,
|
|
623
|
-
};
|
|
624
|
-
});
|
|
625
|
-
it('should log', async () => {
|
|
626
|
-
const baseWebpackConfig = newWebpackConfiguration();
|
|
627
|
-
await (0, framework_preset_angular_cli_1.webpackFinal)(baseWebpackConfig, options);
|
|
628
|
-
expect(node_logger_1.logger.info).toHaveBeenCalledTimes(3);
|
|
629
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(1, '=> Loading angular-cli config for angular lower than 12.2.0');
|
|
630
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(2, '=> Using default angular project with "tsConfig:projects/pattern-lib/tsconfig.lib.json"');
|
|
631
|
-
expect(node_logger_1.logger.info).toHaveBeenNthCalledWith(3, '=> Using angular-cli webpack config');
|
|
632
|
-
});
|
|
633
|
-
});
|
|
634
|
-
});
|
|
635
|
-
const newWebpackConfiguration = (transformer = (c) => c) => {
|
|
636
|
-
return transformer({
|
|
637
|
-
name: 'preview',
|
|
638
|
-
mode: 'development',
|
|
639
|
-
bail: false,
|
|
640
|
-
devtool: 'cheap-module-source-map',
|
|
641
|
-
entry: [
|
|
642
|
-
'/Users/joe/storybook/lib/core-server/dist/esm/globals/polyfills.js',
|
|
643
|
-
'/Users/joe/storybook/examples/angular-cli/.storybook/storybook-init-framework-entry.js',
|
|
644
|
-
'/Users/joe/storybook/addons/docs/dist/esm/frameworks/common/config.js-generated-other-entry.js',
|
|
645
|
-
'/Users/joe/storybook/addons/docs/dist/esm/frameworks/angular/config.js-generated-other-entry.js',
|
|
646
|
-
'/Users/joe/storybook/addons/actions/dist/esm/preset/addDecorator.js-generated-other-entry.js',
|
|
647
|
-
'/Users/joe/storybook/addons/actions/dist/esm/preset/addArgs.js-generated-other-entry.js',
|
|
648
|
-
'/Users/joe/storybook/addons/links/dist/esm/preset/addDecorator.js-generated-other-entry.js',
|
|
649
|
-
'/Users/joe/storybook/addons/knobs/dist/esm/preset/addDecorator.js-generated-other-entry.js',
|
|
650
|
-
'/Users/joe/storybook/addons/backgrounds/dist/esm/preset/addDecorator.js-generated-other-entry.js',
|
|
651
|
-
'/Users/joe/storybook/addons/backgrounds/dist/esm/preset/addParameter.js-generated-other-entry.js',
|
|
652
|
-
'/Users/joe/storybook/addons/a11y/dist/esm/a11yRunner.js-generated-other-entry.js',
|
|
653
|
-
'/Users/joe/storybook/addons/a11y/dist/esm/a11yHighlight.js-generated-other-entry.js',
|
|
654
|
-
'/Users/joe/storybook/examples/angular-cli/.storybook/preview.ts-generated-config-entry.js',
|
|
655
|
-
'/Users/joe/storybook/examples/angular-cli/.storybook/generated-stories-entry.js',
|
|
656
|
-
'/Users/joe/storybook/node_modules/webpack-hot-middleware/client.js?reload=true&quiet=false&noInfo=undefined',
|
|
657
|
-
],
|
|
658
|
-
output: {
|
|
659
|
-
path: '/Users/joe/storybook/examples/angular-cli/node_modules/.cache/storybook/public',
|
|
660
|
-
filename: '[name].[hash].bundle.js',
|
|
661
|
-
publicPath: '',
|
|
662
|
-
},
|
|
663
|
-
plugins: [{ keepBasePlugin: true }],
|
|
664
|
-
module: {
|
|
665
|
-
rules: [{ keepBaseRule: true }],
|
|
666
|
-
},
|
|
667
|
-
resolve: {
|
|
668
|
-
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'],
|
|
669
|
-
modules: ['node_modules'],
|
|
670
|
-
mainFields: ['browser', 'main'],
|
|
671
|
-
alias: {
|
|
672
|
-
'@storybook/preview-api': '/Users/joe/storybook/lib/addons',
|
|
673
|
-
'@storybook/manager-api': '/Users/joe/storybook/lib/api',
|
|
674
|
-
'@storybook/channels': '/Users/joe/storybook/lib/channels',
|
|
675
|
-
'@storybook/channel-postmessage': '/Users/joe/storybook/lib/channel-postmessage',
|
|
676
|
-
'@storybook/components': '/Users/joe/storybook/ui/components',
|
|
677
|
-
'@storybook/core-events': '/Users/joe/storybook/lib/core-events',
|
|
678
|
-
'@storybook/router': '/Users/joe/storybook/lib/router',
|
|
679
|
-
'@storybook/theming': '/Users/joe/storybook/lib/theming',
|
|
680
|
-
'@storybook/client-api': '/Users/joe/storybook/lib/client-api',
|
|
681
|
-
'@storybook/client-logger': '/Users/joe/storybook/lib/client-logger',
|
|
682
|
-
react: '/Users/joe/storybook/node_modules/react',
|
|
683
|
-
'react-dom': '/Users/joe/storybook/node_modules/react-dom',
|
|
684
|
-
},
|
|
685
|
-
plugins: [{ keepBasePlugin: true }],
|
|
686
|
-
},
|
|
687
|
-
resolveLoader: { plugins: [] },
|
|
688
|
-
optimization: {
|
|
689
|
-
splitChunks: { chunks: 'all' },
|
|
690
|
-
runtimeChunk: true,
|
|
691
|
-
sideEffects: true,
|
|
692
|
-
usedExports: true,
|
|
693
|
-
concatenateModules: true,
|
|
694
|
-
minimizer: [],
|
|
695
|
-
},
|
|
696
|
-
performance: { hints: false },
|
|
697
|
-
});
|
|
698
|
-
};
|