/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
test/ProfilingPlugin.unittest.js
135 строк
4 KB
Alexander Akait
fix(css,html): correct two printer defects a real-browser equivalence check found (#21608)
05 авг 2026, 03:12
Не верифицирован
05 авг 2026, 03:12
a0d975f
Код
Авторство
О чём код?
"use strict"; const path = require("path"); const fs = require("graceful-fs"); const rimraf = require("rimraf"); const ProfilingPlugin = require("../lib/debug/ProfilingPlugin"); const launchChrome = require("./helpers/launchChrome"); describe("Profiling Plugin", () => { it("should persist the passed output path", () => { const outputPath = path.join(__dirname, "invest_in_doge_coin"); const plugin = new ProfilingPlugin({ outputPath }); expect(plugin.options.outputPath).toBe(outputPath); }); it("should handle no options", () => { expect(() => { // eslint-disable-next-line no-new new ProfilingPlugin(); }).not.toThrow(); }); it("should handle when unable to require the inspector", () => { // @ts-expect-error intentionally calling without required argument const profiler = new ProfilingPlugin.Profiler(); return profiler.startProfiling(); }); it("should handle when unable to start a profiling session", () => { const profiler = new ProfilingPlugin.Profiler( /** @type {EXPECTED_ANY} */ ({ Session() { throw new Error("Sean Larkin was here."); } }) ); return profiler.startProfiling(); }); it("handles sending a profiling message when no session", () => { // @ts-expect-error intentionally calling without required argument const profiler = new ProfilingPlugin.Profiler(); return profiler.sendCommand( "randy", /** @type {EXPECTED_OBJECT} */ (/** @type {unknown} */ ("is awesome")) ); }); it("handles destroying when no session", () => { // @ts-expect-error intentionally calling without required argument const profiler = new ProfilingPlugin.Profiler(); return profiler.destroy(); }); }); /** * @typedef {{ frame: string, parent?: string }} TraceFrame * @typedef {{ name: string, args: { data: { frames: TraceFrame[] } } }} TraceEvent */ describe("ProfilingPlugin in real Chrome", () => { /** @type {import("puppeteer-core").Browser} */ let browser; beforeAll(async () => { browser = await launchChrome(); }, 120000); afterAll(async () => { if (browser) await browser.close(); }); it("should generate a trace Chrome DevTools can load (#17234)", (done) => { // Narrowed handle so the type survives into the callbacks below. const activeBrowser = browser; const webpack = require(".."); const outputPath = path.join(__dirname, "js/profiling-chrome"); const eventsPath = path.join(outputPath, "events.json"); rimraf(outputPath, () => { const compiler = webpack({ context: __dirname, entry: "./fixtures/a.js", output: { path: path.join(outputPath, "dist") }, plugins: [new webpack.debug.ProfilingPlugin({ outputPath: eventsPath })] }); compiler.run(async (err) => { if (err) return done(err); try { /** @type {TraceEvent[]} */ const events = JSON.parse(fs.readFileSync(eventsPath, "utf8")); const page = await activeBrowser.newPage(); // Run Chrome DevTools' trace bootstrap (MetaHandler) in the real // browser: iterate the TracingStartedInBrowser frames and pick the // parent-less main frame. A missing `frames` array threw // "frames is not iterable" and the whole trace failed to load. const result = await page.evaluate( (/** @type {TraceEvent[]} */ evs) => { const event = evs.find( (e) => e && e.name === "TracingStartedInBrowser" ); if (!event) return { ok: false, threw: null, mainFrame: null }; /** @type {string | null} */ let threw = null; /** @type {string | null} */ let mainFrame = null; try { for (const frame of event.args.data.frames) { if (!frame.parent) mainFrame = frame.frame; } } catch (err_) { threw = err_ instanceof Error ? err_.message : String(err_); } return { ok: threw === null, threw, mainFrame }; }, events ); await page.close(); expect(result.threw).toBeNull(); expect(result.ok).toBe(true); expect(typeof result.mainFrame).toBe("string"); done(); } catch (err_) { done(err_); } }); }); }, 120000); });