-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
/
ProfilingPlugin.test.js
54 lines (50 loc) · 1.58 KB
/
ProfilingPlugin.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use strict";
require("./helpers/warmup-webpack");
const path = require("path");
const fs = require("graceful-fs");
const rimraf = require("rimraf");
describe("Profiling Plugin", function () {
jest.setTimeout(120000);
it("should handle output path with folder creation", done => {
const webpack = require("../");
const outputPath = path.join(__dirname, "js/profilingPath");
const finalPath = path.join(outputPath, "events.json");
rimraf(outputPath, () => {
const startTime = process.hrtime();
const compiler = webpack({
context: __dirname,
entry: "./fixtures/a.js",
output: {
path: path.join(__dirname, "js/profilingOut")
},
plugins: [
new webpack.debug.ProfilingPlugin({
outputPath: finalPath
})
],
experiments: {
backCompat: false
}
});
compiler.run(err => {
if (err) return done(err);
const testDuration = process.hrtime(startTime);
if (!fs.existsSync(outputPath))
return done(new Error("Folder should be created."));
const data = require(finalPath);
const maxTs = data.reduce((max, entry) => Math.max(max, entry.ts), 0);
const minTs = data[0].ts;
const duration = maxTs - minTs;
expect(duration).toBeLessThan(
testDuration[0] * 1000000 + testDuration[1] / 1000
);
const cpuProfile = data.find(entry => entry.name === "CpuProfile");
expect(cpuProfile).toBeTypeOf("object");
const profile = cpuProfile.args.data.cpuProfile;
expect(profile.startTime).toBeGreaterThanOrEqual(minTs);
expect(profile.endTime).toBeLessThanOrEqual(maxTs);
done();
});
});
});
});