Skip to content

Commit

Permalink
tests(refactor): better test suite for binary tests (#635)
Browse files Browse the repository at this point in the history
* chore(tests): PoC on new way of running integration tests

* tests(refactor): started moving to a better test suite case

* tests(refactoring): refactored entry point tests

* tests(refactoring): refactored entry points tests

* tests(refactoring): refactored configFile bins

* tests(refactoring): refactored errors

* tests(refactoring): ported the rest of the tests

* chore(tests): remove snapshots that are dynamic

* chore(tests): moved setTimout before running the tests

* chore(tests): applied suggestions on async tests

* chore(tests): apply timeout to wait for output from the process

* chore(tests): added maxWorkers to CI

* chore: revise n-workers

* chore: update tests

* chore: add async-await and revise babel

* chore: increase timeout

* chore: revise timeout

* chore: more async timeouts

* chore: add async timeout

* chore: async
  • Loading branch information
ematipico authored and dhruvdutt committed Nov 4, 2018
1 parent 8f8937e commit ca1e4a3
Show file tree
Hide file tree
Showing 180 changed files with 4,693 additions and 12,474 deletions.
11 changes: 11 additions & 0 deletions .babelrc
@@ -0,0 +1,11 @@
{
"presets": [
["env",
{
"targets": {
"node": "current"
}
}],
"jest"
]
}
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -24,6 +24,8 @@ coverage

# Test Compilation
test/js/*
test/binCases/**/bin/
test/binCases/**/**/bin/

# lerna log
lerna-debug.log
Expand Down
5 changes: 5 additions & 0 deletions .prettierrc
@@ -0,0 +1,5 @@
{
"useTabs": true,
"tabWidth": 4,
"printWidth": 120
}
73 changes: 17 additions & 56 deletions bin/cli.js
Expand Up @@ -45,9 +45,7 @@
return require("./prompt-command")(NON_COMPILATION_CMD, ...process.argv);
}

