AddFile() public method

public AddFile ( string filename, string contents, string mimeType ) : IWebpackFile
filename string
contents string
mimeType string
return IWebpackFile
        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);
                }
            }
        }
Beispiel #3
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_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());
            }
        }
Beispiel #5
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());
            }
        }
Beispiel #7
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 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));
                }
            }
        }