-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: add option "serveIndex" to enable/disable serveIndex middleware #1752
Feature: add option "serveIndex" to enable/disable serveIndex middleware #1752
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1752 +/- ##
=========================================
+ Coverage 87.54% 87.6% +0.06%
=========================================
Files 9 9
Lines 586 589 +3
Branches 173 175 +2
=========================================
+ Hits 513 516 +3
Misses 61 61
Partials 12 12
Continue to review full report at Codecov.
|
if I got it right I tried to create a test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add tests
@evilebottnawi here is a minimum reproducible test repo : https://github.com/EslamHiko/webpack-dev-server/tree/serve-index-option-test
I wanted to write a jest test but i got |
lib/Server.js
Outdated
if (contentBase !== false) { | ||
if ( | ||
contentBase !== false && | ||
(options.serveIndex || typeof options.serveIndex === 'undefined') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use typeof
, we prefer using !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(options.serveIndex || options.serveIndex === undefined)
@evilebottnawi done
lib/Server.js
Outdated
@@ -555,7 +555,7 @@ class Server { | |||
|
|||
if ( | |||
contentBase !== false && | |||
(options.serveIndex || typeof options.serveIndex === 'undefined') | |||
(options.serveIndex || options.serveIndex === undefined) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just simplify:
const shouldHandleServeIndex = contentBase || options.serveIndex
serveIndex
by default should be true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evilebottnawi i've simplified the condition & i added a comment to elaborate why i'm comparing with undefined
if (contentBase !== false) {
// checking if it's set to true or not set (Default : undefined => true)
options.serveIndex = options.serveIndex || options.serveIndex === undefined;
const shouldHandleServeIndex = contentBase && options.serveIndex;
if (shouldHandleServeIndex) {
defaultFeatures.push('contentBaseIndex');
}
lib/Server.js
Outdated
(options.serveIndex || options.serveIndex === undefined) | ||
) { | ||
// checking if it's set to true or not set (Default : undefined => true) | ||
options.serveIndex = options.serveIndex || options.serveIndex === undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better avoid modify options
because code below also can use options and modification original options is not good idea better keep this in separate variable, it is good practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evilebottnawi thank you for the advice, I set the option value to a separate variable this.serveIndex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but we need add test for this
@evilebottnawi here is a minimum reproducible test repo with the new code: https://github.com/EslamHiko/webpack-dev-server/tree/serve-index-option-test2 testing is the same as this comment :
if there is any way to use jest to browse folders it'll be great to create a jest test for it. |
We have test for contentBase, so test should be same |
@evilebottnawi I added valid tests testing True,False & default settings, you wouldn't believe what caused the |
/cc @hiroppy |
|
||
it('should list the files inside the assets folder (200)', (done) => { | ||
req.get('/assets/').expect(200, done); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the following test here because it is confirmed in serveIndex:false
.
it('should show Heyo. because bar has index.html inside it (200)', (done) => {
req.get('/bar/').expect(200, /Heyo/, done);
});
it('should list the files inside the assets folder (200)', (done) => { | ||
req.get('/assets/').expect(200, done); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@hiroppy Done |
/cc @hiroppy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thanks!
@hiroppy You're Welcome 😄 |
For Bugs and Features; did you add new tests?
I used the examples in the example folder
Motivation / Use-Case
add this feature #1745
Breaking Changes
it disables/enables serveIndex
Additional Info