public async ValueTask TryHandleFileAction_CausesBrowserRefreshForNonCssFile() { // Arrange var server = new Mock <BrowserRefreshServer>(NullReporter.Singleton); byte[] writtenBytes = null; server.Setup(s => s.SendMessage(It.IsAny <byte[]>(), It.IsAny <CancellationToken>())) .Callback((byte[] bytes, CancellationToken cts) => { writtenBytes = bytes; }); var fileContentHandler = new StaticFileHandler(NullReporter.Singleton); var context = new DotNetWatchContext { BrowserRefreshServer = server.Object, }; var file = new FileItem { FilePath = "Test.js", IsStaticFile = true, StaticWebAssetPath = "Test.js" }; // Act var result = await fileContentHandler.TryHandleFileChange(context, file, default); // Assert Assert.True(result); Assert.NotNull(writtenBytes); var deserialized = JsonSerializer.Deserialize <UpdateStaticFileMessage>(writtenBytes, new JsonSerializerOptions(JsonSerializerDefaults.Web)); Assert.Equal("UpdateStaticFile", deserialized.Type); Assert.Equal("content/Test.js", deserialized.Path); }
public async ValueTask <bool> TryHandleFileChange(DotNetWatchContext context, FileItem file, CancellationToken cancellationToken) { return (await _staticFileHandler.TryHandleFileChange(context, file, cancellationToken) || await _scopedCssFileHandler.TryHandleFileChange(context, file, cancellationToken) || await _compilationHandler.TryHandleFileChange(context, file, cancellationToken)); }
public async ValueTask <bool> TryHandleFileChange(DotNetWatchContext context, FileItem file, CancellationToken cancellationToken) { HotReloadEventSource.Log.HotReloadStart(HotReloadEventSource.StartType.Main); var fileHandlerResult = await _staticFileHandler.TryHandleFileChange(context, file, cancellationToken) || await _scopedCssFileHandler.TryHandleFileChange(context, file, cancellationToken) || await _compilationHandler.TryHandleFileChange(context, file, cancellationToken); HotReloadEventSource.Log.HotReloadEnd(HotReloadEventSource.StartType.Main); return(fileHandlerResult); }
public async ValueTask <bool> TryHandleFileChange(DotNetWatchContext context, FileItem file, CancellationToken cancellationToken) { if (await _staticFileHandler.TryHandleFileChange(context, file, cancellationToken)) { return(true); } if (await _compilationHandler.TryHandleFileChange(context, file, cancellationToken)) // This needs to be 6.0 { return(true); } return(false); }
public async ValueTask <bool> TryHandleFileChange(DotNetWatchContext context, FileItem[] files, CancellationToken cancellationToken) { HotReloadEventSource.Log.HotReloadStart(HotReloadEventSource.StartType.Main); var fileHandlerResult = false; for (var i = files.Length - 1; i >= 0; i--) { var file = files[i]; if (await _staticFileHandler.TryHandleFileChange(context, file, cancellationToken) || await _scopedCssFileHandler.TryHandleFileChange(context, file, cancellationToken)) { fileHandlerResult = true; } } fileHandlerResult |= await _compilationHandler.TryHandleFileChange(context, files, cancellationToken); HotReloadEventSource.Log.HotReloadEnd(HotReloadEventSource.StartType.Main); return(fileHandlerResult); }