From 7bd9a33c67c8a60e934e6bff0a24c13c701d4dd2 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Tue, 2 Jan 2018 16:16:09 +0100 Subject: [PATCH] fix(coverage): fix coverage for binCases (#231) fix prettier for bin and test fix lint for windows users improve reporting for CI --- .appveyor.yml | 6 +- .editorconfig | 3 + .gitignore | 1 + .travis.yml | 6 +- bin/webpack.js | 773 +++++++++++++++--------------- package.json | 39 +- test/BinTestCases.test.js | 59 +-- test/helpers/exec-in-directory.js | 8 + yarn.lock | 158 +++++- 9 files changed, 617 insertions(+), 436 deletions(-) create mode 100644 test/helpers/exec-in-directory.js diff --git a/.appveyor.yml b/.appveyor.yml index d57f1ff93ab..5998a2864f4 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -21,9 +21,9 @@ test_script: - npm --version - yarn --version - which yarn - - yarn prepare - - yarn lint - - yarn test:ci + - yarn appveyor:prepare + - yarn appveyor:lint + - yarn appveyor:test cache: - node_modules -> appveyor.yml,package.json,yarn.lock diff --git a/.editorconfig b/.editorconfig index e3fc128fcf4..b6030406bfb 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,9 @@ trim_trailing_whitespace = true insert_final_newline = true max_line_length = 233 +[*.js] +end_of_line = lf + [*.json] indent_style = space indent_size = 2 diff --git a/.gitignore b/.gitignore index 5719464f341..0473786d680 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ yarn-error.log # Jest Coverage /coverage +/.nyc_output # Distribution Build dist diff --git a/.travis.yml b/.travis.yml index 40161397885..ee12df39133 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,5 @@ before_script: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start -after_success: - - bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" - -script: npm run travis:$JOB_PART +script: + - npm run travis:$JOB_PART diff --git a/bin/webpack.js b/bin/webpack.js index a9b3a1b0874..8f335f964a2 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -4,446 +4,449 @@ MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ -require("v8-compile-cache"); -var resolveCwd = require("resolve-cwd"); -// Local version replace global one -var localCLI = resolveCwd.silent("webpack-cli/bin/webpack"); -var ErrorHelpers = require("webpack/lib/ErrorHelpers"); -const NON_COMPILATION_ARGS = [ - "init", - "migrate", - "add", - /* - "remove", - "update", - "make", - */ - "serve", - "generate-loader", - "generate-plugin" -]; - -const NON_COMPILATION_CMD = process.argv.find(arg => { - if (arg === "serve") { - global.process.argv = global.process.argv.filter(a => a !== "serve"); - process.argv = global.process.argv; - } - return NON_COMPILATION_ARGS.find(a => a === arg); -}); - -if (NON_COMPILATION_CMD) { - // eslint-disable-next-line - return require("../dist/index")(NON_COMPILATION_CMD, process.argv); -} - -if (localCLI && localCLI !== __filename) { - try { - return require(localCLI); - } catch (err) { - console.error(`\n ${err.message}`); - process.exit(1); - } -} - -var yargs = require("yargs").usage( - "webpack-cli " + - require("../package.json").version + - "\n" + - "Usage: https://webpack.js.org/api/cli/\n" + - "Usage without config file: webpack [] --output [-o] \n" + - "Usage with config file: webpack" -); - -require("./config-yargs")(yargs); - -var DISPLAY_GROUP = "Stats options:"; -var BASIC_GROUP = "Basic options:"; - -yargs.options({ - json: { - type: "boolean", - alias: "j", - describe: "Prints the result as JSON." - }, - progress: { - type: "boolean", - describe: "Print compilation progress in percentage", - group: BASIC_GROUP - }, - color: { - type: "boolean", - alias: "colors", - default: function supportsColor() { - return require("supports-color"); - }, - group: DISPLAY_GROUP, - describe: "Enables/Disables colors on the console" - }, - "sort-modules-by": { - type: "string", - group: DISPLAY_GROUP, - describe: "Sorts the modules list by property in module" - }, - "sort-chunks-by": { - type: "string", - group: DISPLAY_GROUP, - describe: "Sorts the chunks list by property in chunk" - }, - "sort-assets-by": { - type: "string", - group: DISPLAY_GROUP, - describe: "Sorts the assets list by property in asset" - }, - "hide-modules": { - type: "boolean", - group: DISPLAY_GROUP, - describe: "Hides info about modules" - }, - "display-exclude": { - type: "string", - group: DISPLAY_GROUP, - describe: "Exclude modules in the output" - }, - "display-modules": { - type: "boolean", - group: DISPLAY_GROUP, - describe: "Display even excluded modules in the output" - }, - "display-max-modules": { - type: "number", - group: DISPLAY_GROUP, - describe: "Sets the maximum number of visible modules in output" - }, - "display-chunks": { - type: "boolean", - group: DISPLAY_GROUP, - describe: "Display chunks in the output" - }, - "display-entrypoints": { - type: "boolean", - group: DISPLAY_GROUP, - describe: "Display entry points in the output" - }, - "display-origins": { - type: "boolean", - group: DISPLAY_GROUP, - describe: "Display origins of chunks in the output" - }, - "display-cached": { - type: "boolean", - group: DISPLAY_GROUP, - describe: "Display also cached modules in the output" - }, - "display-cached-assets": { - type: "boolean", - group: DISPLAY_GROUP, - describe: "Display also cached assets in the output" - }, - "display-reasons": { - type: "boolean", - group: DISPLAY_GROUP, - describe: "Display reasons about module inclusion in the output" - }, - "display-depth": { - type: "boolean", - group: DISPLAY_GROUP, - describe: "Display distance from entry point for each module" - }, - "display-used-exports": { - type: "boolean", - group: DISPLAY_GROUP, - describe: "Display information about used exports in modules (Tree Shaking)" - }, - "display-provided-exports": { - type: "boolean", - group: DISPLAY_GROUP, - describe: "Display information about exports provided from modules" - }, - "display-optimization-bailout": { - type: "boolean", - group: DISPLAY_GROUP, - describe: - "Display information about why optimization bailed out for modules" - }, - "display-error-details": { - type: "boolean", - group: DISPLAY_GROUP, - describe: "Display details about errors" - }, - display: { - type: "string", - group: DISPLAY_GROUP, - describe: - "Select display preset (verbose, detailed, normal, minimal, errors-only, none)" - }, - verbose: { - type: "boolean", - group: DISPLAY_GROUP, - describe: "Show more details" - } -}); - -// yargs will terminate the process early when the user uses help or version. -// This causes large help outputs to be cut short (https://github.com/nodejs/node/wiki/API-changes-between-v0.10-and-v4#process). -// To prevent this we use the yargs.parse API and exit the process normally -yargs.parse(process.argv.slice(2), (err, argv, output) => { - Error.stackTraceLimit = 30; - - // arguments validation failed - if (err && output) { - console.error(output); - process.exitCode = 1; - return; - } - // help or version info - if (output) { - console.log(output); - return; - } +(function() { + // wrap in IIFE to be able to use return - if (argv.verbose) { - argv["display"] = "verbose"; + var resolveCwd = require("resolve-cwd"); + // Local version replace global one + var localCLI = resolveCwd.silent("webpack-cli/bin/webpack"); + if (localCLI && localCLI !== __filename) { + require(localCLI); + return; } - try { - var options = require("./convert-argv")(yargs, argv); - } catch (err) { - if (err.name !== "ValidationError") { - throw err; - } - - var stack = ErrorHelpers.cleanUpWebpackOptions(err.stack, err.message); - var message = err.message + "\n" + stack; - - if (argv.color) { - console.error(`\u001b[1m\u001b[31m${message}\u001b[39m\u001b[22m`); - } else { - console.error(message); + require("v8-compile-cache"); + var ErrorHelpers = require("webpack/lib/ErrorHelpers"); + + const NON_COMPILATION_ARGS = [ + "init", + "migrate", + "add", + /* + "remove", + "update", + "make", + */ + "serve", + "generate-loader", + "generate-plugin" + ]; + + const NON_COMPILATION_CMD = process.argv.find(arg => { + if (arg === "serve") { + global.process.argv = global.process.argv.filter(a => a !== "serve"); + process.argv = global.process.argv; } + return NON_COMPILATION_ARGS.find(a => a === arg); + }); - process.exitCode = 1; + if (NON_COMPILATION_CMD) { + // eslint-disable-next-line + require("../dist/index")(NON_COMPILATION_CMD, process.argv); return; } - function ifArg(name, fn, init) { - if (Array.isArray(argv[name])) { - if (init) init(); - argv[name].forEach(fn); - } else if (typeof argv[name] !== "undefined") { - if (init) init(); - fn(argv[name], -1); + var yargs = require("yargs").usage( + "webpack-cli " + + require("../package.json").version + + "\n" + + "Usage: https://webpack.js.org/api/cli/\n" + + "Usage without config file: webpack [] --output [-o] \n" + + "Usage with config file: webpack" + ); + + require("./config-yargs")(yargs); + + var DISPLAY_GROUP = "Stats options:"; + var BASIC_GROUP = "Basic options:"; + + yargs.options({ + json: { + type: "boolean", + alias: "j", + describe: "Prints the result as JSON." + }, + progress: { + type: "boolean", + describe: "Print compilation progress in percentage", + group: BASIC_GROUP + }, + color: { + type: "boolean", + alias: "colors", + default: function supportsColor() { + return require("supports-color"); + }, + group: DISPLAY_GROUP, + describe: "Enables/Disables colors on the console" + }, + "sort-modules-by": { + type: "string", + group: DISPLAY_GROUP, + describe: "Sorts the modules list by property in module" + }, + "sort-chunks-by": { + type: "string", + group: DISPLAY_GROUP, + describe: "Sorts the chunks list by property in chunk" + }, + "sort-assets-by": { + type: "string", + group: DISPLAY_GROUP, + describe: "Sorts the assets list by property in asset" + }, + "hide-modules": { + type: "boolean", + group: DISPLAY_GROUP, + describe: "Hides info about modules" + }, + "display-exclude": { + type: "string", + group: DISPLAY_GROUP, + describe: "Exclude modules in the output" + }, + "display-modules": { + type: "boolean", + group: DISPLAY_GROUP, + describe: "Display even excluded modules in the output" + }, + "display-max-modules": { + type: "number", + group: DISPLAY_GROUP, + describe: "Sets the maximum number of visible modules in output" + }, + "display-chunks": { + type: "boolean", + group: DISPLAY_GROUP, + describe: "Display chunks in the output" + }, + "display-entrypoints": { + type: "boolean", + group: DISPLAY_GROUP, + describe: "Display entry points in the output" + }, + "display-origins": { + type: "boolean", + group: DISPLAY_GROUP, + describe: "Display origins of chunks in the output" + }, + "display-cached": { + type: "boolean", + group: DISPLAY_GROUP, + describe: "Display also cached modules in the output" + }, + "display-cached-assets": { + type: "boolean", + group: DISPLAY_GROUP, + describe: "Display also cached assets in the output" + }, + "display-reasons": { + type: "boolean", + group: DISPLAY_GROUP, + describe: "Display reasons about module inclusion in the output" + }, + "display-depth": { + type: "boolean", + group: DISPLAY_GROUP, + describe: "Display distance from entry point for each module" + }, + "display-used-exports": { + type: "boolean", + group: DISPLAY_GROUP, + describe: "Display information about used exports in modules (Tree Shaking)" + }, + "display-provided-exports": { + type: "boolean", + group: DISPLAY_GROUP, + describe: "Display information about exports provided from modules" + }, + "display-optimization-bailout": { + type: "boolean", + group: DISPLAY_GROUP, + describe: + "Display information about why optimization bailed out for modules" + }, + "display-error-details": { + type: "boolean", + group: DISPLAY_GROUP, + describe: "Display details about errors" + }, + display: { + type: "string", + group: DISPLAY_GROUP, + describe: + "Select display preset (verbose, detailed, normal, minimal, errors-only, none)" + }, + verbose: { + type: "boolean", + group: DISPLAY_GROUP, + describe: "Show more details" } - } - - function processOptions(options) { - // process Promise - if (typeof options.then === "function") { - options.then(processOptions).catch(function(err) { - console.error(err.stack || err); - process.exit(1); // eslint-disable-line - }); + }); + + // yargs will terminate the process early when the user uses help or version. + // This causes large help outputs to be cut short (https://github.com/nodejs/node/wiki/API-changes-between-v0.10-and-v4#process). + // To prevent this we use the yargs.parse API and exit the process normally + yargs.parse(process.argv.slice(2), (err, argv, output) => { + Error.stackTraceLimit = 30; + + // arguments validation failed + if (err && output) { + console.error(output); + process.exitCode = 1; return; } - var firstOptions = [].concat(options)[0]; - var statsPresetToOptions = require("webpack/lib/Stats.js").presetToOptions; - - var outputOptions = options.stats; - if ( - typeof outputOptions === "boolean" || - typeof outputOptions === "string" - ) { - outputOptions = statsPresetToOptions(outputOptions); - } else if (!outputOptions) { - outputOptions = {}; + // help or version info + if (output) { + console.log(output); + return; } - ifArg("display", function(preset) { - outputOptions = statsPresetToOptions(preset); - }); - - outputOptions = Object.create(outputOptions); - if (Array.isArray(options) && !outputOptions.children) { - outputOptions.children = options.map(o => o.stats); + if (argv.verbose) { + argv["display"] = "verbose"; } - if (typeof outputOptions.context === "undefined") - outputOptions.context = firstOptions.context; - ifArg("env", function(value) { - if (outputOptions.env) { - outputOptions._env = value; + try { + var options = require("./convert-argv")(yargs, argv); + } catch (err) { + if (err.name !== "ValidationError") { + throw err; } - }); - ifArg("json", function(bool) { - if (bool) outputOptions.json = bool; - }); + var stack = ErrorHelpers.cleanUpWebpackOptions(err.stack, err.message); + var message = err.message + "\n" + stack; - if (typeof outputOptions.colors === "undefined") - outputOptions.colors = require("supports-color"); + if (argv.color) { + console.error(`\u001b[1m\u001b[31m${message}\u001b[39m\u001b[22m`); + } else { + console.error(message); + } - ifArg("sort-modules-by", function(value) { - outputOptions.modulesSort = value; - }); + process.exitCode = 1; + return; + } - ifArg("sort-chunks-by", function(value) { - outputOptions.chunksSort = value; - }); + function ifArg(name, fn, init) { + if (Array.isArray(argv[name])) { + if (init) init(); + argv[name].forEach(fn); + } else if (typeof argv[name] !== "undefined") { + if (init) init(); + fn(argv[name], -1); + } + } - ifArg("sort-assets-by", function(value) { - outputOptions.assetsSort = value; - }); + function processOptions(options) { + // process Promise + if (typeof options.then === "function") { + options.then(processOptions).catch(function(err) { + console.error(err.stack || err); + process.exit(1); // eslint-disable-line + }); + return; + } - ifArg("display-exclude", function(value) { - outputOptions.exclude = value; - }); + var firstOptions = [].concat(options)[0]; + var statsPresetToOptions = require("webpack/lib/Stats.js").presetToOptions; + + var outputOptions = options.stats; + if ( + typeof outputOptions === "boolean" || + typeof outputOptions === "string" + ) { + outputOptions = statsPresetToOptions(outputOptions); + } else if (!outputOptions) { + outputOptions = {}; + } - if (!outputOptions.json) { - if (typeof outputOptions.cached === "undefined") - outputOptions.cached = false; - if (typeof outputOptions.cachedAssets === "undefined") - outputOptions.cachedAssets = false; + ifArg("display", function(preset) { + outputOptions = statsPresetToOptions(preset); + }); - ifArg("display-chunks", function(bool) { - if (bool) { - outputOptions.modules = false; - outputOptions.chunks = true; - outputOptions.chunkModules = true; + outputOptions = Object.create(outputOptions); + if (Array.isArray(options) && !outputOptions.children) { + outputOptions.children = options.map(o => o.stats); + } + if (typeof outputOptions.context === "undefined") + outputOptions.context = firstOptions.context; + + ifArg("env", function(value) { + if (outputOptions.env) { + outputOptions._env = value; } }); - ifArg("display-entrypoints", function(bool) { - if (bool) outputOptions.entrypoints = true; + ifArg("json", function(bool) { + if (bool) outputOptions.json = bool; }); - ifArg("display-reasons", function(bool) { - if (bool) outputOptions.reasons = true; - }); + if (typeof outputOptions.colors === "undefined") + outputOptions.colors = require("supports-color"); - ifArg("display-depth", function(bool) { - if (bool) outputOptions.depth = true; + ifArg("sort-modules-by", function(value) { + outputOptions.modulesSort = value; }); - ifArg("display-used-exports", function(bool) { - if (bool) outputOptions.usedExports = true; + ifArg("sort-chunks-by", function(value) { + outputOptions.chunksSort = value; }); - ifArg("display-provided-exports", function(bool) { - if (bool) outputOptions.providedExports = true; + ifArg("sort-assets-by", function(value) { + outputOptions.assetsSort = value; }); - ifArg("display-optimization-bailout", function(bool) { - if (bool) outputOptions.optimizationBailout = bool; + ifArg("display-exclude", function(value) { + outputOptions.exclude = value; }); - ifArg("display-error-details", function(bool) { - if (bool) outputOptions.errorDetails = true; - }); + if (!outputOptions.json) { + if (typeof outputOptions.cached === "undefined") + outputOptions.cached = false; + if (typeof outputOptions.cachedAssets === "undefined") + outputOptions.cachedAssets = false; + + ifArg("display-chunks", function(bool) { + if (bool) { + outputOptions.modules = false; + outputOptions.chunks = true; + outputOptions.chunkModules = true; + } + }); - ifArg("display-origins", function(bool) { - if (bool) outputOptions.chunkOrigins = true; - }); + ifArg("display-entrypoints", function(bool) { + if (bool) outputOptions.entrypoints = true; + }); - ifArg("display-max-modules", function(value) { - outputOptions.maxModules = +value; - }); + ifArg("display-reasons", function(bool) { + if (bool) outputOptions.reasons = true; + }); - ifArg("display-cached", function(bool) { - if (bool) outputOptions.cached = true; - }); + ifArg("display-depth", function(bool) { + if (bool) outputOptions.depth = true; + }); - ifArg("display-cached-assets", function(bool) { - if (bool) outputOptions.cachedAssets = true; - }); + ifArg("display-used-exports", function(bool) { + if (bool) outputOptions.usedExports = true; + }); - if (!outputOptions.exclude) - outputOptions.exclude = [ - "node_modules", - "bower_components", - "components" - ]; - - if (argv["display-modules"]) { - outputOptions.maxModules = Infinity; - outputOptions.exclude = undefined; - outputOptions.modules = true; - } - } + ifArg("display-provided-exports", function(bool) { + if (bool) outputOptions.providedExports = true; + }); - ifArg("hide-modules", function(bool) { - if (bool) { - outputOptions.modules = false; - outputOptions.chunkModules = false; - } - }); + ifArg("display-optimization-bailout", function(bool) { + if (bool) outputOptions.optimizationBailout = bool; + }); - var webpack = require("webpack/lib/webpack.js"); + ifArg("display-error-details", function(bool) { + if (bool) outputOptions.errorDetails = true; + }); - var lastHash = null; - var compiler; - try { - compiler = webpack(options); - } catch (err) { - if (err.name === "WebpackOptionsValidationError") { - 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); - } + ifArg("display-origins", function(bool) { + if (bool) outputOptions.chunkOrigins = true; + }); - throw err; - } + ifArg("display-max-modules", function(value) { + outputOptions.maxModules = +value; + }); - if (argv.progress) { - var ProgressPlugin = require("webpack/lib/ProgressPlugin"); - compiler.apply( - new ProgressPlugin({ - profile: argv.profile - }) - ); - } + ifArg("display-cached", function(bool) { + if (bool) outputOptions.cached = true; + }); - function compilerCallback(err, stats) { - if (!options.watch || err) { - // Do not keep cache anymore - compiler.purgeInputFileSystem(); + ifArg("display-cached-assets", function(bool) { + if (bool) outputOptions.cachedAssets = true; + }); + + if (!outputOptions.exclude) + outputOptions.exclude = [ + "node_modules", + "bower_components", + "components" + ]; + + if (argv["display-modules"]) { + outputOptions.maxModules = Infinity; + outputOptions.exclude = undefined; + outputOptions.modules = true; + } } - if (err) { - lastHash = null; - console.error(err.stack || err); - if (err.details) console.error(err.details); - process.exit(1); // eslint-disable-line + + ifArg("hide-modules", function(bool) { + if (bool) { + outputOptions.modules = false; + outputOptions.chunkModules = false; + } + }); + + var webpack = require("webpack/lib/webpack.js"); + + var lastHash = null; + var compiler; + try { + compiler = webpack(options); + } catch (err) { + if (err.name === "WebpackOptionsValidationError") { + 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); + } + + throw err; } - if (outputOptions.json) { - process.stdout.write( - JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n" + + if (argv.progress) { + var ProgressPlugin = require("webpack/lib/ProgressPlugin"); + compiler.apply( + new ProgressPlugin({ + profile: argv.profile + }) ); - } else if (stats.hash !== lastHash) { - lastHash = stats.hash; - var statsString = stats.toString(outputOptions); - if (statsString) process.stdout.write(statsString + "\n"); } - if (!options.watch && stats.hasErrors()) { - process.exitCode = 2; + + function compilerCallback(err, stats) { + if (!options.watch || err) { + // Do not keep cache anymore + compiler.purgeInputFileSystem(); + } + if (err) { + lastHash = null; + console.error(err.stack || err); + if (err.details) console.error(err.details); + process.exit(1); // eslint-disable-line + } + if (outputOptions.json) { + process.stdout.write( + JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n" + ); + } else if (stats.hash !== lastHash) { + lastHash = stats.hash; + var statsString = stats.toString(outputOptions); + if (statsString) process.stdout.write(statsString + "\n"); + } + if (!options.watch && stats.hasErrors()) { + process.exitCode = 2; + } } + if (firstOptions.watch || options.watch) { + var 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); + console.log("\nWebpack is watching the files…\n"); + } else compiler.run(compilerCallback); } - if (firstOptions.watch || options.watch) { - var 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); - console.log("\nWebpack is watching the files…\n"); - } else compiler.run(compilerCallback); - } - processOptions(options); -}); + processOptions(options); + }); +})(); diff --git a/package.json b/package.json index 6fc21b505ff..0aa5f581ce0 100644 --- a/package.json +++ b/package.json @@ -16,18 +16,21 @@ "node": ">=6.11.5" }, "scripts": { - "lint": "./node_modules/eslint/bin/eslint.js \"**/*.js\"", - "format": "prettier-eslint \"bin/**/**/*.js\" --write && prettier-eslint \"lib/**/**/*.js\" --write && prettier-eslint \"test/**/**/*.js\" --write", - "format:dist": "prettier-eslint \"dist/**/**/*.js\" --write", + "lint": "eslint \"**/*.js\"", + "format": "prettier-eslint \"bin/**/*.js\" \"lib/**/*.js\" \"test/**/*.js\" --write", + "format:dist": "prettier-eslint \"dist/**/*.js\" --write", "lint:codeOnly": "eslint \"{lib,bin}/**/!(__testfixtures__)/*.js\" \"{lib,bin}/**.js\"", "precommit": "lint-staged", "prepare": "flow-remove-types lib/ -d dist/ && yarn format:dist", "pretest": "yarn lint", - "test": "jest", - "test:ci": "jest --ci && codecov -f coverage/coverage-final.json", + "test": "nyc jest", + "reportCoverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json --disable=gcov", "jsdoc": "jsdoc -c jsdoc.json -r -d docs", - "travis:integration": "yarn prepare && yarn test:ci", - "travis:lint": "yarn prepare && yarn lint" + "appveyor:prepare": "yarn prepare", + "appveyor:lint": "yarn lint", + "appveyor:test": "nyc jest && yarn reportCoverage", + "travis:integration": "yarn prepare && nyc jest && yarn reportCoverage", + "travis:lint": "yarn lint" }, "lint-staged": { "{lib,bin}/**/!(__testfixtures__)/**.js": [ @@ -40,8 +43,23 @@ "modulePathIgnorePatterns": [ "dist" ], - "coverageDirectory": "./coverage/", - "collectCoverage": true + "collectCoverage": true, + "coverageReporters": [ + "none" + ] + }, + "nyc": { + "exclude": [ + "**/__testfixtures__/**" + ], + "include": [ + "lib/**.js", + "bin/**.js" + ], + "reporter": [ + "lcov" + ], + "all": true }, "dependencies": { "babel-code-frame": "^6.22.0", @@ -49,10 +67,12 @@ "babel-preset-env": "^1.6.1", "babel-preset-stage-3": "^6.24.1", "chalk": "^2.0.1", + "codecov": "^3.0.0", "cross-spawn": "^5.1.0", "diff": "^3.3.0", "enhanced-resolve": "^3.4.1", "glob-all": "^3.1.0", + "global": "^4.3.2", "global-modules": "^1.0.0", "got": "^7.1.0", "inquirer": "^3.2.0", @@ -91,6 +111,7 @@ "jest-cli": "^21.2.1", "jsdoc": "^3.5.5", "lint-staged": "^4.1.3", + "nyc": "^11.4.1", "prettier-eslint-cli": "^4.6.1", "schema-utils": "^0.4.2", "webpack": "^4.0.0-alpha.1", diff --git a/test/BinTestCases.test.js b/test/BinTestCases.test.js index 9b44b5fc9d9..a7b2c1d5242 100644 --- a/test/BinTestCases.test.js +++ b/test/BinTestCases.test.js @@ -6,30 +6,21 @@ const fs = require("fs"); const child_process = require("child_process"); function spawn(args, options) { - if (process.env.running_under_istanbul) { - args = [ - "--no-deprecation", - require.resolve("istanbul/lib/cli.js"), - "cover", - "--report", - "none", - "--print", + return child_process.spawn( + process.execPath, + [ + require.resolve("nyc/bin/nyc.js"), + "--reporter", "none", - "--include-pid", - "--dir", - path.resolve("coverage"), - "--", - require.resolve("webpack/test/helpers/exec-in-directory.js"), + "--no-all", + process.execPath, + "--no-deprecation", + require.resolve("./helpers/exec-in-directory.js"), options.cwd - ].concat(args); - options = Object.assign({}, options, { + ].concat(args), + Object.assign({}, options, { cwd: undefined - }); - } - return child_process.spawn( - process.execPath, - ["--no-deprecation"].concat(args), - options + }) ); } @@ -87,10 +78,10 @@ describe("BinTestCases", function() { testName ); - const cmd = `${path.resolve(process.cwd(), "bin/webpack.js")}`; + const cmd = `${path.resolve(__dirname, "../bin/webpack.js")}`; const args = testArgs.concat(["--output-path", `${outputPath}`]); const opts = { - cwd: path.resolve("./", testDirectory) + cwd: testDirectory }; const asyncExists = fs.existsSync(path.join(testDirectory, "async")); @@ -104,7 +95,7 @@ describe("BinTestCases", function() { if (asyncExists) { describe(testName, function() { it("should run successfully", function(done) { - jest.setTimeout(10000); + jest.setTimeout(20000); const child = spawn([cmd].concat(args), opts); child.on("close", code => { @@ -130,15 +121,21 @@ describe("BinTestCases", function() { const stdout = convertToArrayOfLines(env.stdout); const stderr = convertToArrayOfLines(env.stderr); - testAssertions(stdout, stderr, done); + try { + testAssertions(stdout, stderr, done); + } catch(e) { + console.log(`### stderr ###\n${env.stderr.join("")}`); + console.log(`### stdout ###\n${env.stdout.join("")}`); + throw e; + } child.kill(); }, 8000); // wait a little to get an output }); }); } else { describe(testName, function() { - beforeEach(function(done) { - jest.setTimeout(20000); + beforeAll(function(done) { + jest.setTimeout(30000); const child = spawn([cmd].concat(args), opts); @@ -167,7 +164,13 @@ describe("BinTestCases", function() { it("should run successfully", function() { const stdout = convertToArrayOfLines(env.stdout); const stderr = convertToArrayOfLines(env.stderr); - testAssertions(env.code, stdout, stderr); + try { + testAssertions(env.code, stdout, stderr); + } catch(e) { + console.log(`### stderr ###\n${env.stderr.join("")}`); + console.log(`### stdout ###\n${env.stdout.join("")}`); + throw e; + } }); }); } diff --git a/test/helpers/exec-in-directory.js b/test/helpers/exec-in-directory.js new file mode 100644 index 00000000000..f487768b120 --- /dev/null +++ b/test/helpers/exec-in-directory.js @@ -0,0 +1,8 @@ +"use strict"; + +const dir = process.argv[2]; +const bin = process.argv[3]; +process.argv.splice(1, 2); +process.chdir(dir); + +require(bin); diff --git a/yarn.lock b/yarn.lock index c2db846edf5..bbe9aa64662 100644 --- a/yarn.lock +++ b/yarn.lock @@ -134,6 +134,10 @@ aproba@^1.0.3, aproba@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a" +archy@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/archy/-/archy-1.0.0.tgz#f9c8c13757cc1dd7bc379ac77b2c62a5c2868c40" + are-we-there-yet@~1.1.2: version "1.1.4" resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-1.1.4.tgz#bb5dca382bb94f05e15194373d16fd3ba1ca110d" @@ -147,6 +151,10 @@ argparse@^1.0.7: dependencies: sprintf-js "~1.0.2" +argv@0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/argv/-/argv-0.0.2.tgz#ecbd16f8949b157183711b1bda334f37840185ab" + arr-diff@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-2.0.0.tgz#8f3b827f955a8bd669697e4a4256ac3ceae356cf" @@ -1205,6 +1213,14 @@ cacache@^10.0.0: unique-filename "^1.1.0" y18n "^3.2.1" +caching-transform@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/caching-transform/-/caching-transform-1.0.1.tgz#6dbdb2f20f8d8fbce79f3e94e9d1742dcdf5c0a1" + dependencies: + md5-hex "^1.2.0" + mkdirp "^0.5.1" + write-file-atomic "^1.1.4" + caller-path@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-0.1.0.tgz#94085ef63581ecd3daa92444a8fe94e82577751f" @@ -1420,6 +1436,14 @@ code-point-at@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" +codecov@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/codecov/-/codecov-3.0.0.tgz#c273b8c4f12945723e8dc9d25803d89343e5f28e" + dependencies: + argv "0.0.2" + request "2.81.0" + urlgrey "0.4.4" + color-convert@^1.9.0: version "1.9.1" resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.1.tgz#c1261107aeb2f294ebffec9ed9ecad529a6097ed" @@ -1518,7 +1542,7 @@ content-type@~1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b" -convert-source-map@^1.4.0, convert-source-map@^1.5.0: +convert-source-map@^1.3.0, convert-source-map@^1.4.0, convert-source-map@^1.5.0: version "1.5.1" resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.5.1.tgz#b8278097b9bc229365de5c62cf5fcaed8b5599e5" @@ -1589,6 +1613,13 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4: safe-buffer "^5.0.1" sha.js "^2.4.8" +cross-spawn@^4: + version "4.0.2" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-4.0.2.tgz#7b9247621c23adfdd3856004a823cbe397424d41" + dependencies: + lru-cache "^4.0.1" + which "^1.2.9" + cross-spawn@^5.0.1, cross-spawn@^5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449" @@ -1667,6 +1698,10 @@ dateformat@^2.0.0: version "2.2.0" resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-2.2.0.tgz#4065e2013cf9fb916ddfd82efb506ad4c6769062" +debug-log@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/debug-log/-/debug-log-1.0.1.tgz#2307632d4c04382b8df8a32f70b895046d52745f" + debug@2.6.9, debug@^2.0.0, debug@^2.1.0, debug@^2.2.0, debug@^2.6.6, debug@^2.6.8: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -1821,6 +1856,10 @@ doctrine@^2.0.2: dependencies: esutils "^2.0.2" +dom-walk@^0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.1.tgz#672226dc74c8f799ad35307df936aba11acd6018" + domain-browser@^1.1.1: version "1.1.7" resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.1.7.tgz#867aa4b093faa05f1de08c06f4d7b21fdf8698bc" @@ -2299,6 +2338,14 @@ finalhandler@1.1.0: statuses "~1.3.1" unpipe "~1.0.0" +find-cache-dir@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-0.1.1.tgz#c8defae57c8a52a8a784f9e31c57c742e993a0b9" + dependencies: + commondir "^1.0.1" + mkdirp "^0.5.1" + pkg-dir "^1.0.0" + find-cache-dir@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-1.0.0.tgz#9288e3e9e3cc3748717d39eade17cf71fc30ee6f" @@ -2371,6 +2418,13 @@ foreach@^2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99" +foreground-child@^1.5.3, foreground-child@^1.5.6: + version "1.5.6" + resolved "https://registry.yarnpkg.com/foreground-child/-/foreground-child-1.5.6.tgz#4fd71ad2dfde96789b980a5c0a295937cb2f5ce9" + dependencies: + cross-spawn "^4" + signal-exit "^3.0.0" + forever-agent@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" @@ -2537,7 +2591,7 @@ glob@^6.0.1: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2: +glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.1, glob@^7.1.2: version "7.1.2" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" dependencies: @@ -2577,6 +2631,13 @@ global-prefix@^1.0.1: is-windows "^1.0.1" which "^1.2.14" +global@^4.3.2: + version "4.3.2" + resolved "https://registry.yarnpkg.com/global/-/global-4.3.2.tgz#e76989268a6c74c38908b1305b10fc0e394e9d0f" + dependencies: + min-document "^2.19.0" + process "~0.5.1" + globals@^11.0.1: version "11.1.0" resolved "https://registry.yarnpkg.com/globals/-/globals-11.1.0.tgz#632644457f5f0e3ae711807183700ebf2e4633e4" @@ -3897,6 +3958,16 @@ marked@~0.3.6: version "0.3.7" resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.7.tgz#80ef3bbf1bd00d1c9cfebe42ba1b8c85da258d0d" +md5-hex@^1.2.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/md5-hex/-/md5-hex-1.3.0.tgz#d2c4afe983c4370662179b8cad145219135046c4" + dependencies: + md5-o-matic "^0.1.1" + +md5-o-matic@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/md5-o-matic/-/md5-o-matic-0.1.1.tgz#822bccd65e117c514fab176b25945d54100a03c3" + md5.js@^1.3.4: version "1.3.4" resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.4.tgz#e9bdbde94a20a5ac18b04340fc5764d5b09d901d" @@ -3963,6 +4034,12 @@ merge-descriptors@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61" +merge-source-map@^1.0.2: + version "1.1.0" + resolved "https://registry.yarnpkg.com/merge-source-map/-/merge-source-map-1.1.0.tgz#2fdde7e6020939f70906a68f2d7ae685e4c8c646" + dependencies: + source-map "^0.6.1" + merge@^1.1.3: version "1.2.0" resolved "https://registry.yarnpkg.com/merge/-/merge-1.2.0.tgz#7531e39d4949c281a66b8c5a6e0265e8b05894da" @@ -4036,6 +4113,12 @@ mimic-response@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-1.0.0.tgz#df3d3652a73fded6b9b0b24146e6fd052353458e" +min-document@^2.19.0: + version "2.19.0" + resolved "https://registry.yarnpkg.com/min-document/-/min-document-2.19.0.tgz#7bd282e3f5842ed295bb748cdd9f1ffa2c824685" + dependencies: + dom-walk "^0.1.0" + minimalistic-assert@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.0.tgz#702be2dda6b37f4836bcb3f5db56641b64a1d3d3" @@ -4279,6 +4362,38 @@ number-is-nan@^1.0.0: version "1.4.3" resolved "https://registry.yarnpkg.com/nwmatcher/-/nwmatcher-1.4.3.tgz#64348e3b3d80f035b40ac11563d278f8b72db89c" +nyc@^11.4.1: + version "11.4.1" + resolved "https://registry.yarnpkg.com/nyc/-/nyc-11.4.1.tgz#13fdf7e7ef22d027c61d174758f6978a68f4f5e5" + dependencies: + archy "^1.0.0" + arrify "^1.0.1" + caching-transform "^1.0.0" + convert-source-map "^1.3.0" + debug-log "^1.0.1" + default-require-extensions "^1.0.0" + find-cache-dir "^0.1.1" + find-up "^2.1.0" + foreground-child "^1.5.3" + glob "^7.0.6" + istanbul-lib-coverage "^1.1.1" + istanbul-lib-hook "^1.1.0" + istanbul-lib-instrument "^1.9.1" + istanbul-lib-report "^1.1.2" + istanbul-lib-source-maps "^1.2.2" + istanbul-reports "^1.1.3" + md5-hex "^1.2.0" + merge-source-map "^1.0.2" + micromatch "^2.3.11" + mkdirp "^0.5.0" + resolve-from "^2.0.0" + rimraf "^2.5.4" + signal-exit "^3.0.1" + spawn-wrap "^1.4.2" + test-exclude "^4.1.1" + yargs "^10.0.3" + yargs-parser "^8.0.0" + oauth-sign@~0.8.1, oauth-sign@~0.8.2: version "0.8.2" resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43" @@ -4587,6 +4702,12 @@ pinkie@^2.0.0: version "2.0.4" resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870" +pkg-dir@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-1.0.0.tgz#7a4b508a8d5bb2d629d447056ff4e9c9314cf3d4" + dependencies: + find-up "^1.0.0" + pkg-dir@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-2.0.0.tgz#f6d5d1109e19d63edf428e0bd57e12777615334b" @@ -4683,6 +4804,10 @@ process@^0.11.10: version "0.11.10" resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182" +process@~0.5.1: + version "0.5.2" + resolved "https://registry.yarnpkg.com/process/-/process-0.5.2.tgz#1638d8a8e34c2f440a91db95ab9aeb677fc185cf" + progress@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.0.tgz#8a1be366bf8fc23db2bd23f10c6fe920b4389d1f" @@ -5077,6 +5202,10 @@ resolve-from@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226" +resolve-from@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-2.0.0.tgz#9480ab20e94ffa1d9e80a804c7ea147611966b57" + resolve-from@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748" @@ -5111,7 +5240,7 @@ right-align@^0.1.1: dependencies: align-text "^0.1.1" -rimraf@2, rimraf@^2.2.0, rimraf@^2.2.8, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1: +rimraf@2, rimraf@^2.2.0, rimraf@^2.2.8, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2: version "2.6.2" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36" dependencies: @@ -5309,7 +5438,7 @@ shellwords@^0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" -signal-exit@^3.0.0, signal-exit@^3.0.2: +signal-exit@^3.0.0, signal-exit@^3.0.1, signal-exit@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" @@ -5392,6 +5521,17 @@ spawn-sync@^1.0.15: concat-stream "^1.4.7" os-shim "^0.1.2" +spawn-wrap@^1.4.2: + version "1.4.2" + resolved "https://registry.yarnpkg.com/spawn-wrap/-/spawn-wrap-1.4.2.tgz#cff58e73a8224617b6561abdc32586ea0c82248c" + dependencies: + foreground-child "^1.5.6" + mkdirp "^0.5.0" + os-homedir "^1.0.1" + rimraf "^2.6.2" + signal-exit "^3.0.2" + which "^1.3.0" + spdx-correct@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-1.0.2.tgz#4b3073d933ff51f3912f03ac5519498a4150db40" @@ -5906,6 +6046,10 @@ url@^0.11.0: punycode "1.3.2" querystring "0.2.0" +urlgrey@0.4.4: + version "0.4.4" + resolved "https://registry.yarnpkg.com/urlgrey/-/urlgrey-0.4.4.tgz#892fe95960805e85519f1cd4389f2cb4cbb7652f" + user-home@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/user-home/-/user-home-1.1.1.tgz#2b5be23a32b63a7c9deb8d0f28d485724a3df190" @@ -6146,7 +6290,7 @@ which-module@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a" -which@^1.2.10, which@^1.2.12, which@^1.2.14, which@^1.2.9: +which@^1.2.10, which@^1.2.12, which@^1.2.14, which@^1.2.9, which@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/which/-/which-1.3.0.tgz#ff04bdfc010ee547d780bec38e1ac1c2777d253a" dependencies: @@ -6192,7 +6336,7 @@ wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" -write-file-atomic@^1.2.0: +write-file-atomic@^1.1.4, write-file-atomic@^1.2.0: version "1.3.4" resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-1.3.4.tgz#f807a4f0b1d9e913ae7a48112e6cc3af1991b45f" dependencies: @@ -6252,7 +6396,7 @@ yargs-parser@^8.0.0: dependencies: camelcase "^4.1.0" -yargs@10.0.3: +yargs@10.0.3, yargs@^10.0.3: version "10.0.3" resolved "https://registry.yarnpkg.com/yargs/-/yargs-10.0.3.tgz#6542debd9080ad517ec5048fb454efe9e4d4aaae" dependencies: