Skip to content

Commit 61b7346

Browse files
committed
Fix generate assets feature tests
1 parent b95a834 commit 61b7346

File tree

1 file changed

+52
-24
lines changed

1 file changed

+52
-24
lines changed

test/featureTests/assets.test.ts

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as path from 'path';
77
import * as protocol from '../../src/omnisharp/protocol';
88
import * as vscode from 'vscode';
99
import * as jsonc from 'jsonc-parser';
10-
// import { FormattingOptions } from 'jsonc-parser';
10+
// import { FormattingOptions } from 'jsonc-parser';
1111

1212
import { AssetGenerator, ProgramLaunchType, replaceCommentPropertiesWithComments, updateJsonWithComments } from '../../src/assets';
1313
import { parse } from 'jsonc-parser';
@@ -29,24 +29,52 @@ suite("Asset generation: csproj", () => {
2929
segments.should.deep.equal(['${workspaceFolder}', 'testApp.csproj']);
3030
});
3131

32-
test("Generated tasks.json has the property GenerateFullPaths set to true ", () => {
32+
test("Generated 'build' and 'publish' tasks have the property GenerateFullPaths set to true ", () => {
3333
let rootPath = path.resolve('testRoot');
3434
let info = createMSBuildWorkspaceInformation(path.join(rootPath, 'testApp.csproj'), 'testApp', 'netcoreapp1.0');
3535
let generator = new AssetGenerator(info, createMockWorkspaceFolder(rootPath));
3636
generator.setStartupProject(0);
3737
let tasksJson = generator.createTasksConfiguration();
3838

39-
tasksJson.tasks.forEach(task => task.args.should.contain("/property:GenerateFullPaths=true"));
39+
// We do not check the watch task since this parameter can break hot reload scenarios.
40+
tasksJson.tasks
41+
.filter(task => task.label !== "watch")
42+
.forEach(task => task.args.should.contain("/property:GenerateFullPaths=true"));
4043
});
4144

42-
test("Generated tasks.json has the consoleloggerparameters argument set to NoSummary", () => {
45+
test("Generated 'build' and 'publish' tasks have the consoleloggerparameters argument set to NoSummary", () => {
4346
let rootPath = path.resolve('testRoot');
4447
let info = createMSBuildWorkspaceInformation(path.join(rootPath, 'testApp.csproj'), 'testApp', 'netcoreapp1.0');
4548
let generator = new AssetGenerator(info, createMockWorkspaceFolder(rootPath));
4649
generator.setStartupProject(0);
4750
let tasksJson = generator.createTasksConfiguration();
4851

49-
tasksJson.tasks.forEach(task => task.args.should.contain("/consoleloggerparameters:NoSummary"));
52+
// We do not check the watch task since this parameter can break hot reload scenarios.
53+
tasksJson.tasks
54+
.filter(task => task.label !== "watch")
55+
.forEach(task => task.args.should.contain("/consoleloggerparameters:NoSummary"));
56+
});
57+
58+
test("Generated 'watch' task does not have the property GenerateFullPaths set to true ", () => {
59+
let rootPath = path.resolve('testRoot');
60+
let info = createMSBuildWorkspaceInformation(path.join(rootPath, 'testApp.csproj'), 'testApp', 'netcoreapp1.0');
61+
let generator = new AssetGenerator(info, createMockWorkspaceFolder(rootPath));
62+
generator.setStartupProject(0);
63+
let tasksJson = generator.createTasksConfiguration();
64+
65+
const watchTask = tasksJson.tasks.find(task => task.label === "watch");
66+
watchTask.args.should.not.contain("/property:GenerateFullPaths=true");
67+
});
68+
69+
test("Generated 'watch' task does not have the consoleloggerparameters argument set to NoSummary", () => {
70+
let rootPath = path.resolve('testRoot');
71+
let info = createMSBuildWorkspaceInformation(path.join(rootPath, 'testApp.csproj'), 'testApp', 'netcoreapp1.0');
72+
let generator = new AssetGenerator(info, createMockWorkspaceFolder(rootPath));
73+
generator.setStartupProject(0);
74+
let tasksJson = generator.createTasksConfiguration();
75+
76+
const watchTask = tasksJson.tasks.find(task => task.label === "watch");
77+
watchTask.args.should.not.contain("/consoleloggerparameters:NoSummary");
5078
});
5179

5280
test("Create tasks.json for nested project opened in workspace", () => {
@@ -205,80 +233,80 @@ suite("Asset generation: csproj", () => {
205233

206234
test("Add a new item to JSON", () => {
207235
const existingItem = { name: 'existing-item' };
208-
const original = {
236+
const original = {
209237
configurations: [
210238
existingItem
211239
]
212240
};
213241

214-
const newItem = { name: 'new-item' };
242+
const newItem = { name: 'new-item' };
215243
const updated = updateJsonWithComments(JSON.stringify(original), [newItem], 'configurations', 'name', /*formattingOptions*/ null);
216244
const parsed = jsonc.parse(updated);
217245
const configurations = parsed.configurations;
218246

219-
const expected = [ existingItem, newItem ];
247+
const expected = [existingItem, newItem];
220248
configurations.should.deep.equal(expected);
221249
});
222250

223251
test("Update item in JSON", () => {
224252
const existingItem = { name: 'existing-item', command: 'cmd' };
225-
const original = {
253+
const original = {
226254
configurations: [
227255
// this should update to have command dotnet, because the name is the same as our updated item
228256
{ name: 'build', command: 'old value' },
229257
existingItem
230258
]
231259
};
232260

233-
const updatedItem = { name: 'build', command: 'dotnet' };
234-
261+
const updatedItem = { name: 'build', command: 'dotnet' };
262+
235263
const updated = updateJsonWithComments(JSON.stringify(original), [updatedItem], 'configurations', 'name', /*formattingOptions*/ null);
236264
const parsed = jsonc.parse(updated);
237265
const configurations = parsed.configurations;
238266

239-
const expected = [ updatedItem, existingItem ];
267+
const expected = [updatedItem, existingItem];
240268
configurations.should.deep.equal(expected);
241269
});
242270

243271
test("Update JSON and preserve all comments", () => {
244272
const original = `
245273
// user comment in file
246-
{
274+
{
247275
"configurations": [
248276
{ "name": "build", "command": "old value" },
249-
{
277+
{
250278
// user comment in their configuration
251-
"name": "existing-item",
252-
"command": "cmd"
279+
"name": "existing-item",
280+
"command": "cmd"
253281
}
254282
]
255283
}`;
256284

257-
const updatedItem = { name: 'build', command: 'dotnet' };
258-
285+
const updatedItem = { name: 'build', command: 'dotnet' };
286+
259287
const updated = updateJsonWithComments(original, [updatedItem], 'configurations', 'name', /*formattingOptions*/ null);
260288
const lines = updated.trim().split('\n');
261-
289+
262290
lines[0].trim().should.equal('// user comment in file');
263291
lines[5].trim().should.equal('// user comment in their configuration');
264292
});
265293

266294
test("Replace items named OS-COMMENTxxx with JSON comment syntax", () => {
267295
const original = `
268-
{
296+
{
269297
"configurations": [
270-
{
271-
"name": "build",
298+
{
299+
"name": "build",
272300
"OS-COMMENT": "This is a dotnet build command",
273301
"OS-COMMENT2": "this is the default command.",
274-
"command": "dotnet build"
302+
"command": "dotnet build"
275303
},
276304
]
277305
}`;
278306

279307
let updated = replaceCommentPropertiesWithComments(original);
280308
let lines = updated.trim().split('\n');
281-
309+
282310
lines[4].trim().should.equal('// This is a dotnet build command');
283311
lines[5].trim().should.equal('// this is the default command.');
284312
});

0 commit comments

Comments
 (0)