상속: IWebpackService
        public async Task HotReload_EmitsOnValid()
        {
            var mock = new WebpackServiceMock();

            mock.AddFile("/public/bundle.js", "bundle.js", "js");

            using (var server = CreateServer(mock))
            {
                using (var client = server.CreateClient())
                {
                    client.DefaultRequestHeaders.Add("Accept", "text/event-stream");
                    var stream = await client.GetStreamAsync("/__webpack_hmr");

                    var buffer     = new byte[256];
                    var byteCount1 = await stream.ReadAsync(buffer, 0, 256);

                    Assert.Equal(14, byteCount1);

                    var e = new JArray();
                    e.Add(new JObject());
                    mock.OnValid(e);

                    // TODO
                    var byteCount2 = await stream.ReadAsync(buffer, 0, 256);

                    Assert.Equal(28, byteCount2);
                    Assert.Equal("data: {\"action\":\"built\"}\r\n\r\n", System.Text.Encoding.UTF8.GetString(buffer).Substring(0, byteCount2));
                }
            }
        }
        public async Task HotReload_DisconnectsOnShutdown()
        {
            var mockService = new WebpackServiceMock();

            mockService.AddFile("/public/bundle.js", "bundle.js", "js");

            using (var server = CreateServer(mockService))
            {
                using (var client = server.CreateClient())
                {
                    client.DefaultRequestHeaders.Add("Accept", "text/event-stream");
                    var stream = await client.GetStreamAsync("/__webpack_hmr");

                    var buffer     = new byte[256];
                    var byteCount1 = await stream.ReadAsync(buffer, 0, 256);

                    Assert.Equal(14, byteCount1);

                    await server.Host.StopAsync();

                    // For some reason this doesn't throw, but it does return 0 bytes
                    var byteCount2 = await stream.ReadAsync(buffer, 0, 256);

                    Assert.Equal(0, byteCount2);
                }
            }
        }
예제 #3
0
        public async Task DevServer_EmitsHeartbeats()
        {
            // Arrange
            var mock = new WebpackServiceMock();

            using (var server = CreateServer(mock))
            {
                using (var client = server.CreateClient())
                {
                    // Act
                    var stream = await client.GetStreamAsync("/__webpack_hmr");

                    var buffer     = new byte[256];
                    var byteCount1 = await stream.ReadAsync(buffer, 0, 256);

                    Assert.Equal(14, byteCount1);

                    var cancellationTokenSource = new CancellationTokenSource(10000);
                    var byteCount2 = await stream.ReadAsync(buffer, 0, 256, cancellationTokenSource.Token);

                    Assert.Equal(14, byteCount2);
                    Assert.Equal("data: \uD83D\uDC93\r\n\r\n", System.Text.Encoding.UTF8.GetString(buffer).Substring(0, byteCount2 - 2));
                }
            }
        }
예제 #4
0
        public async Task DevServer_EmitsOnValid()
        {
            // Arrange
            var mock = new WebpackServiceMock();

            mock.AddFile("/public/bundle.js", "bundle.js", "js");

            using (var server = CreateServer(mock))
            {
                using (var client = server.CreateClient())
                {
                    // Act
                    var stream = await client.GetStreamAsync("/__webpack_hmr");

                    var buffer     = new byte[256];
                    var byteCount1 = await stream.ReadAsync(buffer, 0, 256);

                    Assert.Equal(14, byteCount1);

                    var e = new JObject();
                    mock.OnValid(e);

                    // TODO
                    var byteCount2 = await stream.ReadAsync(buffer, 0, 256);

                    Assert.Equal(28, byteCount2);
                    Assert.Equal("data: {\"action\":\"built\"}\r\n\r\n", System.Text.Encoding.UTF8.GetString(buffer).Substring(0, byteCount2));
                }
            }
        }
        public async Task DevServer_Returns404WhenWebpackFileNotFound()
        {
            // Arrange
            var mock = new WebpackServiceMock();
            mock.AddNonExistantFile("/public/bundle.js");

            using (var server = CreateServer(mock))
            {
                // Act
                // Actual request.
                var response = await server.CreateRequest("/public/bundle.js").SendAsync("GET");

                // Assert
                Assert.Equal(System.Net.HttpStatusCode.NotFound, response.StatusCode);
            }
        }
        public async Task DevServer_IgnoresNonWebpackFiles()
        {
            // Arrange
            var mock = new WebpackServiceMock();
            mock.AddFile("/public/bundle.js", "bundle.js", "js");

            using (var server = CreateServer(mock))
            {
                // Act
                // Actual request.
                var response = await server.CreateRequest("/public/notbundle.js").SendAsync("GET");

                // Assert
                response.EnsureSuccessStatusCode();
                Assert.Equal(DEFAULT_RESPONSE, await response.Content.ReadAsStringAsync());
            }
        }
예제 #7
0
        public async Task DevServer_Returns404WhenWebpackFileNotFound()
        {
            // Arrange
            var mock = new WebpackServiceMock();

            mock.AddNonExistantFile("/public/bundle.js");

            using (var server = CreateServer(mock))
            {
                // Act
                // Actual request.
                var response = await server.CreateRequest("/public/bundle.js").SendAsync("GET");

                // Assert
                Assert.Equal(System.Net.HttpStatusCode.NotFound, response.StatusCode);
            }
        }
