diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 00000000..48d59bad --- /dev/null +++ b/jest.config.js @@ -0,0 +1,7 @@ +const path = require("path"); + +module.exports = { + watchPathIgnorePatterns: [ + path.resolve(__dirname, "build") + ] +} diff --git a/src/fixtures/webpack/a.js b/src/fixtures/webpack/a.js new file mode 100644 index 00000000..948e9f24 --- /dev/null +++ b/src/fixtures/webpack/a.js @@ -0,0 +1,5 @@ +import b from "./b.js"; + +const message = import("./c.js").then(c => c.default + b); + +export default message; diff --git a/src/fixtures/webpack/b.js b/src/fixtures/webpack/b.js new file mode 100644 index 00000000..888cae37 --- /dev/null +++ b/src/fixtures/webpack/b.js @@ -0,0 +1 @@ +module.exports = 42; diff --git a/src/fixtures/webpack/c.js b/src/fixtures/webpack/c.js new file mode 100644 index 00000000..64d245e2 --- /dev/null +++ b/src/fixtures/webpack/c.js @@ -0,0 +1 @@ +export default "Hello world"; diff --git a/src/mocks/chokidar/index.js b/src/mocks/chokidar/index.js new file mode 100644 index 00000000..39cdfdb8 --- /dev/null +++ b/src/mocks/chokidar/index.js @@ -0,0 +1,3 @@ +module.exports = { + watch: () => {} +}; diff --git a/src/suite.js b/src/suite.js index ab00cf28..d9c1a838 100644 --- a/src/suite.js +++ b/src/suite.js @@ -22,5 +22,6 @@ suite.add(require("./source-map-benchmark")); suite.add(require("./typescript-benchmark")); suite.add(require("./uglify-js-benchmark")); suite.add(require("./uglify-es-benchmark")); +suite.add(require("./webpack-benchmark")); module.exports = suite; diff --git a/src/vfs.js b/src/vfs.js index 14e26070..e5c3aec4 100644 --- a/src/vfs.js +++ b/src/vfs.js @@ -79,5 +79,18 @@ fs.writeFileSync( "third_party/vue.runtime.esm-nobuble-2.4.4.js", require("raw-loader!../third_party/vue.runtime.esm-nobuble-2.4.4.js") ); +fs.mkdirpSync("/src/fixtures/webpack"); +fs.writeFileSync( + "/src/fixtures/webpack/a.js", + require("raw-loader!./fixtures/webpack/a.js") +); +fs.writeFileSync( + "/src/fixtures/webpack/b.js", + require("raw-loader!./fixtures/webpack/b.js") +); +fs.writeFileSync( + "/src/fixtures/webpack/c.js", + require("raw-loader!./fixtures/webpack/c.js") +); module.exports = fs; diff --git a/src/webpack-benchmark.js b/src/webpack-benchmark.js new file mode 100644 index 00000000..65440d24 --- /dev/null +++ b/src/webpack-benchmark.js @@ -0,0 +1,37 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +const webpack = require("webpack"); + +const payloads = [ + { + entry: "/src/fixtures/webpack/a.js" + } +].map(({ entry }, i) => ({ + entry, + output: { + path: "/dist/webpack/", + filename: `bundle.${i}.js` + }, + // Using bail option in order to receive noisy errors in the benchmark if something went wrong + bail: true, + // We need to define that because Firefox has a Object.prototype.watch function + watch: false +})); + +module.exports = { + name: "webpack", + defer: true, + fn(deferred) { + return Promise.all( + payloads.map( + config => + new Promise((resolve, reject) => { + const compiler = webpack(config); + compiler.run((err, stats) => void (err ? reject(err) : resolve())); + }) + ) + ).then(() => deferred.resolve()); + } +}; diff --git a/src/webpack-benchmark.test.js b/src/webpack-benchmark.test.js new file mode 100644 index 00000000..8163446e --- /dev/null +++ b/src/webpack-benchmark.test.js @@ -0,0 +1,45 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +const path = require("path"); +const webpack = require("webpack"); +const webpackConfig = require("../webpack.config.js"); + +const outputFile = path.resolve( + __dirname, + "..", + "build", + "webpack-benchmark.test.js" +); +let webpackBenchmark; + +beforeAll( + () => + new Promise((resolve, reject) => { + const baseConfig = webpackConfig[0]; + const config = Object.assign({}, baseConfig, { + entry: require.resolve("./webpack-benchmark.js"), + bail: true + }); + config.output = Object.assign({}, baseConfig.output, { + libraryTarget: "commonjs2", + path: path.dirname(outputFile), + filename: path.basename(outputFile) + }); + const compiler = webpack(config); + compiler.run(err => { + if (err) { + reject(err); + return; + } + webpackBenchmark = require(outputFile); + resolve(); + }); + }) +); + +it("webpack runs to completion", () => + new Promise(resolve => { + webpackBenchmark.fn({ resolve }); + })); diff --git a/webpack.config.js b/webpack.config.js index 34996be1..0935bcbd 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -19,7 +19,10 @@ module.exports = [ resolve: { alias: { fs: require.resolve("./src/vfs"), - module: require.resolve("./src/mocks/dummy") + "graceful-fs": require.resolve("./src/vfs"), + module: require.resolve("./src/mocks/dummy"), + chokidar: require.resolve("./src/mocks/chokidar"), + "uglify-js": require.resolve("./src/mocks/dummy") } }, plugins: [ @@ -46,7 +49,10 @@ module.exports = [ alias: { define: require.resolve("./src/mocks/dummy"), fs: require.resolve("./src/vfs"), - module: require.resolve("./src/mocks/dummy") + "graceful-fs": require.resolve("./src/vfs"), + module: require.resolve("./src/mocks/dummy"), + chokidar: require.resolve("./src/mocks/chokidar"), + "uglify-js": require.resolve("./src/mocks/dummy") } }, plugins: [