mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-28 21:24:26 +08:00
This CL adds a custom browser wrapper that starts the browser using Puppeteer instead of letting Karma to directly start the browser. The wrapper also exposes a binding that allows the test code to capture a screenshot of the test DOM. The helper reuses existing screenshot assertions and reports the result back to the test code. This CL also adds args to improve stability of screenshots and fixes the font to be a Roboto font loaded from Google Fonts. To test: `npm run test -- front_end/panels/ai_assistance/components/UserActionRow.test.ts` Bug: 401489541 Change-Id: I04889d0f0caa5c468fd35f98c66b0e6ac393de18 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6330749 Auto-Submit: Alex Rudenko <alexrudenko@chromium.org> Commit-Queue: Danil Somsikov <dsv@chromium.org> Reviewed-by: Danil Somsikov <dsv@chromium.org>
65 lines
2.4 KiB
TypeScript
65 lines
2.4 KiB
TypeScript
// Copyright 2020 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
/*
|
|
* This file is automatically loaded and run by Karma because it automatically
|
|
* loads and injects all *.js files it finds.
|
|
*/
|
|
|
|
import * as Common from '../core/common/common.js';
|
|
import * as Host from '../core/host/host.js';
|
|
import * as Root from '../core/root/root.js';
|
|
import * as Trace from '../models/trace/trace.js';
|
|
import * as Timeline from '../panels/timeline/timeline.js';
|
|
import * as ThemeSupport from '../ui/legacy/theme_support/theme_support.js';
|
|
|
|
import {cleanTestDOM, setupTestDOM} from './DOMHelpers.js';
|
|
import {createFakeSetting, resetHostConfig} from './EnvironmentHelpers.js';
|
|
import {
|
|
checkForPendingActivity,
|
|
startTrackingAsyncActivity,
|
|
stopTrackingAsyncActivity,
|
|
} from './TrackAsyncOperations.js';
|
|
|
|
const style = document.createElement('style');
|
|
style.innerText =
|
|
'@import url(\'https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100..900;1,100..900&display=swap\');';
|
|
document.head.append(style);
|
|
document.documentElement.classList.add('platform-screenshot-test');
|
|
|
|
beforeEach(async () => {
|
|
resetHostConfig();
|
|
await setupTestDOM();
|
|
// Ensure that no trace data leaks between tests when testing the trace engine.
|
|
for (const handler of Object.values(Trace.Handlers.ModelHandlers)) {
|
|
handler.reset();
|
|
}
|
|
Trace.Helpers.SyntheticEvents.SyntheticEventsManager.reset();
|
|
Timeline.Utils.SourceMapsResolver.SourceMapsResolver.clearResolvedNodeNames();
|
|
|
|
// Don't retain host binding listeners across tests. Set this up before initializing ThemeSupport as
|
|
// ThemeSupport adds a host binding listener.
|
|
Host.InspectorFrontendHost.InspectorFrontendHostInstance.events = new Common.ObjectWrapper.ObjectWrapper();
|
|
|
|
// Some unit tests exercise code that assumes a ThemeSupport instance is available.
|
|
// Run this in a beforeEach in case an individual test overrides it.
|
|
const setting = createFakeSetting('theme', 'default');
|
|
ThemeSupport.ThemeSupport.instance({forceNew: true, setting});
|
|
|
|
startTrackingAsyncActivity();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
for (const key of Object.keys(Root.Runtime.hostConfig)) {
|
|
// @ts-expect-error
|
|
delete Root.Runtime.hostConfig[key];
|
|
}
|
|
await cleanTestDOM();
|
|
await checkForPendingActivity();
|
|
resetHostConfig();
|
|
sinon.restore();
|
|
stopTrackingAsyncActivity();
|
|
// Clear out any Sinon stubs or spies between individual tests.
|
|
});
|