Skip to content

Commit be42bff

Browse files
committed
Maybe trying to apply the edits is what makes this flaky
1 parent 084381e commit be42bff

File tree

1 file changed

+30
-41
lines changed

1 file changed

+30
-41
lines changed

test/razorIntegrationTests/formatting.integration.test.ts

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ import { describe, beforeAll, afterAll, test, expect } from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
1010
import * as integrationHelpers from '../integrationTests/integrationHelpers';
1111

12-
function normalizeNewlines(original: string | undefined): string | undefined {
13-
if (!original) {
14-
return original;
15-
}
16-
17-
while (original.indexOf('\r\n') != -1) {
18-
original = original.replace('\r\n', '\n');
19-
}
20-
21-
return original;
22-
}
23-
2412
describe(`Razor Formatting ${testAssetWorkspace.description}`, function () {
2513
beforeAll(async function () {
2614
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
@@ -59,34 +47,35 @@ describe(`Razor Formatting ${testAssetWorkspace.description}`, function () {
5947
}
6048
);
6149

62-
expect(edits).toBeDefined();
63-
64-
console.log(`Got ${edits.length} edits`);
65-
66-
// It's much easier to verify the expected state of the document, than a bunch of edits
67-
const formatEdit = new vscode.WorkspaceEdit();
68-
formatEdit.set(activeDocument, edits);
69-
70-
console.log(`Applying edit ${formatEdit}`);
71-
72-
await vscode.workspace.applyEdit(formatEdit);
73-
74-
const contents = normalizeNewlines(vscode.window.activeTextEditor?.document.getText());
75-
76-
console.log(`Checking document contents...`);
77-
78-
expect(contents).toBe(
79-
normalizeNewlines(`@page "/bad"
80-
81-
@code {
82-
private string _x = "";
83-
84-
private void M()
85-
{
86-
// hi there
87-
}
88-
}
89-
`)
90-
);
50+
expect(edits).toHaveLength(13);
51+
52+
assertEditEqual(edits[0], 3, 0, 3, 0, ' ');
53+
assertEditEqual(edits[1], 3, 7, 3, 17, '');
54+
assertEditEqual(edits[2], 3, 18, 3, 31, '');
55+
assertEditEqual(edits[3], 3, 37, 3, 38, '');
56+
assertEditEqual(edits[4], 3, 39, 3, 57, '');
57+
assertEditEqual(edits[5], 3, 59, 3, 69, '');
58+
assertEditEqual(edits[6], 3, 70, 3, 86, '');
59+
assertEditEqual(edits[7], 3, 87, 3, 99, '');
60+
assertEditEqual(edits[8], 3, 100, 3, 108, '');
61+
assertEditEqual(edits[9], 5, 0, 5, 0, ' ');
62+
assertEditEqual(edits[10], 6, 0, 6, 0, ' ');
63+
assertEditEqual(edits[11], 7, 0, 7, 0, ' ');
64+
assertEditEqual(edits[12], 8, 0, 8, 0, ' ');
65+
66+
function assertEditEqual(
67+
actual: vscode.TextEdit,
68+
startLine: number,
69+
startChar: number,
70+
endLine: number,
71+
endChar: number,
72+
text: string
73+
) {
74+
expect(actual.newText).toBe(text);
75+
expect(actual.range.start.line).toBe(startLine);
76+
expect(actual.range.start.character).toBe(startChar);
77+
expect(actual.range.end.line).toBe(endLine);
78+
expect(actual.range.end.character).toBe(endChar);
79+
}
9180
});
9281
});

0 commit comments

Comments
 (0)