diff --git a/test/e2e/__snapshots__/static-public-path.test.js.snap.webpack4 b/test/e2e/__snapshots__/static-public-path.test.js.snap.webpack4 new file mode 100644 index 0000000000..474a73fb14 --- /dev/null +++ b/test/e2e/__snapshots__/static-public-path.test.js.snap.webpack4 @@ -0,0 +1,262 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`static.publicPath option Content type should handle request to example.txt: console messages 1`] = `Array []`; + +exports[`static.publicPath option Content type should handle request to example.txt: page errors 1`] = `Array []`; + +exports[`static.publicPath option Content type should handle request to example.txt: response header content-type 1`] = `"text/plain; charset=UTF-8"`; + +exports[`static.publicPath option Content type should handle request to example.txt: response status 1`] = `200`; + +exports[`static.publicPath option defaults to CWD should handle request to page: console messages 1`] = `Array []`; + +exports[`static.publicPath option defaults to CWD should handle request to page: page errors 1`] = `Array []`; + +exports[`static.publicPath option defaults to CWD should handle request to page: response status 1`] = `200`; + +exports[`static.publicPath option defaults to CWD should handle request to page: response text 1`] = ` +"Heyo. +" +`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the /foo route of second path: console messages 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the /foo route of second path: page errors 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the /foo route of second path: response status 1`] = `200`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the /foo route of second path: response text 1`] = ` +"Foo! +" +`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the index of first path: console messages 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the index of first path: page errors 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the index of first path: response status 1`] = `200`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the index of first path: response text 1`] = ` +"Heyo. +" +`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the other file of first path: console messages 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the other file of first path: page errors 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the other file of first path: response status 1`] = `200`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the other file of first path: response text 1`] = ` +"Other html +" +`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of first path: console messages 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of first path: page errors 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of first path: response status 1`] = `200`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of first path: response text 1`] = ` +"Foo! +" +`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of second path: console messages 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of second path: page errors 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of second path: response status 1`] = `200`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of second path: response text 1`] = ` +"Foo! +" +`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the index of first path: console messages 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the index of first path: page errors 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the index of first path: response status 1`] = `200`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the index of first path: response text 1`] = ` +"Heyo. +" +`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the other file of first path: console messages 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the other file of first path: page errors 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the other file of first path: response status 1`] = `200`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the other file of first path: response text 1`] = ` +"Other html +" +`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should handle GET request: console messages 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should handle GET request: page errors 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should handle GET request: response status 1`] = `200`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should handle HEAD request: console messages 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should handle HEAD request: page errors 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should handle HEAD request: response status 1`] = `200`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle DELETE request: console messages 1`] = ` +Array [ + "Failed to load resource: the server responded with a status of 404 (Not Found)", +] +`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle DELETE request: page errors 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle DELETE request: response status 1`] = `404`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle PATCH request: console messages 1`] = ` +Array [ + "Failed to load resource: the server responded with a status of 404 (Not Found)", +] +`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle PATCH request: page errors 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle PATCH request: response status 1`] = `404`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle POST request: console messages 1`] = ` +Array [ + "Failed to load resource: the server responded with a status of 404 (Not Found)", +] +`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle POST request: page errors 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle POST request: response status 1`] = `404`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle PUT request: console messages 1`] = ` +Array [ + "Failed to load resource: the server responded with a status of 404 (Not Found)", +] +`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle PUT request: page errors 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle PUT request: response status 1`] = `404`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex default (true) should list the files inside the assets folder (200): console messages 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex default (true) should list the files inside the assets folder (200): page errors 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex default (true) should list the files inside the assets folder (200): response status 1`] = `200`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex default (true) should show Heyo. because bar has index.html inside it (200): console messages 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex default (true) should show Heyo. because bar has index.html inside it (200): page errors 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex default (true) should show Heyo. because bar has index.html inside it (200): response status 1`] = `200`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex default (true) should show Heyo. because bar has index.html inside it (200): response text 1`] = ` +"Heyo +" +`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false should show Heyo. because bar has index.html inside it (200): console messages 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false should show Heyo. because bar has index.html inside it (200): page errors 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false should show Heyo. because bar has index.html inside it (200): response status 1`] = `200`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false should show Heyo. because bar has index.html inside it (200): response text 1`] = ` +"Heyo +" +`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false shouldn't list the files inside the assets folder (404): console messages 1`] = ` +Array [ + "Failed to load resource: the server responded with a status of 404 (Not Found)", +] +`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false shouldn't list the files inside the assets folder (404): page errors 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false shouldn't list the files inside the assets folder (404): response status 1`] = `404`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false shouldn't list the files inside the assets folder (404): response text 1`] = ` +" + + + +Error + + +
Cannot GET /serve-content-at-this-url/assets/
+ + +" +`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: true should list the files inside the assets folder (200): console messages 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: true should list the files inside the assets folder (200): page errors 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: true should list the files inside the assets folder (200): response status 1`] = `200`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: true should show Heyo. because bar has index.html inside it (200): console messages 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: true should show Heyo. because bar has index.html inside it (200): page errors 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: true should show Heyo. because bar has index.html inside it (200): response status 1`] = `200`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: true should show Heyo. because bar has index.html inside it (200): response text 1`] = ` +"Heyo +" +`; + +exports[`static.publicPath option to directory should handle request to index: console messages 1`] = `Array []`; + +exports[`static.publicPath option to directory should handle request to index: page errors 1`] = `Array []`; + +exports[`static.publicPath option to directory should handle request to index: response status 1`] = `200`; + +exports[`static.publicPath option to directory should handle request to index: response text 1`] = ` +"Heyo. +" +`; + +exports[`static.publicPath option to directory should handle request to other file: console messages 1`] = `Array []`; + +exports[`static.publicPath option to directory should handle request to other file: page errors 1`] = `Array []`; + +exports[`static.publicPath option to directory should handle request to other file: response status 1`] = `200`; + +exports[`static.publicPath option to directory should handle request to other file: response text 1`] = ` +"Other html +" +`; + +exports[`static.publicPath option to multiple directories should handle request to first directory: console messages 1`] = `Array []`; + +exports[`static.publicPath option to multiple directories should handle request to first directory: page errors 1`] = `Array []`; + +exports[`static.publicPath option to multiple directories should handle request to first directory: response status 1`] = `200`; + +exports[`static.publicPath option to multiple directories should handle request to first directory: response text 1`] = ` +"Heyo. +" +`; + +exports[`static.publicPath option to multiple directories should handle request to second directory: console messages 1`] = `Array []`; + +exports[`static.publicPath option to multiple directories should handle request to second directory: page errors 1`] = `Array []`; + +exports[`static.publicPath option to multiple directories should handle request to second directory: response status 1`] = `200`; + +exports[`static.publicPath option to multiple directories should handle request to second directory: response text 1`] = ` +"Foo! +" +`; diff --git a/test/e2e/__snapshots__/static-public-path.test.js.snap.webpack5 b/test/e2e/__snapshots__/static-public-path.test.js.snap.webpack5 new file mode 100644 index 0000000000..474a73fb14 --- /dev/null +++ b/test/e2e/__snapshots__/static-public-path.test.js.snap.webpack5 @@ -0,0 +1,262 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`static.publicPath option Content type should handle request to example.txt: console messages 1`] = `Array []`; + +exports[`static.publicPath option Content type should handle request to example.txt: page errors 1`] = `Array []`; + +exports[`static.publicPath option Content type should handle request to example.txt: response header content-type 1`] = `"text/plain; charset=UTF-8"`; + +exports[`static.publicPath option Content type should handle request to example.txt: response status 1`] = `200`; + +exports[`static.publicPath option defaults to CWD should handle request to page: console messages 1`] = `Array []`; + +exports[`static.publicPath option defaults to CWD should handle request to page: page errors 1`] = `Array []`; + +exports[`static.publicPath option defaults to CWD should handle request to page: response status 1`] = `200`; + +exports[`static.publicPath option defaults to CWD should handle request to page: response text 1`] = ` +"Heyo. +" +`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the /foo route of second path: console messages 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the /foo route of second path: page errors 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the /foo route of second path: response status 1`] = `200`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the /foo route of second path: response text 1`] = ` +"Foo! +" +`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the index of first path: console messages 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the index of first path: page errors 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the index of first path: response status 1`] = `200`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the index of first path: response text 1`] = ` +"Heyo. +" +`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the other file of first path: console messages 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the other file of first path: page errors 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the other file of first path: response status 1`] = `200`; + +exports[`static.publicPath option multiple static.publicPath entries should handle request to the other file of first path: response text 1`] = ` +"Other html +" +`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of first path: console messages 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of first path: page errors 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of first path: response status 1`] = `200`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of first path: response text 1`] = ` +"Foo! +" +`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of second path: console messages 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of second path: page errors 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of second path: response status 1`] = `200`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the /foo route of second path: response text 1`] = ` +"Foo! +" +`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the index of first path: console messages 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the index of first path: page errors 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the index of first path: response status 1`] = `200`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the index of first path: response text 1`] = ` +"Heyo. +" +`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the other file of first path: console messages 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the other file of first path: page errors 1`] = `Array []`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the other file of first path: response status 1`] = `200`; + +exports[`static.publicPath option multiple static.publicPath entries with publicPath array should handle request to the other file of first path: response text 1`] = ` +"Other html +" +`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should handle GET request: console messages 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should handle GET request: page errors 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should handle GET request: response status 1`] = `200`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should handle HEAD request: console messages 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should handle HEAD request: page errors 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should handle HEAD request: response status 1`] = `200`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle DELETE request: console messages 1`] = ` +Array [ + "Failed to load resource: the server responded with a status of 404 (Not Found)", +] +`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle DELETE request: page errors 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle DELETE request: response status 1`] = `404`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle PATCH request: console messages 1`] = ` +Array [ + "Failed to load resource: the server responded with a status of 404 (Not Found)", +] +`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle PATCH request: page errors 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle PATCH request: response status 1`] = `404`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle POST request: console messages 1`] = ` +Array [ + "Failed to load resource: the server responded with a status of 404 (Not Found)", +] +`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle POST request: page errors 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle POST request: response status 1`] = `404`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle PUT request: console messages 1`] = ` +Array [ + "Failed to load resource: the server responded with a status of 404 (Not Found)", +] +`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle PUT request: page errors 1`] = `Array []`; + +exports[`static.publicPath option should ignore methods other than GET and HEAD should not handle PUT request: response status 1`] = `404`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex default (true) should list the files inside the assets folder (200): console messages 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex default (true) should list the files inside the assets folder (200): page errors 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex default (true) should list the files inside the assets folder (200): response status 1`] = `200`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex default (true) should show Heyo. because bar has index.html inside it (200): console messages 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex default (true) should show Heyo. because bar has index.html inside it (200): page errors 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex default (true) should show Heyo. because bar has index.html inside it (200): response status 1`] = `200`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex default (true) should show Heyo. because bar has index.html inside it (200): response text 1`] = ` +"Heyo +" +`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false should show Heyo. because bar has index.html inside it (200): console messages 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false should show Heyo. because bar has index.html inside it (200): page errors 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false should show Heyo. because bar has index.html inside it (200): response status 1`] = `200`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false should show Heyo. because bar has index.html inside it (200): response text 1`] = ` +"Heyo +" +`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false shouldn't list the files inside the assets folder (404): console messages 1`] = ` +Array [ + "Failed to load resource: the server responded with a status of 404 (Not Found)", +] +`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false shouldn't list the files inside the assets folder (404): page errors 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false shouldn't list the files inside the assets folder (404): response status 1`] = `404`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: false shouldn't list the files inside the assets folder (404): response text 1`] = ` +" + + + +Error + + +
Cannot GET /serve-content-at-this-url/assets/
+ + +" +`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: true should list the files inside the assets folder (200): console messages 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: true should list the files inside the assets folder (200): page errors 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: true should list the files inside the assets folder (200): response status 1`] = `200`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: true should show Heyo. because bar has index.html inside it (200): console messages 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: true should show Heyo. because bar has index.html inside it (200): page errors 1`] = `Array []`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: true should show Heyo. because bar has index.html inside it (200): response status 1`] = `200`; + +exports[`static.publicPath option test listing files in folders without index.html using the option static.serveIndex: true should show Heyo. because bar has index.html inside it (200): response text 1`] = ` +"Heyo +" +`; + +exports[`static.publicPath option to directory should handle request to index: console messages 1`] = `Array []`; + +exports[`static.publicPath option to directory should handle request to index: page errors 1`] = `Array []`; + +exports[`static.publicPath option to directory should handle request to index: response status 1`] = `200`; + +exports[`static.publicPath option to directory should handle request to index: response text 1`] = ` +"Heyo. +" +`; + +exports[`static.publicPath option to directory should handle request to other file: console messages 1`] = `Array []`; + +exports[`static.publicPath option to directory should handle request to other file: page errors 1`] = `Array []`; + +exports[`static.publicPath option to directory should handle request to other file: response status 1`] = `200`; + +exports[`static.publicPath option to directory should handle request to other file: response text 1`] = ` +"Other html +" +`; + +exports[`static.publicPath option to multiple directories should handle request to first directory: console messages 1`] = `Array []`; + +exports[`static.publicPath option to multiple directories should handle request to first directory: page errors 1`] = `Array []`; + +exports[`static.publicPath option to multiple directories should handle request to first directory: response status 1`] = `200`; + +exports[`static.publicPath option to multiple directories should handle request to first directory: response text 1`] = ` +"Heyo. +" +`; + +exports[`static.publicPath option to multiple directories should handle request to second directory: console messages 1`] = `Array []`; + +exports[`static.publicPath option to multiple directories should handle request to second directory: page errors 1`] = `Array []`; + +exports[`static.publicPath option to multiple directories should handle request to second directory: response status 1`] = `200`; + +exports[`static.publicPath option to multiple directories should handle request to second directory: response text 1`] = ` +"Foo! +" +`; diff --git a/test/e2e/static-public-path.test.js b/test/e2e/static-public-path.test.js new file mode 100644 index 0000000000..94b832f3e4 --- /dev/null +++ b/test/e2e/static-public-path.test.js @@ -0,0 +1,1095 @@ +"use strict"; + +const path = require("path"); +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/static-config/webpack.config"); +const port = require("../ports-map")["static-public-path-option"]; +const runBrowser = require("../helpers/run-browser"); + +const staticDirectory = path.resolve(__dirname, "../fixtures/static-config"); +const publicDirectory = path.resolve(staticDirectory, "public"); +const otherPublicDirectory = path.resolve(staticDirectory, "other"); +const staticPublicPath = "/serve-content-at-this-url"; +const otherStaticPublicPath = "/serve-other-content-at-this-url"; + +describe("static.publicPath option", () => { + describe("to directory", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + compiler = webpack(config); + + server = new Server( + { + static: { + directory: publicDirectory, + publicPath: staticPublicPath, + watch: true, + }, + port, + }, + compiler + ); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + await server.stop(); + }); + + it("should handle request to index", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should handle request to other file", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/other.html`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); + + describe("test listing files in folders without index.html using the option static.serveIndex: false", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + compiler = webpack(config); + + server = new Server( + { + static: { + directory: publicDirectory, + publicPath: staticPublicPath, + watch: true, + serveIndex: false, + }, + port, + }, + compiler + ); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + await server.stop(); + }); + + it("shouldn't list the files inside the assets folder (404)", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/assets`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should show Heyo. because bar has index.html inside it (200)", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/bar`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); + + describe("test listing files in folders without index.html using the option static.serveIndex: true", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + compiler = webpack(config); + + server = new Server( + { + static: { + directory: publicDirectory, + publicPath: staticPublicPath, + watch: true, + serveIndex: true, + }, + port, + }, + compiler + ); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + await server.stop(); + }); + + it("should list the files inside the assets folder (200)", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/assets`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toContain("other.txt"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should show Heyo. because bar has index.html inside it (200)", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/bar`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); + + describe("test listing files in folders without index.html using the option static.serveIndex default (true)", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + compiler = webpack(config); + + server = new Server( + { + static: { + directory: publicDirectory, + publicPath: staticPublicPath, + watch: true, + serveIndex: true, + }, + port, + }, + compiler + ); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + await server.stop(); + }); + + it("should list the files inside the assets folder (200)", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/assets`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toContain("other.txt"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should show Heyo. because bar has index.html inside it (200)", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/bar`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); + + describe("to multiple directories", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + compiler = webpack(config); + + server = new Server( + { + static: [ + { + directory: publicDirectory, + publicPath: staticPublicPath, + }, + { + directory: otherPublicDirectory, + publicPath: staticPublicPath, + }, + ], + port, + }, + compiler + ); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + await server.stop(); + }); + + it("should handle request to first directory", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should handle request to second directory", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/foo.html`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); + + describe("defaults to CWD", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + jest.spyOn(process, "cwd").mockImplementation(() => staticDirectory); + compiler = webpack(config); + + server = new Server( + { + static: { + publicPath: staticPublicPath, + }, + port, + }, + compiler + ); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + await server.stop(); + }); + + it("should handle request to page", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/index.html`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); + + describe("Content type", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + compiler = webpack(config); + + server = new Server( + { + static: { + directory: publicDirectory, + publicPath: staticPublicPath, + }, + port, + }, + compiler + ); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + await server.stop(); + }); + + it("should handle request to example.txt", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/assets/example.txt`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(response.headers()["content-type"]).toMatchSnapshot( + "response header content-type" + ); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); + + describe("should ignore methods other than GET and HEAD", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + compiler = webpack(config); + + server = new Server( + { + static: { + directory: publicDirectory, + publicPath: staticPublicPath, + }, + port, + }, + compiler + ); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + await server.stop(); + }); + + it("should handle GET request", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should handle HEAD request", async () => { + await page.setRequestInterception(true); + + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }) + .on("request", (interceptedRequest) => { + interceptedRequest.continue({ method: "HEAD" }); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should not handle POST request", async () => { + await page.setRequestInterception(true); + + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }) + .on("request", (interceptedRequest) => { + interceptedRequest.continue({ method: "POST" }); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should not handle PUT request", async () => { + await page.setRequestInterception(true); + + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }) + .on("request", (interceptedRequest) => { + interceptedRequest.continue({ method: "PUT" }); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should not handle DELETE request", async () => { + await page.setRequestInterception(true); + + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }) + .on("request", (interceptedRequest) => { + interceptedRequest.continue({ method: "DELETE" }); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should not handle PATCH request", async () => { + await page.setRequestInterception(true); + + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }) + .on("request", (interceptedRequest) => { + interceptedRequest.continue({ method: "PATCH" }); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); + + describe("multiple static.publicPath entries", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + compiler = webpack(config); + + server = new Server( + { + static: [ + { + directory: publicDirectory, + publicPath: staticPublicPath, + watch: true, + }, + { + directory: otherPublicDirectory, + publicPath: otherStaticPublicPath, + watch: true, + }, + ], + port, + }, + compiler + ); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + await server.stop(); + }); + + it("should handle request to the index of first path", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should handle request to the other file of first path", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/other.html`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should handle request to the /foo route of second path", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${otherStaticPublicPath}/foo.html`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); + + describe("multiple static.publicPath entries with publicPath array", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + compiler = webpack(config); + + server = new Server( + { + static: [ + { + directory: publicDirectory, + publicPath: staticPublicPath, + watch: true, + }, + { + directory: otherPublicDirectory, + publicPath: [staticPublicPath, otherStaticPublicPath], + watch: true, + }, + ], + port, + }, + compiler + ); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + await server.stop(); + }); + + it("should handle request to the index of first path", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should handle request to the other file of first path", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/other.html`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should handle request to the /foo route of first path", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${staticPublicPath}/foo.html`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should handle request to the /foo route of second path", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}${otherStaticPublicPath}/foo.html`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(await response.text()).toMatchSnapshot("response text"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); +}); diff --git a/test/server/static-publicPath-option.test.js b/test/server/static-publicPath-option.test.js deleted file mode 100644 index 1c0b7d13a0..0000000000 --- a/test/server/static-publicPath-option.test.js +++ /dev/null @@ -1,463 +0,0 @@ -"use strict"; - -const path = require("path"); -const request = require("supertest"); -const webpack = require("webpack"); -const Server = require("../../lib/Server"); -const config = require("../fixtures/static-config/webpack.config"); -const port = require("../ports-map")["static-public-path-option"]; - -const staticDirectory = path.resolve(__dirname, "../fixtures/static-config"); -const publicDirectory = path.resolve(staticDirectory, "public"); -const otherPublicDirectory = path.resolve(staticDirectory, "other"); -const staticPublicPath = "/serve-content-base-at-this-url"; -const otherStaticPublicPath = "/serve-other-content-at-this-url"; - -describe("static.publicPath option", () => { - let server; - let req; - - describe("to directory", () => { - beforeAll(async () => { - const compiler = webpack(config); - - server = new Server( - { - static: { - directory: publicDirectory, - publicPath: staticPublicPath, - watch: true, - }, - port, - }, - compiler - ); - - await server.start(); - - req = request(server.app); - }); - - afterAll(async () => { - await server.stop(); - }); - - it("Request to index", async () => { - const response = await req.get(`${staticPublicPath}/`); - - expect(response.statusCode).toEqual(200); - expect(response.text).toContain("Heyo"); - }); - - it("Request to other file", async () => { - const response = await req.get(`${staticPublicPath}/other.html`); - - expect(response.statusCode).toEqual(200); - expect(response.text).toContain("Other html"); - }); - }); - - describe("test listing files in folders without index.html using the option static.serveIndex:false", () => { - beforeAll(async () => { - const compiler = webpack(config); - - server = new Server( - { - static: { - directory: publicDirectory, - publicPath: staticPublicPath, - watch: true, - serveIndex: false, - }, - port, - }, - compiler - ); - - await server.start(); - - req = request(server.app); - }); - - afterAll(async () => { - await server.stop(); - }); - - it("shouldn't list the files inside the assets folder (404)", async () => { - const response = await req.get(`${staticPublicPath}/assets/`); - - expect(response.statusCode).toEqual(404); - }); - - it("should show Heyo. because bar has index.html inside it (200)", async () => { - const response = await req.get(`${staticPublicPath}/bar/`); - - expect(response.statusCode).toEqual(200); - expect(response.text).toContain("Heyo"); - }); - }); - - describe("test listing files in folders without index.html using the option static.serveIndex:true", () => { - beforeAll(async () => { - const compiler = webpack(config); - - server = new Server( - { - static: { - directory: publicDirectory, - publicPath: staticPublicPath, - watch: true, - serveIndex: true, - }, - port, - }, - compiler - ); - - await server.start(); - - req = request(server.app); - }); - - afterAll(async () => { - await server.stop(); - }); - - it("should list the files inside the assets folder (200)", async () => { - const response = await req.get(`${staticPublicPath}/assets/`); - - expect(response.statusCode).toEqual(200); - }); - - it("should show Heyo. because bar has index.html inside it (200)", async () => { - const response = await req.get(`${staticPublicPath}/bar/`); - - expect(response.statusCode).toEqual(200); - expect(response.text).toContain("Heyo"); - }); - }); - - describe("test listing files in folders without index.html using the option static.serveIndex default (true)", () => { - beforeAll(async () => { - const compiler = webpack(config); - - server = new Server( - { - static: { - directory: publicDirectory, - publicPath: staticPublicPath, - watch: true, - }, - port, - }, - compiler - ); - - await server.start(); - - req = request(server.app); - }); - - afterAll(async () => { - await server.stop(); - }); - - it("should list the files inside the assets folder (200)", async () => { - const response = await req.get(`${staticPublicPath}/assets/`); - - expect(response.statusCode).toEqual(200); - }); - - it("should show Heyo. because bar has index.html inside it (200)", async () => { - const response = await req.get(`${staticPublicPath}/bar/`); - - expect(response.statusCode).toEqual(200); - expect(response.text).toContain("Heyo"); - }); - }); - - describe("to directories", () => { - beforeAll(async () => { - const compiler = webpack(config); - - server = new Server( - { - static: [ - { - directory: publicDirectory, - publicPath: staticPublicPath, - }, - { - directory: otherPublicDirectory, - publicPath: staticPublicPath, - }, - ], - port, - }, - compiler - ); - - await server.start(); - - req = request(server.app); - }); - - afterAll(async () => { - await server.stop(); - }); - - it("Request to first directory", async () => { - const response = await req.get(`${staticPublicPath}/`); - - expect(response.statusCode).toEqual(200); - expect(response.text).toContain("Heyo"); - }); - - it("Request to second directory", async () => { - const response = await req.get(`${staticPublicPath}/foo.html`); - - expect(response.statusCode).toEqual(200); - expect(response.text).toContain("Foo!"); - }); - }); - - describe("default to PWD", () => { - beforeAll(async () => { - jest.spyOn(process, "cwd").mockImplementation(() => staticDirectory); - - const compiler = webpack(config); - - server = new Server( - { - static: { - publicPath: staticPublicPath, - }, - port, - }, - compiler - ); - - await server.start(); - - req = request(server.app); - }); - - afterAll(async () => { - await server.stop(); - }); - - it("Request to page", async () => { - const response = await req.get(`${staticPublicPath}/index.html`); - - expect(response.statusCode).toEqual(200); - }); - }); - - describe("Content type", () => { - beforeAll(async () => { - const compiler = webpack(config); - - server = new Server( - { - static: { - directory: publicDirectory, - publicPath: staticPublicPath, - }, - port, - }, - compiler - ); - - await server.start(); - - req = request(server.app); - }); - - afterAll(async () => { - await server.stop(); - }); - - it("Request foo.wasm", async () => { - const response = await req.get(`${staticPublicPath}/foo.wasm`); - - expect(response.headers["content-type"]).toBe("application/wasm"); - }); - }); - - describe("to ignore other methods than GET and HEAD", () => { - beforeAll(async () => { - const compiler = webpack(config); - - server = new Server( - { - static: { - directory: publicDirectory, - publicPath: staticPublicPath, - watch: true, - }, - port, - }, - compiler - ); - - await server.start(); - - req = request(server.app); - }); - - afterAll(async () => { - await server.stop(); - }); - - it("GET request", async () => { - const response = await req.get(`${staticPublicPath}/`); - - expect(response.statusCode).toEqual(200); - }); - - it("HEAD request", async () => { - const response = await req.head(`${staticPublicPath}/`); - - expect(response.statusCode).toEqual(200); - }); - - it("POST request", async () => { - const response = await req.post(`${staticPublicPath}/`); - - expect(response.statusCode).toEqual(404); - }); - - it("PUT request", async () => { - const response = await req.put(`${staticPublicPath}/`); - - expect(response.statusCode).toEqual(404); - }); - - it("DELETE request", async () => { - const response = await req.delete(`${staticPublicPath}/`); - - expect(response.statusCode).toEqual(404); - }); - - it("PATCH request", async () => { - const response = await req.patch(`${staticPublicPath}/`); - - expect(response.statusCode).toEqual(404); - }); - }); - - describe("multiple static.publicPath entries", () => { - beforeAll(async () => { - const compiler = webpack(config); - - server = new Server( - { - static: [ - { - directory: publicDirectory, - publicPath: staticPublicPath, - watch: true, - }, - { - directory: otherPublicDirectory, - publicPath: otherStaticPublicPath, - watch: true, - }, - ], - port, - }, - compiler - ); - - await server.start(); - - req = request(server.app); - }); - - afterAll(async () => { - await server.stop(); - }); - - it("Request the first path to index", async () => { - const response = await req.get(`${staticPublicPath}/`); - - expect(response.statusCode).toEqual(200); - expect(response.text).toContain("Heyo"); - }); - - it("Request the first path to other file", async () => { - const response = await req.get(`${staticPublicPath}/other.html`); - - expect(response.statusCode).toEqual(200); - expect(response.text).toContain("Other html"); - }); - - it("Request the second path to foo", async () => { - const response = await req.get(`${otherStaticPublicPath}/foo.html`); - - expect(response.statusCode).toEqual(200); - expect(response.text).toContain("Foo!"); - }); - }); - - describe("multiple static.publicPath entries with publicPath array", () => { - beforeAll(async () => { - const compiler = webpack(config); - - server = new Server( - { - static: [ - { - directory: publicDirectory, - publicPath: staticPublicPath, - watch: true, - }, - { - directory: otherPublicDirectory, - publicPath: [staticPublicPath, otherStaticPublicPath], - watch: true, - }, - ], - port, - }, - compiler - ); - - await server.start(); - - req = request(server.app); - }); - - afterAll(async () => { - await server.stop(); - }); - - it("Request the first path to index", async () => { - const response = await req.get(`${staticPublicPath}/`); - - expect(response.statusCode).toEqual(200); - expect(response.text).toContain("Heyo"); - }); - - it("Request the first path to other file", async () => { - const response = await req.get(`${staticPublicPath}/other.html`); - - expect(response.statusCode).toEqual(200); - expect(response.text).toContain("Other html"); - }); - - it("Request the first path to foo", async () => { - const response = await req.get(`${staticPublicPath}/foo.html`); - - expect(response.statusCode).toEqual(200); - expect(response.text).toContain("Foo!"); - }); - - it("Request the second path to foo", async () => { - const response = await req.get(`${staticPublicPath}/foo.html`); - - expect(response.statusCode).toEqual(200); - expect(response.text).toContain("Foo!"); - }); - }); -});