Skip to content

Commit

Permalink
test(server): add tests only
Browse files Browse the repository at this point in the history
  • Loading branch information
EslamHiko committed Aug 21, 2019
1 parent fded1d8 commit 8a827e8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
13 changes: 8 additions & 5 deletions lib/Server.js
Expand Up @@ -23,11 +23,11 @@ const serveIndex = require('serve-index');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const validateOptions = require('schema-utils');
const isAbsoluteUrl = require('is-absolute-url');
const normalizeOptions = require('./utils/normalizeOptions');
const updateCompiler = require('./utils/updateCompiler');
const createLogger = require('./utils/createLogger');
const getCertificate = require('./utils/getCertificate');
const checkUrl = require('./utils/checkUrl');
const status = require('./utils/status');
const createDomain = require('./utils/createDomain');
const runBonjour = require('./utils/runBonjour');
Expand Down Expand Up @@ -339,7 +339,7 @@ class Server {
contentBase.forEach((item) => {
this.app.get('*', express.static(item));
});
} else if (checkUrl(contentBase)) {
} else if (isAbsoluteUrl(String(contentBase))) {
this.log.warn(
'Using a URL as contentBase is deprecated and will be removed in the next major version. Please use the proxy option instead.'
);
Expand Down Expand Up @@ -390,19 +390,22 @@ class Server {
contentBase.forEach((item) => {
this.app.get('*', serveIndex(item));
});
} else if (typeof contentBase !== 'number' && !checkUrl(contentBase)) {
} else if (
typeof contentBase !== 'number' &&
!isAbsoluteUrl(String(contentBase))
) {
this.app.get('*', serveIndex(contentBase));
}
}

setupWatchStaticFeature() {
const contentBase = this.options.contentBase;

if (checkUrl(contentBase) || typeof contentBase === 'number') {
if (isAbsoluteUrl(String(contentBase)) || typeof contentBase === 'number') {
throw new Error('Watching remote files is not supported.');
} else if (Array.isArray(contentBase)) {
contentBase.forEach((item) => {
if (checkUrl(item) || typeof item === 'number') {
if (isAbsoluteUrl(String(item)) || typeof item === 'number') {
throw new Error('Watching remote files is not supported.');
}
this._watch(item);
Expand Down
7 changes: 0 additions & 7 deletions lib/utils/checkUrl.js

This file was deleted.

9 changes: 6 additions & 3 deletions lib/utils/createConfig.js
@@ -1,8 +1,8 @@
'use strict';

const path = require('path');
const isAbsoluteUrl = require('is-absolute-url');
const defaultTo = require('./defaultTo');
const checkUrl = require('./checkUrl');

function createConfig(config, argv, { port }) {
const firstWpOpt = Array.isArray(config) ? config[0] : config;
Expand Down Expand Up @@ -64,7 +64,10 @@ function createConfig(config, argv, { port }) {
options.publicPath =
(firstWpOpt.output && firstWpOpt.output.publicPath) || '';

if (!checkUrl(options.publicPath) && options.publicPath[0] !== '/') {
if (
!isAbsoluteUrl(String(options.publicPath)) &&
options.publicPath[0] !== '/'
) {
options.publicPath = `/${options.publicPath}`;
}
}
Expand Down Expand Up @@ -111,7 +114,7 @@ function createConfig(config, argv, { port }) {
options.contentBase = options.contentBase.map((p) => path.resolve(p));
} else if (/^[0-9]$/.test(options.contentBase)) {
options.contentBase = +options.contentBase;
} else if (!checkUrl(options.contentBase)) {
} else if (!isAbsoluteUrl(String(options.contentBase))) {
options.contentBase = path.resolve(options.contentBase);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/runOpen.js
@@ -1,7 +1,7 @@
'use strict';

const open = require('opn');
const checkUrl = require('./checkUrl');
const isAbsoluteUrl = require('is-absolute-url');

function runOpen(uri, options, log) {
// https://github.com/webpack/webpack-dev-server/issues/1990
Expand All @@ -14,7 +14,7 @@ function runOpen(uri, options, log) {
}

const pageUrl =
options.openPage && checkUrl(options.openPage)
options.openPage && isAbsoluteUrl(String(options.openPage))
? options.openPage
: `${uri}${options.openPage || ''}`;

Expand Down

0 comments on commit 8a827e8

Please sign in to comment.