-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
angular-cli_config.test.ts
82 lines (71 loc) · 2.63 KB
/
angular-cli_config.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import stripJsonComments from 'strip-json-comments';
import { Path } from '@angular-devkit/core';
import * as fs from 'fs';
import * as path from 'path';
import {
applyAngularCliWebpackConfig,
getAngularCliWebpackConfigOptions,
getLeadingAngularCliProject,
} from '../angular-cli_config';
describe('angular-cli_config', () => {
it('should return have empty `buildOptions.sourceMap` and `buildOptions.optimization` by default', () => {
const config = getAngularCliWebpackConfigOptions(__dirname as Path);
expect(config).toMatchObject({
buildOptions: {
sourceMap: {},
optimization: {},
},
});
});
it('should use `storybook` project by default when `storybook` project is defined', () => {
// Lazy clone example angular json
const angularJson = fs.readFileSync(path.resolve(__dirname, 'angular.json'), 'utf8');
const angularJsonWithStorybookProject = JSON.parse(stripJsonComments(angularJson));
// Add storybook project
angularJsonWithStorybookProject.projects.storybook = {
architect: {
build: {
options: {
assets: [],
styles: ['custom/styles'],
},
},
},
};
const projectConfig = getLeadingAngularCliProject(angularJsonWithStorybookProject);
// Assure configuration matches values from `storybook` project
expect(projectConfig).toMatchObject({
architect: {
build: {
options: {
assets: [],
styles: ['custom/styles'],
},
},
},
});
});
it('should return null if `architect.build` option are not exists.', () => {
const angularJson = fs.readFileSync(path.resolve(__dirname, 'angular.json'), 'utf8');
const angularJsonWithNoBuildOptions = JSON.parse(stripJsonComments(angularJson));
angularJsonWithNoBuildOptions.projects['angular-cli'].architect.build = undefined;
getLeadingAngularCliProject(angularJsonWithNoBuildOptions);
const config = getAngularCliWebpackConfigOptions('/' as Path);
expect(config).toBeNull();
});
it('should return baseConfig if no angular.json was found', () => {
const baseConfig = { test: 'config' };
const projectConfig = getAngularCliWebpackConfigOptions('test-path' as Path);
const config = applyAngularCliWebpackConfig(baseConfig, projectConfig);
expect(projectConfig).toBe(null);
expect(config).toBe(baseConfig);
});
it('should return empty `buildOptions.budgets` by default', () => {
const config = getAngularCliWebpackConfigOptions(__dirname as Path);
expect(config).toMatchObject({
buildOptions: {
budgets: [],
},
});
});
});