mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-28 13:13:37 +08:00
[cleanup] Use default (empty) host configuration for unit tests.
Each unit test should properly configure `Root.Runtime.hostConfig` and not rely on some global defaults (for tests). Bug: 396033932 Change-Id: I6462a6e80a8c687e9fc1f8a652f5ecc7e350b50c Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6257768 Commit-Queue: Alex Rudenko <alexrudenko@chromium.org> Reviewed-by: Alex Rudenko <alexrudenko@chromium.org> Commit-Queue: Benedikt Meurer <bmeurer@chromium.org> Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
This commit is contained in:
committed by
Devtools-frontend LUCI CQ
parent
36d83565c2
commit
fc8f12f4cb
@@ -133,7 +133,7 @@ out/Default/chrome --enable-features="DevToolsNewFeature:string_param/foo/double
|
||||
|
||||
* Update the type definition in [`Runtime.ts`](https://crsrc.org/c/third_party/devtools-frontend/src/front_end/core/root/Runtime.ts).
|
||||
* Update the dummy value returned by `getHostConfig` in [`InspectorFrontendHost.ts`](https://crsrc.org/c/third_party/devtools-frontend/src/front_end/core/host/InspectorFrontendHost.ts).
|
||||
* For tests, update the `HOST_CONFIG` in [`EnvironmentHelpers.ts`](https://crsrc.org/c/third_party/devtools-frontend/src/front_end/testing/EnvironmentHelpers.ts).
|
||||
* Access the host config via `Root.Runtime.hostConfig`.
|
||||
* In unit tests, make sure to assign the expected configuration using `Object.assign(Root.Runtime.hostConfig, { foo: bar })`.
|
||||
|
||||
Please refer to this [example CL](https://crrev.com/c/5626314).
|
||||
|
||||
@@ -11,7 +11,11 @@ const TEST_MODEL_ID = 'testModelId';
|
||||
|
||||
describeWithEnvironment('AidaClient', () => {
|
||||
it('adds no model temperature if console insights is not enabled', () => {
|
||||
Object.assign(Root.Runtime.hostConfig, {});
|
||||
Object.assign(Root.Runtime.hostConfig, {
|
||||
aidaAvailability: {
|
||||
disallowLogging: false,
|
||||
},
|
||||
});
|
||||
const request = Host.AidaClient.AidaClient.buildConsoleInsightsRequest('foo');
|
||||
assert.deepEqual(request, {
|
||||
current_message: {parts: [{text: 'foo'}], role: Host.AidaClient.Role.USER},
|
||||
@@ -23,6 +27,9 @@ describeWithEnvironment('AidaClient', () => {
|
||||
|
||||
it('adds a model temperature', () => {
|
||||
Object.assign(Root.Runtime.hostConfig, {
|
||||
aidaAvailability: {
|
||||
disallowLogging: false,
|
||||
},
|
||||
devToolsConsoleInsights: {
|
||||
enabled: true,
|
||||
temperature: 0.5,
|
||||
@@ -42,6 +49,9 @@ describeWithEnvironment('AidaClient', () => {
|
||||
|
||||
it('adds a model temperature of 0', () => {
|
||||
Object.assign(Root.Runtime.hostConfig, {
|
||||
aidaAvailability: {
|
||||
disallowLogging: false,
|
||||
},
|
||||
devToolsConsoleInsights: {
|
||||
enabled: true,
|
||||
temperature: 0,
|
||||
@@ -61,6 +71,9 @@ describeWithEnvironment('AidaClient', () => {
|
||||
|
||||
it('ignores a negative model temperature', () => {
|
||||
Object.assign(Root.Runtime.hostConfig, {
|
||||
aidaAvailability: {
|
||||
disallowLogging: false,
|
||||
},
|
||||
devToolsConsoleInsights: {
|
||||
enabled: true,
|
||||
temperature: -1,
|
||||
@@ -77,6 +90,9 @@ describeWithEnvironment('AidaClient', () => {
|
||||
|
||||
it('adds a model id and temperature', () => {
|
||||
Object.assign(Root.Runtime.hostConfig, {
|
||||
aidaAvailability: {
|
||||
disallowLogging: false,
|
||||
},
|
||||
devToolsConsoleInsights: {
|
||||
enabled: true,
|
||||
modelId: TEST_MODEL_ID,
|
||||
|
||||
@@ -403,7 +403,7 @@ export class InspectorFrontendHostStub implements InspectorFrontendHostAPI {
|
||||
});
|
||||
}
|
||||
|
||||
getHostConfig(callback: (arg0: Root.Runtime.HostConfig) => void): void {
|
||||
getHostConfig(callback: (hostConfig: Root.Runtime.HostConfig) => void): void {
|
||||
const result: Root.Runtime.HostConfig = {
|
||||
aidaAvailability: {
|
||||
enabled: true,
|
||||
|
||||
@@ -191,7 +191,11 @@ describeWithEnvironment('ConsoleInsight', () => {
|
||||
});
|
||||
|
||||
const reportsRating = (positive: boolean) => async () => {
|
||||
Object.assign(Root.Runtime.hostConfig, {});
|
||||
Object.assign(Root.Runtime.hostConfig, {
|
||||
aidaAvailability: {
|
||||
disallowLogging: false,
|
||||
},
|
||||
});
|
||||
const actionTaken = sinon.stub(Host.userMetrics, 'actionTaken');
|
||||
const aidaClient = getTestAidaClient();
|
||||
component = new Explain.ConsoleInsight(
|
||||
|
||||
@@ -501,65 +501,9 @@ export function expectConsoleLogs(expectedLogs: {warn?: string[], log?: string[]
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The default host configuration used for unit tests.
|
||||
*/
|
||||
export const HOST_CONFIG: Readonly<Root.Runtime.HostConfig> = Object.freeze({
|
||||
aidaAvailability: {
|
||||
disallowLogging: false,
|
||||
enterprisePolicyValue: 0,
|
||||
},
|
||||
devToolsConsoleInsights: {
|
||||
enabled: false,
|
||||
modelId: '',
|
||||
temperature: -1,
|
||||
},
|
||||
devToolsFreestyler: {
|
||||
modelId: '',
|
||||
temperature: -1,
|
||||
enabled: false,
|
||||
},
|
||||
devToolsAiAssistanceNetworkAgent: {
|
||||
modelId: '',
|
||||
temperature: -1,
|
||||
enabled: false,
|
||||
},
|
||||
devToolsAiAssistanceFileAgent: {
|
||||
modelId: '',
|
||||
temperature: -1,
|
||||
enabled: false,
|
||||
},
|
||||
devToolsAiAssistancePerformanceAgent: {
|
||||
modelId: '',
|
||||
temperature: -1,
|
||||
enabled: false,
|
||||
insightsEnabled: false,
|
||||
},
|
||||
devToolsImprovedWorkspaces: {
|
||||
enabled: false,
|
||||
},
|
||||
devToolsVeLogging: {
|
||||
enabled: true,
|
||||
testing: false,
|
||||
},
|
||||
devToolsWellKnown: {
|
||||
enabled: false,
|
||||
},
|
||||
devToolsPrivacyUI: {
|
||||
enabled: false,
|
||||
},
|
||||
devToolsEnableOriginBoundCookies: {
|
||||
portBindingEnabled: false,
|
||||
schemeBindingEnabled: false,
|
||||
},
|
||||
devToolsAnimationStylesInStylesTab: {
|
||||
enabled: false,
|
||||
},
|
||||
isOffTheRecord: false,
|
||||
thirdPartyCookieControls: {
|
||||
thirdPartyCookieRestrictionEnabled: false,
|
||||
thirdPartyCookieMetadataEnabled: true,
|
||||
thirdPartyCookieHeuristicsEnabled: true,
|
||||
managedBlockThirdPartyCookies: 'Unset',
|
||||
},
|
||||
});
|
||||
export function resetHostConfig() {
|
||||
for (const key of Object.keys(Root.Runtime.hostConfig)) {
|
||||
// @ts-expect-error
|
||||
delete Root.Runtime.hostConfig[key];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ 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, HOST_CONFIG} from './EnvironmentHelpers.js';
|
||||
import {createFakeSetting, resetHostConfig} from './EnvironmentHelpers.js';
|
||||
import {
|
||||
checkForPendingActivity,
|
||||
startTrackingAsyncActivity,
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
} from './TrackAsyncOperations.js';
|
||||
|
||||
beforeEach(async () => {
|
||||
Object.assign(Root.Runtime.hostConfig, HOST_CONFIG);
|
||||
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)) {
|
||||
@@ -51,6 +51,7 @@ afterEach(async () => {
|
||||
}
|
||||
await cleanTestDOM();
|
||||
await checkForPendingActivity();
|
||||
resetHostConfig();
|
||||
sinon.restore();
|
||||
stopTrackingAsyncActivity();
|
||||
// Clear out any Sinon stubs or spies between individual tests.
|
||||
|
||||
Reference in New Issue
Block a user