Skip to content

Commit

Permalink
Add webpack benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnns committed Oct 24, 2017
1 parent c45d93c commit 89596fd
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 2 deletions.
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require("path");

module.exports = {
watchPathIgnorePatterns: [
path.resolve(__dirname, "build")
]
}
5 changes: 5 additions & 0 deletions src/fixtures/webpack/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import b from "./b.js";

const message = import("./c.js").then(c => c.default + b);

export default message;
1 change: 1 addition & 0 deletions src/fixtures/webpack/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 42;
1 change: 1 addition & 0 deletions src/fixtures/webpack/c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "Hello world";
3 changes: 3 additions & 0 deletions src/mocks/chokidar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
watch: () => {}
};
1 change: 1 addition & 0 deletions src/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
13 changes: 13 additions & 0 deletions src/vfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
37 changes: 37 additions & 0 deletions src/webpack-benchmark.js
Original file line number Diff line number Diff line change
@@ -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());
}
};
45 changes: 45 additions & 0 deletions src/webpack-benchmark.test.js
Original file line number Diff line number Diff line change
@@ -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 });
}));
10 changes: 8 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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: [
Expand Down

0 comments on commit 89596fd

Please sign in to comment.