forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex_spec.ts
More file actions
139 lines (126 loc) · 5.36 KB
/
index_spec.ts
File metadata and controls
139 lines (126 loc) · 5.36 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import { parse as parseJson } from 'jsonc-parser';
import { latestVersions } from '../utility/latest-versions';
import { Schema as WorkspaceOptions } from './schema';
describe('Workspace Schematic', () => {
const schematicRunner = new SchematicTestRunner(
'@schematics/angular',
require.resolve('../collection.json'),
);
const defaultOptions: WorkspaceOptions = {
name: 'foo',
version: '6.0.0',
};
it('should create all files of a workspace', async () => {
const options = { ...defaultOptions };
const tree = await schematicRunner.runSchematic('workspace', options);
const files = tree.files;
expect(files).toEqual(
jasmine.arrayContaining([
'/.vscode/extensions.json',
'/.vscode/launch.json',
'/.vscode/mcp.json',
'/.vscode/tasks.json',
'/.editorconfig',
'/angular.json',
'/.gitignore',
'/package.json',
'/README.md',
'/tsconfig.json',
]),
);
});
it('should set the name in package.json', async () => {
const tree = await schematicRunner.runSchematic('workspace', defaultOptions);
const pkg = JSON.parse(tree.readContent('/package.json'));
expect(pkg.name).toEqual('foo');
});
it('should set the CLI version in package.json', async () => {
const tree = await schematicRunner.runSchematic('workspace', defaultOptions);
const pkg = JSON.parse(tree.readContent('/package.json'));
expect(pkg.devDependencies['@angular/cli']).toMatch('6.0.0');
});
it('should use the latest known versions in package.json', async () => {
const tree = await schematicRunner.runSchematic('workspace', defaultOptions);
const pkg = JSON.parse(tree.readContent('/package.json'));
expect(pkg.dependencies['@angular/core']).toEqual(latestVersions.Angular);
expect(pkg.dependencies['rxjs']).toEqual(latestVersions['rxjs']);
expect(pkg.devDependencies['typescript']).toEqual(latestVersions['typescript']);
});
it('should create correct files when using minimal', async () => {
const tree = await schematicRunner.runSchematic('workspace', {
...defaultOptions,
minimal: true,
});
const files = tree.files;
expect(files).toEqual(
jasmine.arrayContaining([
'/.vscode/extensions.json',
'/.vscode/launch.json',
'/.vscode/mcp.json',
'/.vscode/tasks.json',
'/angular.json',
'/.gitignore',
'/package.json',
'/README.md',
'/tsconfig.json',
]),
);
expect(files).not.toContain('/.editorconfig');
});
it('should set the `enableI18nLegacyMessageIdFormat` Angular compiler option', async () => {
const tree = await schematicRunner.runSchematic('workspace', defaultOptions);
const { angularCompilerOptions } = parseJson(tree.readContent('tsconfig.json').toString());
expect(angularCompilerOptions.enableI18nLegacyMessageIdFormat).toBe(false);
});
it('should not add strict compiler options when false', async () => {
const tree = await schematicRunner.runSchematic('workspace', {
...defaultOptions,
strict: false,
});
const { compilerOptions, angularCompilerOptions } = parseJson(
tree.readContent('tsconfig.json').toString(),
);
expect(compilerOptions.strict).toBeUndefined();
expect(angularCompilerOptions.strictTemplates).toBeFalse();
expect(angularCompilerOptions.strictInputAccessModifiers).toBeUndefined();
expect(angularCompilerOptions.strictInjectionParameters).toBeUndefined();
});
it('should add strict compiler options when true', async () => {
const tree = await schematicRunner.runSchematic('workspace', {
...defaultOptions,
strict: true,
});
const { compilerOptions, angularCompilerOptions } = parseJson(
tree.readContent('tsconfig.json').toString(),
);
expect(compilerOptions.strict).toBeTrue();
expect(angularCompilerOptions.strictTemplates).toBeUndefined();
expect(angularCompilerOptions.strictInputAccessModifiers).toBeTrue();
expect(angularCompilerOptions.strictInjectionParameters).toBeTrue();
});
it('should add vscode testing configuration', async () => {
const tree = await schematicRunner.runSchematic('workspace', { ...defaultOptions });
const { configurations } = parseJson(tree.readContent('.vscode/launch.json').toString());
expect(configurations).toContain(jasmine.objectContaining({ name: 'ng test' }));
const { tasks } = parseJson(tree.readContent('.vscode/tasks.json').toString());
expect(tasks).toContain(jasmine.objectContaining({ type: 'npm', script: 'test' }));
});
it('should not add vscode testing configuration when using minimal', async () => {
const tree = await schematicRunner.runSchematic('workspace', {
...defaultOptions,
minimal: true,
});
const { configurations } = parseJson(tree.readContent('.vscode/launch.json').toString());
expect(configurations).not.toContain(jasmine.objectContaining({ name: 'ng test' }));
const { tasks } = parseJson(tree.readContent('.vscode/tasks.json').toString());
expect(tasks).not.toContain(jasmine.objectContaining({ type: 'npm', script: 'test' }));
});
});