Files
react-native-devtools-frontend/front_end/models/workspace_diff/WorkspaceDiff.test.ts
T
Benedikt Meurer 39e5133b95 [test] Introduce Platform.DevToolsPath.urlString helper.
This adds a helper function to avoid sprinkling casts to
`Platform.DevToolsPath.UrlString` all over our unit test
suite, combined with an ESLint rule to enforce that we
use this helper consistently.

This leads to much more readable test code for unit tests
that are concerned with APIs that take `UrlString`s, and
the code is more consistent.

Bug: 323797639
Change-Id: I6d797c0db9e5bd2fd019b83b9a7a269c7437ebdf
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6148578
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Danil Somsikov <dsv@chromium.org>
2025-01-07 05:49:23 -08:00

53 lines
2.7 KiB
TypeScript

// Copyright 2022 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.
import * as Platform from '../../core/platform/platform.js';
import * as SDK from '../../core/sdk/sdk.js';
import {describeWithEnvironment} from '../../testing/EnvironmentHelpers.js';
import {createFileSystemUISourceCode} from '../../testing/UISourceCodeHelpers.js';
import * as Bindings from '../bindings/bindings.js';
import * as Breakpoints from '../breakpoints/breakpoints.js';
import * as Persistence from '../persistence/persistence.js';
import * as Workspace from '../workspace/workspace.js';
import * as WorkspaceDiff from '../workspace_diff/workspace_diff.js';
const {urlString} = Platform.DevToolsPath;
describeWithEnvironment('UISourceCodeDiff', () => {
it('returns formatted mapping with a diff', async () => {
const workspace = Workspace.Workspace.WorkspaceImpl.instance({forceNew: true});
const debuggerWorkspaceBinding = Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance({
forceNew: true,
targetManager: SDK.TargetManager.TargetManager.instance(),
resourceMapping:
new Bindings.ResourceMapping.ResourceMapping(SDK.TargetManager.TargetManager.instance(), workspace),
});
const breakpointManager = Breakpoints.BreakpointManager.BreakpointManager.instance({
forceNew: true,
targetManager: SDK.TargetManager.TargetManager.instance(),
workspace,
debuggerWorkspaceBinding,
});
Persistence.Persistence.PersistenceImpl.instance({forceNew: true, workspace, breakpointManager});
Persistence.NetworkPersistenceManager.NetworkPersistenceManager.instance({forceNew: true, workspace});
const URL = urlString`file:///tmp/example.html`;
const {uiSourceCode, project} =
createFileSystemUISourceCode({url: URL, content: 'const data={original:true}', mimeType: 'text/javascript'});
uiSourceCode.setWorkingCopyGetter(() => 'const data={modified:true,original:false}');
const uiSourceCodeDiff = new WorkspaceDiff.WorkspaceDiff.UISourceCodeDiff(uiSourceCode);
const {diff, formattedCurrentMapping} = (await uiSourceCodeDiff.requestDiff({shouldFormatDiff: true}))!;
assert.deepEqual(diff, [
{0: 0, 1: ['const data = {']},
{0: -1, 1: [' original: true']},
{0: 1, 1: [' modified: true,', ' original: false']},
{0: 0, 1: ['}', '']},
]);
assert.deepEqual(formattedCurrentMapping!.originalToFormatted(0, 'const data={'.length), [1, 4]);
assert.deepEqual(formattedCurrentMapping!.originalToFormatted(0, 'const data={modified:true,'.length), [2, 4]);
workspace.removeProject(project);
});
});