From 75a9a515fd676378b50b1d74f5cd2f38bf2e2bd7 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Mon, 18 Feb 2019 09:09:46 +0100 Subject: [PATCH] fix prettierignore file and run prettier --- .prettierignore | 4 +- test/BenchmarkTestCases.benchmark.js | 104 +++--- test/Compiler.test.js | 4 +- ...eMapDevToolModuleOptionsPlugin.unittest.js | 18 +- test/Stats.unittest.js | 332 +++++++++--------- .../webpack.config.js | 4 +- .../optimization/minimizer/webpack.config.js | 8 +- .../split-chunks-max-size/webpack.config.js | 2 +- .../plugins/define-plugin/webpack.config.js | 9 +- 9 files changed, 236 insertions(+), 249 deletions(-) diff --git a/.prettierignore b/.prettierignore index bdf38e4bc..7ca974bc4 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,8 +1,8 @@ # Ignore test fixtures -test +test/*.* !test/*.js !test/**/webpack.config.js # Ignore example fixtures -examples +examples/*.* !examples/**/webpack.config.js diff --git a/test/BenchmarkTestCases.benchmark.js b/test/BenchmarkTestCases.benchmark.js index 5ed590548..9a78a2260 100644 --- a/test/BenchmarkTestCases.benchmark.js +++ b/test/BenchmarkTestCases.benchmark.js @@ -279,63 +279,57 @@ describe("BenchmarkTestCases", function() { describe(`${testName} create benchmarks`, function() { baselines.forEach(baseline => { let baselineStats = null; - it( - `should benchmark ${baseline.name} (${baseline.rev})`, - function(done) { - const outputDirectory = path.join( - __dirname, - "js", - "benchmark", - `baseline-${baseline.name}`, - testName - ); - const config = - Object.create( - require.requireActual( - path.join(testDirectory, "webpack.config.js") - ) - ) || {}; - config.output = Object.create(config.output || {}); - if (!config.context) config.context = testDirectory; - if (!config.output.path) config.output.path = outputDirectory; - runBenchmark(baseline.webpack, config, (err, stats) => { - if (err) return done(err); - process.stderr.write(` ${baseline.name} ${stats.text}`); - if (baseline.name === "HEAD") headStats = stats; - else baselineStats = stats; - done(); - }); - }, - 180000 - ); - - it( - `should benchmark ${baseline.name} (${baseline.rev})`, - done => { - const outputDirectory = path.join( - __dirname, - "js", - "benchmark", - `baseline-${baseline.name}`, - testName - ); - const config = + it(`should benchmark ${baseline.name} (${ + baseline.rev + })`, function(done) { + const outputDirectory = path.join( + __dirname, + "js", + "benchmark", + `baseline-${baseline.name}`, + testName + ); + const config = + Object.create( require.requireActual( path.join(testDirectory, "webpack.config.js") - ) || {}; - config.output = config.output || {}; - if (!config.context) config.context = testDirectory; - if (!config.output.path) config.output.path = outputDirectory; - runBenchmark(baseline.webpack, config, (err, stats) => { - if (err) return done(err); - process.stderr.write(` ${baseline.name} ${stats.text}`); - if (baseline.name === "HEAD") headStats = stats; - else baselineStats = stats; - done(); - }); - }, - 180000 - ); + ) + ) || {}; + config.output = Object.create(config.output || {}); + if (!config.context) config.context = testDirectory; + if (!config.output.path) config.output.path = outputDirectory; + runBenchmark(baseline.webpack, config, (err, stats) => { + if (err) return done(err); + process.stderr.write(` ${baseline.name} ${stats.text}`); + if (baseline.name === "HEAD") headStats = stats; + else baselineStats = stats; + done(); + }); + }, 180000); + + it(`should benchmark ${baseline.name} (${baseline.rev})`, done => { + const outputDirectory = path.join( + __dirname, + "js", + "benchmark", + `baseline-${baseline.name}`, + testName + ); + const config = + require.requireActual( + path.join(testDirectory, "webpack.config.js") + ) || {}; + config.output = config.output || {}; + if (!config.context) config.context = testDirectory; + if (!config.output.path) config.output.path = outputDirectory; + runBenchmark(baseline.webpack, config, (err, stats) => { + if (err) return done(err); + process.stderr.write(` ${baseline.name} ${stats.text}`); + if (baseline.name === "HEAD") headStats = stats; + else baselineStats = stats; + done(); + }); + }, 180000); if (baseline.name !== "HEAD") { it(`HEAD should not be slower than ${baseline.name} (${ diff --git a/test/Compiler.test.js b/test/Compiler.test.js index e0f501459..c241c9c08 100644 --- a/test/Compiler.test.js +++ b/test/Compiler.test.js @@ -503,9 +503,9 @@ describe("Compiler", () => { output: { path: "/", filename: "bundle.js" - }, + } }); - compiler.hooks.failed.tap('CompilerTest', failedSpy); + compiler.hooks.failed.tap("CompilerTest", failedSpy); compiler.outputFileSystem = new MemoryFs(); compiler.run((err, stats) => { expect(err).toBeTruthy(); diff --git a/test/SourceMapDevToolModuleOptionsPlugin.unittest.js b/test/SourceMapDevToolModuleOptionsPlugin.unittest.js index dd348267b..43d2584e7 100644 --- a/test/SourceMapDevToolModuleOptionsPlugin.unittest.js +++ b/test/SourceMapDevToolModuleOptionsPlugin.unittest.js @@ -58,14 +58,16 @@ describe("SourceMapDevToolModuleOptionsPlugin", () => { }); describe("with line-to-line true", () => { - beforeEach(() => - (eventBindings = applyPluginWithOptions( - SourceMapDevToolModuleOptionsPlugin, - { - module: false, - lineToLine: true - } - ))); + beforeEach( + () => + (eventBindings = applyPluginWithOptions( + SourceMapDevToolModuleOptionsPlugin, + { + module: false, + lineToLine: true + } + )) + ); it("binds one event handler", () => { expect(eventBindings.length).toBe(1); diff --git a/test/Stats.unittest.js b/test/Stats.unittest.js index 9ee873f16..8e75cd60e 100644 --- a/test/Stats.unittest.js +++ b/test/Stats.unittest.js @@ -4,11 +4,28 @@ const Stats = require("../lib/Stats"); const packageJson = require("../package.json"); -describe( - "Stats", - () => { - describe("formatFilePath", () => { - it("emit the file path and request", () => { +describe("Stats", () => { + describe("formatFilePath", () => { + it("emit the file path and request", () => { + const mockStats = new Stats({ + children: [], + errors: ["firstError"], + hash: "1234", + compiler: { + context: "" + } + }); + const inputPath = + "./node_modules/ts-loader!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/app.vue"; + const expectPath = `./src/app.vue (${inputPath})`; + + expect(mockStats.formatFilePath(inputPath)).toBe(expectPath); + }); + }); + + describe("Error Handling", () => { + describe("does have", () => { + it("hasErrors", () => { const mockStats = new Stats({ children: [], errors: ["firstError"], @@ -17,193 +34,172 @@ describe( context: "" } }); - const inputPath = - "./node_modules/ts-loader!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/app.vue"; - const expectPath = `./src/app.vue (${inputPath})`; - - expect(mockStats.formatFilePath(inputPath)).toBe(expectPath); + expect(mockStats.hasErrors()).toBe(true); }); - }); - - describe("Error Handling", () => { - describe("does have", () => { - it("hasErrors", () => { - const mockStats = new Stats({ - children: [], - errors: ["firstError"], - hash: "1234", - compiler: { - context: "" - } - }); - expect(mockStats.hasErrors()).toBe(true); - }); - it("hasWarnings", () => { - const mockStats = new Stats({ - children: [], - warnings: ["firstError"], - hash: "1234", - compiler: { - context: "" - } - }); - expect(mockStats.hasWarnings()).toBe(true); - }); - }); - describe("does not have", () => { - it("hasErrors", () => { - const mockStats = new Stats({ - children: [], - errors: [], - hash: "1234", - compiler: { - context: "" - } - }); - expect(mockStats.hasErrors()).toBe(false); - }); - it("hasWarnings", () => { - const mockStats = new Stats({ - children: [], - warnings: [], - hash: "1234", - compiler: { - context: "" - } - }); - expect(mockStats.hasWarnings()).toBe(false); - }); - }); - describe("children have", () => { - it("hasErrors", () => { - const mockStats = new Stats({ - children: [ - { - getStats: () => - new Stats({ - errors: ["firstError"], - hash: "5678" - }) - } - ], - errors: [], - hash: "1234" - }); - expect(mockStats.hasErrors()).toBe(true); - }); - it("hasWarnings", () => { - const mockStats = new Stats({ - children: [ - { - getStats: () => - new Stats({ - warnings: ["firstError"], - hash: "5678" - }) - } - ], - warnings: [], - hash: "1234" - }); - expect(mockStats.hasWarnings()).toBe(true); - }); - }); - it("formatError handles string errors", () => { + it("hasWarnings", () => { const mockStats = new Stats({ - errors: ["firstError"], - warnings: [], - assets: [], - entrypoints: new Map(), - namedChunkGroups: new Map(), - chunks: [], - modules: [], children: [], + warnings: ["firstError"], hash: "1234", - mainTemplate: { - outputOptions: { - path: "" - }, - getPublicPath: () => "path" - }, compiler: { context: "" } }); - const obj = mockStats.toJson(); - expect(obj.errors[0]).toEqual("firstError"); + expect(mockStats.hasWarnings()).toBe(true); }); }); - describe("toJson", () => { - it("returns plain object representation", () => { + describe("does not have", () => { + it("hasErrors", () => { const mockStats = new Stats({ - errors: [], - warnings: [], - assets: [], - entrypoints: new Map(), - chunks: [], - namedChunkGroups: new Map(), - modules: [], children: [], + errors: [], hash: "1234", - mainTemplate: { - outputOptions: { - path: "/" - }, - getPublicPath: () => "path" - }, compiler: { context: "" } }); - const result = mockStats.toJson(); - expect(result).toEqual({ - assets: [], - assetsByChunkName: {}, + expect(mockStats.hasErrors()).toBe(false); + }); + it("hasWarnings", () => { + const mockStats = new Stats({ children: [], - chunks: [], - entrypoints: {}, - namedChunkGroups: {}, - filteredAssets: 0, - filteredModules: 0, - errors: [], + warnings: [], hash: "1234", - modules: [], - outputPath: "/", - publicPath: "path", - version: packageJson.version, - warnings: [] + compiler: { + context: "" + } }); + expect(mockStats.hasWarnings()).toBe(false); }); }); - describe("Presets", () => { - describe("presetToOptions", () => { - it("returns correct object with 'Normal'", () => { - expect(Stats.presetToOptions("Normal")).toEqual({}); + describe("children have", () => { + it("hasErrors", () => { + const mockStats = new Stats({ + children: [ + { + getStats: () => + new Stats({ + errors: ["firstError"], + hash: "5678" + }) + } + ], + errors: [], + hash: "1234" }); - it("truthy values behave as 'normal'", () => { - const normalOpts = Stats.presetToOptions("normal"); - expect(Stats.presetToOptions("pizza")).toEqual(normalOpts); - expect(Stats.presetToOptions(true)).toEqual(normalOpts); - expect(Stats.presetToOptions(1)).toEqual(normalOpts); + expect(mockStats.hasErrors()).toBe(true); + }); + it("hasWarnings", () => { + const mockStats = new Stats({ + children: [ + { + getStats: () => + new Stats({ + warnings: ["firstError"], + hash: "5678" + }) + } + ], + warnings: [], + hash: "1234" + }); + expect(mockStats.hasWarnings()).toBe(true); + }); + }); + it("formatError handles string errors", () => { + const mockStats = new Stats({ + errors: ["firstError"], + warnings: [], + assets: [], + entrypoints: new Map(), + namedChunkGroups: new Map(), + chunks: [], + modules: [], + children: [], + hash: "1234", + mainTemplate: { + outputOptions: { + path: "" + }, + getPublicPath: () => "path" + }, + compiler: { + context: "" + } + }); + const obj = mockStats.toJson(); + expect(obj.errors[0]).toEqual("firstError"); + }); + }); + describe("toJson", () => { + it("returns plain object representation", () => { + const mockStats = new Stats({ + errors: [], + warnings: [], + assets: [], + entrypoints: new Map(), + chunks: [], + namedChunkGroups: new Map(), + modules: [], + children: [], + hash: "1234", + mainTemplate: { + outputOptions: { + path: "/" + }, + getPublicPath: () => "path" + }, + compiler: { + context: "" + } + }); + const result = mockStats.toJson(); + expect(result).toEqual({ + assets: [], + assetsByChunkName: {}, + children: [], + chunks: [], + entrypoints: {}, + namedChunkGroups: {}, + filteredAssets: 0, + filteredModules: 0, + errors: [], + hash: "1234", + modules: [], + outputPath: "/", + publicPath: "path", + version: packageJson.version, + warnings: [] + }); + }); + }); + describe("Presets", () => { + describe("presetToOptions", () => { + it("returns correct object with 'Normal'", () => { + expect(Stats.presetToOptions("Normal")).toEqual({}); + }); + it("truthy values behave as 'normal'", () => { + const normalOpts = Stats.presetToOptions("normal"); + expect(Stats.presetToOptions("pizza")).toEqual(normalOpts); + expect(Stats.presetToOptions(true)).toEqual(normalOpts); + expect(Stats.presetToOptions(1)).toEqual(normalOpts); - expect(Stats.presetToOptions("verbose")).not.toEqual(normalOpts); - expect(Stats.presetToOptions(false)).not.toEqual(normalOpts); - }); - it("returns correct object with 'none'", () => { - expect(Stats.presetToOptions("none")).toEqual({ - all: false - }); - }); - it("falsy values behave as 'none'", () => { - const noneOpts = Stats.presetToOptions("none"); - expect(Stats.presetToOptions("")).toEqual(noneOpts); - expect(Stats.presetToOptions(null)).toEqual(noneOpts); - expect(Stats.presetToOptions()).toEqual(noneOpts); - expect(Stats.presetToOptions(0)).toEqual(noneOpts); - expect(Stats.presetToOptions(false)).toEqual(noneOpts); + expect(Stats.presetToOptions("verbose")).not.toEqual(normalOpts); + expect(Stats.presetToOptions(false)).not.toEqual(normalOpts); + }); + it("returns correct object with 'none'", () => { + expect(Stats.presetToOptions("none")).toEqual({ + all: false }); }); + it("falsy values behave as 'none'", () => { + const noneOpts = Stats.presetToOptions("none"); + expect(Stats.presetToOptions("")).toEqual(noneOpts); + expect(Stats.presetToOptions(null)).toEqual(noneOpts); + expect(Stats.presetToOptions()).toEqual(noneOpts); + expect(Stats.presetToOptions(0)).toEqual(noneOpts); + expect(Stats.presetToOptions(false)).toEqual(noneOpts); + }); }); - }, - 10000 -); + }); +}, 10000); diff --git a/test/configCases/errors/multi-entry-missing-module/webpack.config.js b/test/configCases/errors/multi-entry-missing-module/webpack.config.js index 7060c77c5..165e6592e 100644 --- a/test/configCases/errors/multi-entry-missing-module/webpack.config.js +++ b/test/configCases/errors/multi-entry-missing-module/webpack.config.js @@ -7,9 +7,7 @@ module.exports = { output: { filename: "[name].js" }, - plugins: [ - new IgnorePlugin(/intentionally-missing-module/) - ], + plugins: [new IgnorePlugin(/intentionally-missing-module/)], node: { __dirname: false } diff --git a/test/configCases/optimization/minimizer/webpack.config.js b/test/configCases/optimization/minimizer/webpack.config.js index 0df441570..b969d497e 100644 --- a/test/configCases/optimization/minimizer/webpack.config.js +++ b/test/configCases/optimization/minimizer/webpack.config.js @@ -1,4 +1,4 @@ -const Compiler = require('../../../../lib/Compiler'); +const Compiler = require("../../../../lib/Compiler"); module.exports = { optimization: { @@ -7,12 +7,12 @@ module.exports = { { apply(compiler) { expect(compiler).toBeInstanceOf(Compiler); - }, + } }, function(compiler) { expect(compiler).toBe(this); expect(compiler).toBeInstanceOf(Compiler); } - ], - }, + ] + } }; diff --git a/test/statsCases/split-chunks-max-size/webpack.config.js b/test/statsCases/split-chunks-max-size/webpack.config.js index 3c68b0d53..cc25996f0 100644 --- a/test/statsCases/split-chunks-max-size/webpack.config.js +++ b/test/statsCases/split-chunks-max-size/webpack.config.js @@ -103,5 +103,5 @@ module.exports = [ } }, stats - }, + } ]; diff --git a/test/watchCases/plugins/define-plugin/webpack.config.js b/test/watchCases/plugins/define-plugin/webpack.config.js index 31a075ce7..ffca20082 100644 --- a/test/watchCases/plugins/define-plugin/webpack.config.js +++ b/test/watchCases/plugins/define-plugin/webpack.config.js @@ -8,12 +8,9 @@ const valueFile = path.resolve( module.exports = { plugins: [ new webpack.DefinePlugin({ - TEST_VALUE: webpack.DefinePlugin.runtimeValue( - () => { - return JSON.stringify(fs.readFileSync(valueFile, "utf-8").trim()); - }, - [valueFile] - ), + TEST_VALUE: webpack.DefinePlugin.runtimeValue(() => { + return JSON.stringify(fs.readFileSync(valueFile, "utf-8").trim()); + }, [valueFile]), TEST_VALUE2: webpack.DefinePlugin.runtimeValue(() => { return JSON.stringify(fs.readFileSync(valueFile, "utf-8").trim()); }, []),