mirror of https://github.com/webpack/webpack.git
Merge pull request #13405 from webpack/test/profiling-plugin-stability
improve stability of ProfilingPlugin test
This commit is contained in:
commit
1d2253fdab
|
@ -6,12 +6,13 @@ const webpack = require("../");
|
||||||
const rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
|
|
||||||
describe("Profiling Plugin", function () {
|
describe("Profiling Plugin", function () {
|
||||||
jest.setTimeout(30000);
|
jest.setTimeout(120000);
|
||||||
|
|
||||||
it("should handle output path with folder creation", done => {
|
it("should handle output path with folder creation", done => {
|
||||||
const outputPath = path.join(__dirname, "js/profilingPath");
|
const outputPath = path.join(__dirname, "js/profilingPath");
|
||||||
const finalPath = path.join(outputPath, "events.json");
|
const finalPath = path.join(outputPath, "events.json");
|
||||||
rimraf(outputPath, () => {
|
rimraf(outputPath, () => {
|
||||||
|
const startTime = process.hrtime();
|
||||||
const compiler = webpack({
|
const compiler = webpack({
|
||||||
context: __dirname,
|
context: __dirname,
|
||||||
entry: "./fixtures/a.js",
|
entry: "./fixtures/a.js",
|
||||||
|
@ -26,13 +27,16 @@ describe("Profiling Plugin", function () {
|
||||||
});
|
});
|
||||||
compiler.run(err => {
|
compiler.run(err => {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
const testDuration = process.hrtime(startTime);
|
||||||
if (!fs.existsSync(outputPath))
|
if (!fs.existsSync(outputPath))
|
||||||
return done(new Error("Folder should be created."));
|
return done(new Error("Folder should be created."));
|
||||||
const data = require(finalPath);
|
const data = require(finalPath);
|
||||||
const maxTs = data.reduce((max, entry) => Math.max(max, entry.ts), 0);
|
const maxTs = data.reduce((max, entry) => Math.max(max, entry.ts), 0);
|
||||||
const minTs = data[0].ts;
|
const minTs = data[0].ts;
|
||||||
const duration = maxTs - minTs;
|
const duration = maxTs - minTs;
|
||||||
expect(duration).toBeLessThan(10000 * 1000);
|
expect(duration).toBeLessThan(
|
||||||
|
testDuration[0] * 1000000 + testDuration[1] / 1000
|
||||||
|
);
|
||||||
const cpuProfile = data.find(entry => entry.name === "CpuProfile");
|
const cpuProfile = data.find(entry => entry.name === "CpuProfile");
|
||||||
expect(cpuProfile).toBeTypeOf("object");
|
expect(cpuProfile).toBeTypeOf("object");
|
||||||
const profile = cpuProfile.args.data.cpuProfile;
|
const profile = cpuProfile.args.data.cpuProfile;
|
||||||
|
|
Loading…
Reference in New Issue