예제 #8
0
        public async Task DevServer_IgnoresNonWebpackFiles()
        {
            // Arrange
            var mock = new WebpackServiceMock();

            mock.AddFile("/public/bundle.js", "bundle.js", "js");

            using (var server = CreateServer(mock))
            {
                // Act
                // Actual request.
                var response = await server.CreateRequest("/public/notbundle.js").SendAsync("GET");

                // Assert
                response.EnsureSuccessStatusCode();
                Assert.Equal(DEFAULT_RESPONSE, await response.Content.ReadAsStringAsync());
            }
        }
        public async Task DevServer_SetsResponseHeaders()
        {
            // Arrange
            var mock = new WebpackServiceMock();
            mock.AddFile("/public/bundle.js", "bundle.js", "js");

            using (var server = CreateServer(mock))
            {
                // Act
                // Actual request.
                var response = await server.CreateRequest("/public/bundle.js").SendAsync("GET");

                // Assert
                response.EnsureSuccessStatusCode();
                Assert.Equal("bundle.js", await response.Content.ReadAsStringAsync());

                Assert.Equal(2, response.Content.Headers.Count());
                Assert.Equal("js", response.Content.Headers.GetValues("Content-Type").FirstOrDefault());
                Assert.Equal("9", response.Content.Headers.GetValues("Content-Length").FirstOrDefault());
            }
        }
예제 #10
0
        public async Task DevServer_SetsContentLengthInBytes()
        {
            // Arrange
            var mock = new WebpackServiceMock();

            mock.AddFile("/public/bundle.js", "[’]", "js"); // unicode

            using (var server = CreateServer(mock))
            {
                // Act
                // Actual request.
                var response = await server.CreateRequest("/public/bundle.js").SendAsync("GET");

                // Assert
                response.EnsureSuccessStatusCode();
                Assert.Equal("[’]", await response.Content.ReadAsStringAsync());

                Assert.Equal(2, response.Content.Headers.Count());
                Assert.Equal("5", response.Content.Headers.GetValues("Content-Length").FirstOrDefault());
            }
        }
        public async Task HotReload_EmitsHeartbeats()
        {
            var mock = new WebpackServiceMock();

            using (var server = CreateServer(mock))
            {
                using (var client = server.CreateClient())
                {
                    client.DefaultRequestHeaders.Add("Accept", "text/event-stream");
                    var stream = await client.GetStreamAsync("/__webpack_hmr");

                    var buffer     = new byte[256];
                    var byteCount1 = await stream.ReadAsync(buffer, 0, 256);

                    Assert.Equal(14, byteCount1);

                    var cancellationTokenSource = new CancellationTokenSource(10000);
                    var byteCount2 = await stream.ReadAsync(buffer, 0, 256, cancellationTokenSource.Token);

                    Assert.Equal(14, byteCount2);
                    Assert.Equal("data: \uD83D\uDC93\r\n\r\n", System.Text.Encoding.UTF8.GetString(buffer).Substring(0, byteCount2 - 2));
                }
            }
        }
        public async Task DevServer_EmitsHeartbeats()
        {
            // Arrange
            var mock = new WebpackServiceMock();

            using (var server = CreateServer(mock))
            {
                using (var client = server.CreateClient())
                {
                    // Act
                    var stream = await client.GetStreamAsync("/__webpack_hmr");

                    var buffer = new byte[256];
                    var byteCount1 = await stream.ReadAsync(buffer, 0, 256);
                    Assert.Equal(14, byteCount1);

                    var cancellationTokenSource = new CancellationTokenSource(10000);
                    var byteCount2 = await stream.ReadAsync(buffer, 0, 256, cancellationTokenSource.Token);

                    Assert.Equal(14, byteCount2);
                    Assert.Equal("data: \uD83D\uDC93\r\n\r\n", System.Text.Encoding.UTF8.GetString(buffer).Substring(0, byteCount2 - 2));
                }
            }
        }
        public async Task DevServer_EmitsOnValid()
        {
            // Arrange
            var mock = new WebpackServiceMock();
            mock.AddFile("/public/bundle.js", "bundle.js", "js");

            using (var server = CreateServer(mock))
            {
                using (var client = server.CreateClient())
                {
                    // Act
                    var stream = await client.GetStreamAsync("/__webpack_hmr");

                    var buffer = new byte[256];
                    var byteCount1 = await stream.ReadAsync(buffer, 0, 256);
                    Assert.Equal(14, byteCount1);

                    var e = new JObject();
                    mock.OnValid(e);

                    // TODO
                    var byteCount2 = await stream.ReadAsync(buffer, 0, 256);
                    Assert.Equal(28, byteCount2);
                    Assert.Equal("data: {\"action\":\"built\"}\r\n\r\n", System.Text.Encoding.UTF8.GetString(buffer).Substring(0, byteCount2));
                }
            }
        }