Skip to content

Commit 5a486cb

Browse files
Julien-Marcoualan-agius4
authored andcommitted
fix(@schematics/angular): remove vscode testing configurations for minimal workspaces
Remove the `ng test` VS Code task and `npm test` VS Code launch configuration from the workspace when building minimal workspaces. Fixes #23360 (cherry picked from commit 7cbbf2f)
1 parent bd99a61 commit 5a486cb

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

packages/schematics/angular/workspace/files/__dot__vscode/launch.json.template

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
"request": "launch",
99
"preLaunchTask": "npm: start",
1010
"url": "http://localhost:4200/"
11-
},
11+
}<% if (!minimal) { %>,
1212
{
1313
"name": "ng test",
1414
"type": "chrome",
1515
"request": "launch",
1616
"preLaunchTask": "npm: test",
1717
"url": "http://localhost:9876/debug.html"
18-
}
18+
}<% } %>
1919
]
2020
}

packages/schematics/angular/workspace/files/__dot__vscode/tasks.json.template

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
}
2121
}
22-
},
22+
}<% if (!minimal) { %>,
2323
{
2424
"type": "npm",
2525
"script": "test",
@@ -37,6 +37,6 @@
3737
}
3838
}
3939
}
40-
}
40+
}<% } %>
4141
]
4242
}

packages/schematics/angular/workspace/index_spec.ts

+26
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ describe('Workspace Schematic', () => {
2828
const files = tree.files;
2929
expect(files).toEqual(
3030
jasmine.arrayContaining([
31+
'/.vscode/extensions.json',
32+
'/.vscode/launch.json',
33+
'/.vscode/tasks.json',
3134
'/.editorconfig',
3235
'/angular.json',
3336
'/.gitignore',
@@ -66,6 +69,9 @@ describe('Workspace Schematic', () => {
6669
const files = tree.files;
6770
expect(files).toEqual(
6871
jasmine.arrayContaining([
72+
'/.vscode/extensions.json',
73+
'/.vscode/launch.json',
74+
'/.vscode/tasks.json',
6975
'/angular.json',
7076
'/.gitignore',
7177
'/package.json',
@@ -106,4 +112,24 @@ describe('Workspace Schematic', () => {
106112
expect(compilerOptions.strict).toBe(true);
107113
expect(angularCompilerOptions.strictTemplates).toBe(true);
108114
});
115+
116+
it('should add vscode testing configuration', async () => {
117+
const tree = await schematicRunner
118+
.runSchematicAsync('workspace', { ...defaultOptions })
119+
.toPromise();
120+
const { configurations } = parseJson(tree.readContent('.vscode/launch.json').toString());
121+
expect(configurations).toContain(jasmine.objectContaining({ name: 'ng test' }));
122+
const { tasks } = parseJson(tree.readContent('.vscode/tasks.json').toString());
123+
expect(tasks).toContain(jasmine.objectContaining({ type: 'npm', script: 'test' }));
124+
});
125+
126+
it('should not add vscode testing configuration when using minimal', async () => {
127+
const tree = await schematicRunner
128+
.runSchematicAsync('workspace', { ...defaultOptions, minimal: true })
129+
.toPromise();
130+
const { configurations } = parseJson(tree.readContent('.vscode/launch.json').toString());
131+
expect(configurations).not.toContain(jasmine.objectContaining({ name: 'ng test' }));
132+
const { tasks } = parseJson(tree.readContent('.vscode/tasks.json').toString());
133+
expect(tasks).not.toContain(jasmine.objectContaining({ type: 'npm', script: 'test' }));
134+
});
109135
});

0 commit comments

Comments
 (0)