const yargs = require("yargs").usage(`webpack-cli ${
require("../package.json").version
}
const yargs = require("yargs").usage(`webpack-cli ${require("../package.json").version}
Usage: webpack-cli [options]
webpack-cli [options] --entry <entry> --output <output>
Expand Down Expand Up @@ -164,8 +162,7 @@ For more information, see https://webpack.js.org/api/cli/.`);
"display-used-exports": {
type: "boolean",
group: DISPLAY_GROUP,
describe:
"Display information about used exports in modules (Tree Shaking)"
describe: "Display information about used exports in modules (Tree Shaking)"
},
"display-provided-exports": {
type: "boolean",
Expand All @@ -175,8 +172,7 @@ For more information, see https://webpack.js.org/api/cli/.`);
"display-optimization-bailout": {
type: "boolean",
group: DISPLAY_GROUP,
describe:
"Display information about why optimization bailed out for modules"
describe: "Display information about why optimization bailed out for modules"
},
"display-error-details": {
type: "boolean",
Expand All @@ -185,15 +181,7 @@ For more information, see https://webpack.js.org/api/cli/.`);
},
display: {
type: "string",
choices: [
"",
"verbose",
"detailed",
"normal",
"minimal",
"errors-only",
"none"
],
choices: ["", "verbose", "detailed", "normal", "minimal", "errors-only", "none"],
group: DISPLAY_GROUP,
describe: "Select display preset"
},
Expand All @@ -207,8 +195,7 @@ For more information, see https://webpack.js.org/api/cli/.`);
default: "info",
choices: ["none", "info", "verbose"],
group: DISPLAY_GROUP,
describe:
"Controls the output of lifecycle messaging e.g. Started watching files..."
describe: "Controls the output of lifecycle messaging e.g. Started watching files..."
},
"build-delimiter": {
type: "string",
Expand Down Expand Up @@ -295,10 +282,7 @@ For more information, see https://webpack.js.org/api/cli/.`);
const statsPresetToOptions = require("webpack").Stats.presetToOptions;

let outputOptions = options.stats;
if (
typeof outputOptions === "boolean" ||
typeof outputOptions === "string"
) {
if (typeof outputOptions === "boolean" || typeof outputOptions === "string") {
outputOptions = statsPresetToOptions(outputOptions);
} else if (!outputOptions) {
outputOptions = {};
Expand All @@ -312,8 +296,7 @@ For more information, see https://webpack.js.org/api/cli/.`);
if (Array.isArray(options) && !outputOptions.children) {
outputOptions.children = options.map(o => o.stats);
}
if (typeof outputOptions.context === "undefined")
outputOptions.context = firstOptions.context;
if (typeof outputOptions.context === "undefined") outputOptions.context = firstOptions.context;

ifArg("env", function(value) {
if (outputOptions.env) {
Expand All @@ -328,8 +311,7 @@ For more information, see https://webpack.js.org/api/cli/.`);
}
});

if (typeof outputOptions.colors === "undefined")
outputOptions.colors = require("supports-color").stdout;
if (typeof outputOptions.colors === "undefined") outputOptions.colors = require("supports-color").stdout;

ifArg("sort-modules-by", function(value) {
outputOptions.modulesSort = value;
Expand All @@ -348,10 +330,8 @@ For more information, see https://webpack.js.org/api/cli/.`);
});

if (!outputOptions.json) {
if (typeof outputOptions.cached === "undefined")
outputOptions.cached = false;
if (typeof outputOptions.cachedAssets === "undefined")
outputOptions.cachedAssets = false;
if (typeof outputOptions.cached === "undefined") outputOptions.cached = false;
if (typeof outputOptions.cachedAssets === "undefined") outputOptions.cachedAssets = false;

ifArg("display-chunks", function(bool) {
if (bool) {
Expand Down Expand Up @@ -405,12 +385,7 @@ For more information, see https://webpack.js.org/api/cli/.`);
if (bool) outputOptions.cachedAssets = true;
});

if (!outputOptions.exclude)
outputOptions.exclude = [
"node_modules",
"bower_components",
"components"
];
if (!outputOptions.exclude) outputOptions.exclude = ["node_modules", "bower_components", "components"];

if (argv["display-modules"]) {
outputOptions.maxModules = Infinity;
Expand Down Expand Up @@ -442,10 +417,7 @@ For more information, see https://webpack.js.org/api/cli/.`);
compiler = webpack(options);
} catch (err) {
if (err.name === "WebpackOptionsValidationError") {
if (argv.color)
console.error(
`\u001b[1m\u001b[31m${err.message}\u001b[39m\u001b[22m`
);
if (argv.color) console.error(`\u001b[1m\u001b[31m${err.message}\u001b[39m\u001b[22m`);
else console.error(err.message);
// eslint-disable-next-line no-process-exit
process.exit(1);
Expand Down Expand Up @@ -490,47 +462,36 @@ For more information, see https://webpack.js.org/api/cli/.`);
process.exit(1); // eslint-disable-line
}
if (outputOptions.json) {
stdout.write(
JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n"
);
stdout.write(JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n");
} else if (stats.hash !== lastHash) {
lastHash = stats.hash;
if (stats.compilation && stats.compilation.errors.length !== 0) {
const errors = stats.compilation.errors;
if (errors[0].name === "EntryModuleNotFoundError") {
console.error(
"\n\u001b[1m\u001b[31mInsufficient number of arguments or no entry found."
);
console.error("\n\u001b[1m\u001b[31mInsufficient number of arguments or no entry found.");
console.error(
"\u001b[1m\u001b[31mAlternatively, run 'webpack(-cli) --help' for usage info.\u001b[39m\u001b[22m\n"
);
}
}
const statsString = stats.toString(outputOptions);
const delimiter = outputOptions.buildDelimiter
? `${outputOptions.buildDelimiter}\n`
: "";
const delimiter = outputOptions.buildDelimiter ? `${outputOptions.buildDelimiter}\n` : "";
if (statsString) stdout.write(`${statsString}\n${delimiter}`);
}
if (!options.watch && stats.hasErrors()) {
process.exitCode = 2;
}
}
if (firstOptions.watch || options.watch) {
const watchOptions =
firstOptions.watchOptions ||
firstOptions.watch ||
options.watch ||
{};
const watchOptions = firstOptions.watchOptions || firstOptions.watch || options.watch || {};
if (watchOptions.stdin) {
process.stdin.on("end", function(_) {
process.exit(); // eslint-disable-line
});
process.stdin.resume();
}
compiler.watch(watchOptions, compilerCallback);
if (outputOptions.infoVerbosity !== "none")
console.log("\nwebpack is watching the files…\n");
if (outputOptions.infoVerbosity !== "none") console.log("\nwebpack is watching the files…\n");
} else compiler.run(compilerCallback);
}

Expand Down
36 changes: 9 additions & 27 deletions bin/config-yargs.js
Expand Up @@ -20,11 +20,7 @@ const resolveSchema = schema => {
const findPropertyInSchema = (schema, property, subProperty) => {
if (!schema) return null;
if (subProperty) {
if (
schema[property] &&
typeof schema[property] === "object" &&
subProperty in schema[property]
) {
if (schema[property] && typeof schema[property] === "object" && subProperty in schema[property]) {
return resolveSchema(schema[property][subProperty]);
}
} else {
Expand All @@ -34,11 +30,7 @@ const findPropertyInSchema = (schema, property, subProperty) => {
if (schema[name]) {
for (const item of schema[name]) {
const resolvedItem = resolveSchema(item);
const result = findPropertyInSchema(
resolvedItem,
property,
subProperty
);
const result = findPropertyInSchema(resolvedItem, property, subProperty);
if (result) return result;
}
}
Expand All @@ -51,9 +43,7 @@ const getSchemaInfo = (path, property, subProperty) => {
let current = optionsSchema;
for (const segment of pathSegments) {
if (segment === "*") {
current =
findPropertyInSchema(current, "additionalProperties") ||
findPropertyInSchema(current, "items");
current = findPropertyInSchema(current, "additionalProperties") || findPropertyInSchema(current, "items");
} else {
current = findPropertyInSchema(current, "properties", segment);
}
Expand Down Expand Up @@ -87,8 +77,7 @@ module.exports = function(yargs) {
"config-register": {
type: "array",
alias: "r",
describe:
"Preload one or more modules before loading the webpack configuration",
describe: "Preload one or more modules before loading the webpack configuration",
group: CONFIG_GROUP,
defaultDescription: "module id or path",
requiresArg: true
Expand Down Expand Up @@ -165,8 +154,7 @@ module.exports = function(yargs) {
type: "string",
describe: getSchemaInfo("output.chunkFilename", "description"),
group: OUTPUT_GROUP,
defaultDescription:
"filename with [id] instead of [name] or [id] prefixed",
defaultDescription: "filename with [id] instead of [name] or [id] prefixed",
requiresArg: true
},
"output-source-map-filename": {
Expand Down Expand Up @@ -305,10 +293,7 @@ module.exports = function(yargs) {
requiresArg: true
},
"optimize-min-chunk-size": {
describe: getSchemaInfo(
"optimization.splitChunks.minSize",
"description"
),
describe: getSchemaInfo("optimization.splitChunks.minSize", "description"),
group: OPTIMIZE_GROUP,
requiresArg: true
},
Expand All @@ -325,8 +310,7 @@ module.exports = function(yargs) {
},
provide: {
type: "string",
describe:
"Provide these modules as free vars in all modules (Example: --provide jQuery=jquery)",
describe: "Provide these modules as free vars in all modules (Example: --provide jQuery=jquery)",
group: ADVANCED_GROUP,
requiresArg: true
},
Expand Down Expand Up @@ -355,14 +339,12 @@ module.exports = function(yargs) {
},
d: {
type: "boolean",
describe:
"shortcut for --debug --devtool eval-cheap-module-source-map --output-pathinfo",
describe: "shortcut for --debug --devtool eval-cheap-module-source-map --output-pathinfo",
group: BASIC_GROUP
},
p: {
type: "boolean",
describe:
"shortcut for --optimize-minimize --define process.env.NODE_ENV=\"production\"",
describe: "shortcut for --optimize-minimize --define process.env.NODE_ENV=\"production\"",
group: BASIC_GROUP
}
});
Expand Down

0 comments on commit ca1e4a3

Please sign in to comment.