add fs option#1819
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1819 +/- ##
=========================================
+ Coverage 87.66% 89.47% +1.8%
=========================================
Files 9 9
Lines 608 608
Branches 185 185
=========================================
+ Hits 533 544 +11
+ Misses 63 54 -9
+ Partials 12 10 -2
Continue to review full report at Codecov.
|
| throw new Error("Validation failed and it shouldn't"); | ||
| } | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Move this to other test file (fs.test.js)
|
For posterity, this is the script I used to organize the 'use strict';
const fs = require('fs-extra');
const ucFirst = require('lodash.upperfirst');
const middlewareLinks = [
'https://github.com/webpack/webpack-dev-middleware#methods',
'https://github.com/webpack/webpack-dev-middleware#headers',
'https://github.com/webpack/webpack-dev-middleware#index',
'https://github.com/webpack/webpack-dev-middleware#lazy',
'https://github.com/webpack/webpack-dev-middleware#logger',
'https://github.com/webpack/webpack-dev-middleware#loglevel',
'https://github.com/webpack/webpack-dev-middleware#logtime',
'https://github.com/webpack/webpack-dev-middleware#mimetypes',
'https://github.com/webpack/webpack-dev-middleware#publicpath',
'https://github.com/webpack/webpack-dev-middleware#reporter',
'https://github.com/webpack/webpack-dev-middleware#serversiderender',
'https://github.com/webpack/webpack-dev-middleware#stats',
'https://github.com/webpack/webpack-dev-middleware#watchoptions',
'https://github.com/webpack/webpack-dev-middleware#writetodisk',
'https://github.com/webpack/webpack-dev-middleware#fs',
];
const links = [
'https://webpack.js.org/configuration/dev-server/#devserverafter',
'https://webpack.js.org/configuration/dev-server/#devserverallowedhosts',
'https://webpack.js.org/configuration/dev-server/#devserverbefore',
'https://webpack.js.org/configuration/dev-server/#devserverbonjour',
'https://webpack.js.org/configuration/dev-server/#devserverclientloglevel',
'https://webpack.js.org/configuration/dev-server/#devservercolor---cli-only',
'https://webpack.js.org/configuration/dev-server/#devservercompress',
'https://webpack.js.org/configuration/dev-server/#devservercontentbase',
'https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck',
'https://webpack.js.org/configuration/dev-server/#devserverfilename-',
'https://webpack.js.org/configuration/dev-server/#devserverheaders-',
'https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback',
'https://webpack.js.org/configuration/dev-server/#devserverhost',
'https://webpack.js.org/configuration/dev-server/#devserverhot',
'https://webpack.js.org/configuration/dev-server/#devserverhotonly',
'https://webpack.js.org/configuration/dev-server/#devserverhttp2',
'https://webpack.js.org/configuration/dev-server/#devserverhttps',
'https://webpack.js.org/configuration/dev-server/#devserverindex',
'https://webpack.js.org/configuration/dev-server/#devserverinfo---cli-only',
'https://webpack.js.org/configuration/dev-server/#devserverinline',
'https://webpack.js.org/configuration/dev-server/#devserverlazy-',
'https://webpack.js.org/configuration/dev-server/#devservermimetypes-',
'https://webpack.js.org/configuration/dev-server/#devservernoinfo-',
'https://webpack.js.org/configuration/dev-server/#devserveropen',
'https://webpack.js.org/configuration/dev-server/#devserveropenpage',
'https://webpack.js.org/configuration/dev-server/#devserveroverlay',
'https://webpack.js.org/configuration/dev-server/#devserverpfx',
'https://webpack.js.org/configuration/dev-server/#devserverpfxpassphrase',
'https://webpack.js.org/configuration/dev-server/#devserverport',
'https://webpack.js.org/configuration/dev-server/#devserverproxy',
'https://webpack.js.org/configuration/dev-server/#devserverprogress---cli-only',
'https://webpack.js.org/configuration/dev-server/#devserverpublic',
'https://webpack.js.org/configuration/dev-server/#devserverpublicpath-',
'https://webpack.js.org/configuration/dev-server/#devserverquiet-',
'https://webpack.js.org/configuration/dev-server/#devserverserveindex',
'https://webpack.js.org/configuration/dev-server/#devserversetup',
'https://webpack.js.org/configuration/dev-server/#devserversocket',
'https://webpack.js.org/configuration/dev-server/#devserversockpath',
'https://webpack.js.org/configuration/dev-server/#devserverstaticoptions',
'https://webpack.js.org/configuration/dev-server/#devserverstats-',
'https://webpack.js.org/configuration/dev-server/#devserverstdin---cli-only',
'https://webpack.js.org/configuration/dev-server/#devserveruselocalip',
'https://webpack.js.org/configuration/dev-server/#devserverwatchcontentbase',
'https://webpack.js.org/configuration/dev-server/#devserverwatchoptions-',
'https://webpack.js.org/configuration/dev-server/#devserverwritetodisk-',
];
const findPropLink = (prop) =>
links.find((link) => link.includes(`#devserver${prop.toLowerCase()}`)) ||
middlewareLinks.find((link) =>
link.endsWith(`middleware#${prop.toLowerCase()}`)
);
const fixOptions = async () => {
const options = await fs.readJson('./lib/options.json');
// regenerate error messages, marry them with the correct links
const errorMessages = {};
for (const [prop, value] of Object.entries(options.properties)) {
let message = 'should be ';
if (value.type || value.instanceof) {
message += `{${ucFirst(value.type || value.instanceof)}}`;
} else if (value.anyOf) {
const type = value.anyOf
.map((obj) => ucFirst(obj.type || obj.instanceof))
.filter(Boolean)
.join('|');
message += `{${type}}`;
} else if (value.enum) {
const values = value.enum.map((string) => `'${string}'`).join(', ');
message += `{String} and equal to one of the allowed values\n\n [ ${values} ]\n\n`;
} else {
console.error(
`Did not handle ${prop}, unable to process value: ${JSON.stringify(
value
)}`
);
}
const link = findPropLink(prop);
if (link) {
message += ` (${link})`;
}
errorMessages[prop] = message;
}
// sort the keys
const originalProperties = options.properties;
const keys = Object.keys(originalProperties).sort();
options.properties = {};
options.errorMessage.properties = {};
for (const key of keys) {
options.properties[key] = originalProperties[key];
options.errorMessage.properties[key] = errorMessages[key];
}
await fs.writeJson('./lib/options.json', options, { spaces: ' ' });
// identify webpack-dev-middleware options that are not in the options.json
const lowerKeys = new Set(keys.map((key) => key.toLowerCase()));
for (const link of middlewareLinks) {
const [, prop] = link.split('#');
if (!lowerKeys.has(prop)) {
console.warn(
`${prop} is a valid middleware option that is not in the options.json file.`
);
}
}
};
fixOptions(); |
| throw err; | ||
| } | ||
|
|
||
| throw new Error("Validation failed and it shouldn't"); |
There was a problem hiding this comment.
Each test should contain expect, let's move error (let error = null) on top and check expect(error).toBe(null)
|
IMO, I want to add |
|
Yes let's do it 👍 |
|
/cc @heygrady |
|
I created options tests so please rebase this if it is merged. Thank you for adding options tests! |
|
/cc @heygrady hi, need rebase, thanks |
|
Rebased. Some notes:
|
|
/cc @hiroppy |
add fs option, sort options file, correct links in error messages, fix validation test (#1818)