-
-
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
fix(server): use regex instead of isAbsoluteUrl #2202
Changes from 4 commits
f381ccb
fded1d8
8a827e8
bf74632
cdb65ed
5234a39
c972787
1396a98
75630c5
4a6fea4
b415ede
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ function runOpen(uri, options, log) { | |
} | ||
|
||
const pageUrl = | ||
options.openPage && isAbsoluteUrl(options.openPage) | ||
options.openPage && isAbsoluteUrl(String(options.openPage)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need this here, if you have problem place let's solve this in other PR |
||
? options.openPage | ||
: `${uri}${options.openPage || ''}`; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -268,7 +268,7 @@ describe('contentBase option', () => { | |
}); | ||
|
||
describe('testing single & multiple external paths', () => { | ||
afterAll((done) => { | ||
afterEach((done) => { | ||
testServer.close(() => { | ||
done(); | ||
}); | ||
|
@@ -301,6 +301,29 @@ describe('contentBase option', () => { | |
done(); | ||
} | ||
}); | ||
it('Should not throw exception (local path with lower case first character)', (done) => { | ||
try { | ||
// eslint-disable-next-line no-unused-vars | ||
server = new Promise((resolve, reject) => { | ||
testServer.start(config, { | ||
contentBase: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add two tests here |
||
contentBasePublic.charAt(0).toLowerCase() + | ||
contentBasePublic.substring(1), | ||
watchContentBase: true, | ||
port: 2222, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use the port number directly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if I use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't add the port number. diff --git a/test/server/contentBase-option.test.js b/test/server/contentBase-option.test.js
index fe120e5..bcde1e6 100644
--- a/test/server/contentBase-option.test.js
+++ b/test/server/contentBase-option.test.js
@@ -269,10 +269,10 @@ describe('contentBase option', () => {
describe('testing single & multiple external paths', () => {
afterEach((done) => {
- testServer.close(() => {
- done();
- });
+ testServer.close(done);
});
+
it('Should throw exception (string)', (done) => {
try {
// eslint-disable-next-line no-unused-vars
@@ -302,71 +302,40 @@ describe('contentBase option', () => {
}
});
it('Should not throw exception (local path with lower case first character)', (done) => {
- try {
- // eslint-disable-next-line no-unused-vars
- server = new Promise((resolve, reject) => {
- testServer.start(config, {
- contentBase:
- contentBasePublic.charAt(0).toLowerCase() +
- contentBasePublic.substring(1),
- watchContentBase: true,
- port: 2222,
- });
- resolve(testServer);
- });
-
- server.then((testServer) => {
- testServer.close(() => {
- done();
- });
- });
- } catch (e) {
- expect(true).toBe(false);
- }
+ testServer.start(
+ config,
+ {
+ contentBase:
+ contentBasePublic.charAt(0).toLowerCase() +
+ contentBasePublic.substring(1),
+ watchContentBase: true,
+ port,
+ },
+ done
+ );
});
it("Should not throw exception (local path with lower case first character & has '-')", (done) => {
- try {
- // eslint-disable-next-line no-unused-vars
- server = new Promise((resolve, reject) => {
- testServer.start(config, {
- contentBase: 'c:\\absolute\\path\\to\\content-base',
- watchContentBase: true,
- port: 2223,
- });
- resolve(testServer);
- });
-
- server.then((testServer) => {
- testServer.close(() => {
- done();
- });
- });
- } catch (e) {
- expect(true).toBe(false);
- }
+ testServer.start(
+ config,
+ {
+ contentBase: 'c:\\absolute\\path\\to\\content-base',
+ watchContentBase: true,
+ port,
+ },
+ done
+ );
});
it("Should not throw exception (local path with upper case first character & has '-')", (done) => {
- try {
- // eslint-disable-next-line no-unused-vars
- server = new Promise((resolve, reject) => {
- testServer.start(config, {
- contentBase: 'C:\\absolute\\path\\to\\content-base',
- watchContentBase: true,
- port: 2224,
- });
- resolve(testServer);
- });
-
- server.then((testServer) => {
- testServer.close(() => {
- done();
- });
- });
- } catch (e) {
- expect(true).toBe(false);
- }
+ testServer.start(
+ config,
+ {
+ contentBase: 'C:\\absolute\\path\\to\\content-base',
+ watchContentBase: true,
+ port,
+ },
+ done
+ );
});
-
it('Should throw exception (array)', (done) => {
try {
// eslint-disable-next-line no-unused-vars You can patch this code. |
||
}); | ||
resolve(testServer); | ||
}); | ||
|
||
server.then((testServer) => { | ||
testServer.close(() => { | ||
done(); | ||
}); | ||
}); | ||
} catch (e) { | ||
expect(true).toBe(false); | ||
} | ||
}); | ||
it('Should throw exception (array)', (done) => { | ||
try { | ||
// eslint-disable-next-line no-unused-vars | ||
|
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.
Why we add
typeof item === 'number'
?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 it's already blocking number values in options.js accepting only strings, in case in future refactors if we change the type of array items to accept any type we still need it to throw an exception if the array item is number type.
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 we can remove number type from options.json
and remove
|| typeof item === 'number'
checks and update tests to check for the exception"should be {String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbase)"
in number type caseswhat do you think ?
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 do it next version