Skip to content

Commit 390aced

Browse files
authored
Halve the time it takes to run formatting unit tests (#11173)
Turns out the boolean parameter passed in here is read in exactly one spot in our code, and that line of code is never hit in these tests because they use mocks. Yes, this is the equivalent of removing a `Thread.Sleep` that was put in previously, but I'm taking it regardless :)
2 parents e87f30d + 6745d9b commit 390aced

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingTestBase.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ private protected async Task RunFormattingTestAsync(
5959
bool skipFlipLineEndingTest = false)
6060
{
6161
// Run with and without forceRuntimeCodeGeneration
62-
await RunFormattingTestInternalAsync(input, expected, tabSize, insertSpaces, fileKind, tagHelpers, allowDiagnostics, razorLSPOptions, inGlobalNamespace, forceRuntimeCodeGeneration: true);
63-
await RunFormattingTestInternalAsync(input, expected, tabSize, insertSpaces, fileKind, tagHelpers, allowDiagnostics, razorLSPOptions, inGlobalNamespace, forceRuntimeCodeGeneration: false);
62+
await RunFormattingTestInternalAsync(input, expected, tabSize, insertSpaces, fileKind, tagHelpers, allowDiagnostics, razorLSPOptions, inGlobalNamespace);
6463

6564
// some tests are failing, skip for now, tracked by https://github.com/dotnet/razor/issues/10836
6665
if (!skipFlipLineEndingTest)
@@ -69,12 +68,11 @@ private protected async Task RunFormattingTestAsync(
6968
input = FlipLineEndings(input);
7069
expected = FlipLineEndings(expected);
7170

72-
await RunFormattingTestInternalAsync(input, expected, tabSize, insertSpaces, fileKind, tagHelpers, allowDiagnostics, razorLSPOptions, inGlobalNamespace, forceRuntimeCodeGeneration: true);
73-
await RunFormattingTestInternalAsync(input, expected, tabSize, insertSpaces, fileKind, tagHelpers, allowDiagnostics, razorLSPOptions, inGlobalNamespace, forceRuntimeCodeGeneration: false);
71+
await RunFormattingTestInternalAsync(input, expected, tabSize, insertSpaces, fileKind, tagHelpers, allowDiagnostics, razorLSPOptions, inGlobalNamespace);
7472
}
7573
}
7674

77-
private async Task RunFormattingTestInternalAsync(string input, string expected, int tabSize, bool insertSpaces, string? fileKind, ImmutableArray<TagHelperDescriptor> tagHelpers, bool allowDiagnostics, RazorLSPOptions? razorLSPOptions, bool inGlobalNamespace, bool forceRuntimeCodeGeneration)
75+
private async Task RunFormattingTestInternalAsync(string input, string expected, int tabSize, bool insertSpaces, string? fileKind, ImmutableArray<TagHelperDescriptor> tagHelpers, bool allowDiagnostics, RazorLSPOptions? razorLSPOptions, bool inGlobalNamespace)
7876
{
7977
// Arrange
8078
fileKind ??= FileKinds.Component;
@@ -89,7 +87,7 @@ private async Task RunFormattingTestInternalAsync(string input, string expected,
8987

9088
var path = "file:///path/to/Document." + fileKind;
9189
var uri = new Uri(path);
92-
var (codeDocument, documentSnapshot) = CreateCodeDocumentAndSnapshot(source, uri.AbsolutePath, tagHelpers, fileKind, allowDiagnostics, inGlobalNamespace, forceRuntimeCodeGeneration);
90+
var (codeDocument, documentSnapshot) = CreateCodeDocumentAndSnapshot(source, uri.AbsolutePath, tagHelpers, fileKind, allowDiagnostics, inGlobalNamespace);
9391
var options = new FormattingOptions()
9492
{
9593
TabSize = tabSize,
@@ -248,7 +246,7 @@ protected async Task RunCodeActionFormattingTestAsync(
248246
protected static TextEdit Edit(int startLine, int startChar, int endLine, int endChar, string newText)
249247
=> VsLspFactory.CreateTextEdit(startLine, startChar, endLine, endChar, newText);
250248

251-
private static (RazorCodeDocument, IDocumentSnapshot) CreateCodeDocumentAndSnapshot(SourceText text, string path, ImmutableArray<TagHelperDescriptor> tagHelpers = default, string? fileKind = default, bool allowDiagnostics = false, bool inGlobalNamespace = false, bool forceRuntimeCodeGeneration = false)
249+
private static (RazorCodeDocument, IDocumentSnapshot) CreateCodeDocumentAndSnapshot(SourceText text, string path, ImmutableArray<TagHelperDescriptor> tagHelpers = default, string? fileKind = default, bool allowDiagnostics = false, bool inGlobalNamespace = false)
252250
{
253251
fileKind ??= FileKinds.Component;
254252
tagHelpers = tagHelpers.NullToEmpty();
@@ -291,7 +289,7 @@ @using Microsoft.AspNetCore.Components.Web
291289
new TestRazorProjectItem(importsPath, fileKind: FileKinds.ComponentImport)]);
292290

293291
var projectEngine = RazorProjectEngine.Create(
294-
new RazorConfiguration(RazorLanguageVersion.Latest, "TestConfiguration", Extensions: [], LanguageServerFlags: new LanguageServerFlags(forceRuntimeCodeGeneration)),
292+
new RazorConfiguration(RazorLanguageVersion.Latest, "TestConfiguration", Extensions: []),
295293
projectFileSystem,
296294
builder =>
297295
{

0 commit comments

Comments
 (0)