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);
        }
Пример #2
0
 public HotReload(ProcessRunner processRunner, IReporter reporter)
 {
     _staticFileHandler    = new StaticFileHandler(reporter);
     _scopedCssFileHandler = new ScopedCssFileHandler(processRunner, reporter);
     _compilationHandler   = new CompilationHandler(reporter);
 }
Пример #3
0
 public HotReload(IReporter reporter)
 {
     _staticFileHandler  = new StaticFileHandler(reporter);
     _compilationHandler = new CompilationHandler(reporter);
 }