Skip to content

Commit

Permalink
add fs option (#1819)
Browse files Browse the repository at this point in the history
* add fs option, fix validation test (#1818)

* adding some more tests

* sort and normalize options
  • Loading branch information
heygrady authored and hiroppy committed Apr 27, 2019
1 parent 5195bfa commit b5bc05c
Show file tree
Hide file tree
Showing 64 changed files with 3,884 additions and 281 deletions.
422 changes: 213 additions & 209 deletions lib/options.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/utils/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function createConfig(config, argv, { port }) {
if (argv.sockPath) {
options.sockPath = argv.sockPath;
}

if (argv.sockPort) {
options.sockPort = argv.sockPort;
}
Expand Down
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"less-loader": "4.1.0",
"lint-staged": "8.1.5",
"marked": "0.6.2",
"memfs": "2.15.2",
"nyc": "14.0.0",
"prettier": "1.17.0",
"puppeteer": "1.15.0",
Expand Down
25 changes: 11 additions & 14 deletions test/Validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
no-shadow,
array-bracket-spacing
*/

const webpack = require('webpack');
const Server = require('../lib/Server');
const schema = require('../lib/options.json');
const config = require('./fixtures/simple-config/webpack.config');

const messages = schema.errorMessage.properties;

describe('Validation', () => {
let compiler;
let server;
Expand All @@ -32,44 +36,38 @@ describe('Validation', () => {
{
name: 'invalid `hot` configuration',
config: { hot: 'false' },
message:
'options.hot should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-hot)\n',
message: `options.hot ${messages.hot}`,
},
{
name: 'invalid `logLevel` configuration',
config: { logLevel: 1 },
message:
'options.logLevel should be {String} and equal to one of the allowed values',
message: `options.logLevel ${messages.logLevel.split('\n\n')[0]}`,
},
{
name: 'invalid `writeToDisk` configuration',
config: { writeToDisk: 1 },
message:
'options.writeToDisk should be {Boolean|Function} (https://github.com/webpack/webpack-dev-middleware#writetodisk)\n',
message: `options.writeToDisk ${messages.writeToDisk}`,
},
{
name: 'invalid `overlay` configuration',
config: { overlay: { errors: 1 } },
message:
'options.overlay should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-overlay)\n',
message: `options.overlay ${messages.overlay}`,
},
{
name: 'invalid `contentBase` configuration',
config: { contentBase: [0] },
message:
'options.contentBase should be {Array} (https://webpack.js.org/configuration/dev-server/#devserver-contentbase)\n',
message: `options.contentBase ${messages.contentBase}`,
},
{
name: 'no additional properties',
config: { additional: true },
message: 'options should NOT have additional properties\n',
message: 'options should NOT have additional properties',
},
];

tests.forEach((test) => {
it(`should fail validation for ${test.name}`, () => {
try {
// eslint-disable-next-line no-new
server = new Server(compiler, test.config);
} catch (err) {
if (err.name !== 'ValidationError') {
Expand All @@ -79,7 +77,7 @@ describe('Validation', () => {
const [title, message] = err.message.split('\n\n');

expect(title).toEqual('webpack Dev Server Invalid Options');
expect(message).toEqual(test.message);
expect(message.trim()).toEqual(test.message);

return;
}
Expand All @@ -98,7 +96,6 @@ describe('Validation', () => {

it('should allow filename to be a function', () => {
try {
// eslint-disable-next-line no-new
server = new Server(compiler, { filename: () => {} });
} catch (err) {
if (err === 'ValidationError') {
Expand Down
2 changes: 1 addition & 1 deletion test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('CLI', () => {
})
.catch(done);
});

it('--color', (done) => {
runDevServer('--color')
.then((output) => {
Expand Down
116 changes: 60 additions & 56 deletions test/options/__snapshots__/options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,71 @@

exports[`options should return errorMessage 1`] = `
Object {
"after": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserver-after)",
"allowedHosts": "should be {Array} (https://webpack.js.org/configuration/dev-server/#devserver-allowedhosts)",
"before": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserver-before)",
"bonjour": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-bonjour)",
"ca": "should be {String|Buffer} (https://webpack.js.org/configuration/dev-server/#devserver-ca)",
"cert": "should be {String|Buffer} (https://webpack.js.org/configuration/dev-server/#devserver-cert)",
"after": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserverafter)",
"allowedHosts": "should be {Array} (https://webpack.js.org/configuration/dev-server/#devserverallowedhosts)",
"before": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserverbefore)",
"bonjour": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverbonjour)",
"ca": "should be {String|Buffer}",
"cert": "should be {String|Buffer}",
"clientLogLevel": "should be {String} and equal to one of the allowed values
[ 'trace', 'debug', 'info', 'warn', 'error', 'silent' ]
[ 'none', 'info', 'error', 'warning' ]
(https://webpack.js.org/configuration/dev-server/#devserver-clientloglevel)",
"compress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-compress)",
"contentBase": "should be {Array} (https://webpack.js.org/configuration/dev-server/#devserver-contentbase)",
"disableHostCheck": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-disablehostcheck)",
"features": "should be {Array} (https://webpack.js.org/configuration/dev-server/#devserver-features)",
"filename": "should be {String|RegExp|Function} (https://webpack.js.org/configuration/dev-server/#devserver-filename-)",
"headers": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserver-headers-)",
"historyApiFallback": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-historyapifallback)",
"host": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-host)",
"hot": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-hot)",
"hotOnly": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-hotonly)",
"http2": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-http2)",
"https": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-https)",
"index": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-index)",
"injectClient": "should be {Array}",
"injectHot": "should be {Array}",
"inline": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-inline)",
"key": "should be {String|Buffer} (https://webpack.js.org/configuration/dev-server/#devserver-key)",
"lazy": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-lazy-)",
"log": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserver-log)",
(https://webpack.js.org/configuration/dev-server/#devserverclientloglevel)",
"compress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devservercompress)",
"contentBase": "should be {Number|String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbase)",
"disableHostCheck": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck)",
"features": "should be {Array}",
"filename": "should be {String|RegExp|Function} (https://webpack.js.org/configuration/dev-server/#devserverfilename-)",
"fs": "should be {Object} (https://github.com/webpack/webpack-dev-middleware#fs)",
"headers": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverheaders-)",
"historyApiFallback": "should be {Boolean|Object} (https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback)",
"host": "should be {String|Null} (https://webpack.js.org/configuration/dev-server/#devserverhost)",
"hot": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhot)",
"hotOnly": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhotonly)",
"http2": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhttp2)",
"https": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhttps)",
"index": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverindex)",
"injectClient": "should be {Boolean|Function}",
"injectHot": "should be {Boolean|Function}",
"inline": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverinline)",
"key": "should be {String|Buffer}",
"lazy": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverlazy-)",
"log": "should be {Function}",
"logLevel": "should be {String} and equal to one of the allowed values
[ 'trace', 'debug', 'info', 'warn', 'error', 'silent' ]
[ 'info', 'warn', 'error', 'debug', 'trace', 'silent' ]
(https://webpack.js.org/configuration/dev-server/#devserver-loglevel)",
"logTime": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-logtime)",
(https://github.com/webpack/webpack-dev-middleware#loglevel)",
"logTime": "should be {Boolean} (https://github.com/webpack/webpack-dev-middleware#logtime)",
"mimeTypes": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devservermimetypes-)",
"noInfo": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-noinfo-)",
"open": "should be {String|Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-open)",
"openPage": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-openpage)",
"overlay": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-overlay)",
"pfx": "should be {String|Buffer} (https://webpack.js.org/configuration/dev-server/#devserver-pfx)",
"pfxPassphrase": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-pfxpassphrase)",
"port": "should be {String|Number} (https://webpack.js.org/configuration/dev-server/#devserver-port)",
"progress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-progress-cli-only)",
"proxy": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-hot)",
"public": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-public)",
"publicPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-publicpath-)",
"quiet": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-quiet-)",
"reporter": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserver-reporter)",
"requestCert": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-requestcert)",
"noInfo": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devservernoinfo-)",
"open": "should be {String|Boolean} (https://webpack.js.org/configuration/dev-server/#devserveropen)",
"openPage": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserveropenpage)",
"overlay": "should be {Boolean|Object} (https://webpack.js.org/configuration/dev-server/#devserveroverlay)",
"pfx": "should be {String|Buffer} (https://webpack.js.org/configuration/dev-server/#devserverpfx)",
"pfxPassphrase": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverpfxpassphrase)",
"port": "should be {Number|String|Null} (https://webpack.js.org/configuration/dev-server/#devserverport)",
"progress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverprogress---cli-only)",
"proxy": "should be {Object|Array} (https://webpack.js.org/configuration/dev-server/#devserverproxy)",
"public": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverpublic)",
"publicPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverpublicpath-)",
"quiet": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverquiet-)",
"reporter": "should be {Function} (https://github.com/webpack/webpack-dev-middleware#reporter)",
"requestCert": "should be {Boolean}",
"serveIndex": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverserveindex)",
"serverSideRender": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-serversiderender)",
"setup": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserver-setup)",
"sockPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-sockPath)",
"sockPort": "should be {Array}",
"socket": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-socket)",
"staticOptions": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-staticOptions)",
"stats": "should be {Boolean|Object|String} (https://webpack.js.org/configuration/dev-server/#devserver-stats-)",
"useLocalIp": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-uselocalip)",
"warn": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserver-warn)",
"watchContentBase": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-watchcontentbase)",
"watchOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserver-watchoptions)",
"writeToDisk": "should be {Boolean|Function} (https://github.com/webpack/webpack-dev-middleware#writetodisk)",
"serverSideRender": "should be {Boolean} (https://github.com/webpack/webpack-dev-middleware#serversiderender)",
"setup": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserversetup)",
"sockPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserversockpath)",
"sockPort": "should be {Number|String|Null}",
"socket": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserversocket)",
"staticOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverstaticoptions)",
"stats": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserverstats-)",
"useLocalIp": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserveruselocalip)",
"warn": "should be {Function}",
"watchContentBase": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverwatchcontentbase)",
"watchOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverwatchoptions-)",
"writeToDisk": "should be {Boolean|Function} (https://webpack.js.org/configuration/dev-server/#devserverwritetodisk-)",
}
`;
Expand Down Expand Up @@ -161,6 +162,9 @@ Object {
},
],
},
"fs": Object {
"type": "object",
},
"headers": Object {
"type": "object",
},
Expand Down
52 changes: 52 additions & 0 deletions test/options/after.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

const ValidationError = require('schema-utils/src/ValidationError');
const webpack = require('webpack');
const Server = require('../../lib/Server');
const config = require('../fixtures/simple-config/webpack.config');

describe('Validation', () => {
let compiler;
let server;

beforeAll(() => {
compiler = webpack(config);
});

describe('after', () => {
beforeEach(() => {
server = null;
});
afterEach((done) => {
if (server) {
server.close(() => {
done();
});
} else {
done();
}
});

it('should allow after to be function', () => {
let error = null;
try {
const after = () => {};

server = new Server(compiler, { after });
} catch (err) {
error = err;
}
expect(error).toBe(null);
});

it('should not allow after to be the wrong type', () => {
let error = null;
try {
server = new Server(compiler, { after: false });
} catch (err) {
error = err;
}
expect(error).toBeInstanceOf(ValidationError);
});
});
});
Loading

0 comments on commit b5bc05c

Please sign in to comment.