diff --git a/front_end/.eslintrc.js b/front_end/.eslintrc.js index bf9bc9ece7..e72d7729cd 100644 --- a/front_end/.eslintrc.js +++ b/front_end/.eslintrc.js @@ -151,6 +151,13 @@ module.exports = { ] } }, + { + 'files': ['*.test.ts'], + 'rules': { + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/no-non-null-assertion' : 'off', + }, + }, { 'files': ['panels/**/components/*.ts', 'ui/components/**/*.ts', 'entrypoints/**/*.ts'], 'rules': { diff --git a/test/unittests/front_end/models/autofill_manager/AutofillManager.test.ts b/front_end/models/autofill_manager/AutofillManager.test.ts similarity index 92% rename from test/unittests/front_end/models/autofill_manager/AutofillManager.test.ts rename to front_end/models/autofill_manager/AutofillManager.test.ts index 7bb51ae57e..99ebe6696b 100644 --- a/test/unittests/front_end/models/autofill_manager/AutofillManager.test.ts +++ b/front_end/models/autofill_manager/AutofillManager.test.ts @@ -4,14 +4,13 @@ const {assert} = chai; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as AutofillManager from '../../../../../front_end/models/autofill_manager/autofill_manager.js'; - -import * as Root from '../../../../../front_end/core/root/root.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as UI from '../../../../../front_end/ui/legacy/legacy.js'; -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import * as Root from '../../core/root/root.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as Protocol from '../../generated/protocol.js'; +import * as UI from '../../ui/legacy/legacy.js'; +import * as AutofillManager from './autofill_manager.js'; describeWithMockConnection('AutofillManager', () => { let target: SDK.Target.Target; diff --git a/front_end/models/autofill_manager/BUILD.gn b/front_end/models/autofill_manager/BUILD.gn index 89b4a83fed..db06a2f5b3 100644 --- a/front_end/models/autofill_manager/BUILD.gn +++ b/front_end/models/autofill_manager/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("autofill_manager") { @@ -30,3 +31,16 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ "AutofillManager.test.ts" ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + "../../core/common:bundle", + "../../core/sdk:bundle", + ] +} diff --git a/front_end/models/bindings/BUILD.gn b/front_end/models/bindings/BUILD.gn index c4cf644bfd..48a00ecd4d 100644 --- a/front_end/models/bindings/BUILD.gn +++ b/front_end/models/bindings/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("bindings") { @@ -75,3 +76,30 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ + "CompilerScriptMapping.test.ts", + "ContentProviderBasedProject.test.ts", + "DebuggerLanguagePlugins.test.ts", + "DebuggerWorkspaceBinding.test.ts", + "DefaultScriptMapping.test.ts", + "FileUtils.test.ts", + "IgnoreListManager.test.ts", + "LiveLocation.test.ts", + "PresentationConsoleMessageHelper.test.ts", + "ResourceMapping.test.ts", + "ResourceScriptMapping.test.ts", + "ResourceUtils.test.ts", + ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + "../../core/common:bundle", + "../persistence:bundle", + "../workspace:bundle", + ] +} diff --git a/test/unittests/front_end/models/bindings/CompilerScriptMapping.test.ts b/front_end/models/bindings/CompilerScriptMapping.test.ts similarity index 97% rename from test/unittests/front_end/models/bindings/CompilerScriptMapping.test.ts rename to front_end/models/bindings/CompilerScriptMapping.test.ts index 912c1e3724..500b85eaf2 100644 --- a/test/unittests/front_end/models/bindings/CompilerScriptMapping.test.ts +++ b/front_end/models/bindings/CompilerScriptMapping.test.ts @@ -2,15 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import type * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; -import {MockProtocolBackend} from '../../helpers/MockScopeChain.js'; -import {encodeSourceMap} from '../../helpers/SourceMapEncoder.js'; +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import {MockProtocolBackend} from '../../../test/unittests/front_end/helpers/MockScopeChain.js'; +import {encodeSourceMap} from '../../../test/unittests/front_end/helpers/SourceMapEncoder.js'; +import type * as Platform from '../../core/platform/platform.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import type * as Protocol from '../../generated/protocol.js'; +import * as Workspace from '../workspace/workspace.js'; + +import * as Bindings from './bindings.js'; describeWithMockConnection('CompilerScriptMapping', () => { let backend: MockProtocolBackend; diff --git a/test/unittests/front_end/models/bindings/ContentProviderBasedProject.test.ts b/front_end/models/bindings/ContentProviderBasedProject.test.ts similarity index 92% rename from test/unittests/front_end/models/bindings/ContentProviderBasedProject.test.ts rename to front_end/models/bindings/ContentProviderBasedProject.test.ts index ced9df983b..b231db775f 100644 --- a/test/unittests/front_end/models/bindings/ContentProviderBasedProject.test.ts +++ b/front_end/models/bindings/ContentProviderBasedProject.test.ts @@ -2,11 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Common from '../../../../../front_end/core/common/common.js'; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; - -import {createContentProviderUISourceCodes} from '../../helpers/UISourceCodeHelpers.js'; +import {createContentProviderUISourceCodes} from '../../../test/unittests/front_end/helpers/UISourceCodeHelpers.js'; +import * as Common from '../../core/common/common.js'; +import type * as Platform from '../../core/platform/platform.js'; +import * as Workspace from '../workspace/workspace.js'; type UrlString = Platform.DevToolsPath.UrlString; diff --git a/test/unittests/front_end/models/bindings/DebuggerLanguagePlugins.test.ts b/front_end/models/bindings/DebuggerLanguagePlugins.test.ts similarity index 83% rename from test/unittests/front_end/models/bindings/DebuggerLanguagePlugins.test.ts rename to front_end/models/bindings/DebuggerLanguagePlugins.test.ts index 28eb5eb9ec..1d82524d89 100644 --- a/test/unittests/front_end/models/bindings/DebuggerLanguagePlugins.test.ts +++ b/front_end/models/bindings/DebuggerLanguagePlugins.test.ts @@ -2,10 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import {type Chrome} from '../../../../../extension-api/ExtensionAPI.js'; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import {TestPlugin} from '../../helpers/LanguagePluginHelpers.js'; +import {type Chrome} from '../../../extension-api/ExtensionAPI.js'; +import {TestPlugin} from '../../../test/unittests/front_end/helpers/LanguagePluginHelpers.js'; +import * as SDK from '../../core/sdk/sdk.js'; + +import * as Bindings from './bindings.js'; describe('DebuggerLanguagePlugins', () => { describe('ExtensionRemoteObject', () => { diff --git a/front_end/models/bindings/DebuggerLanguagePlugins.ts b/front_end/models/bindings/DebuggerLanguagePlugins.ts index 1adf42f7de..1049101815 100644 --- a/front_end/models/bindings/DebuggerLanguagePlugins.ts +++ b/front_end/models/bindings/DebuggerLanguagePlugins.ts @@ -773,46 +773,44 @@ export class DebuggerLanguagePluginManager implements const rawModuleId = rawModuleIdForScript(script); let rawModuleHandle = this.#rawModuleHandles.get(rawModuleId); if (!rawModuleHandle) { - const sourceFileURLsPromise = - (async () => { - const console = Common.Console.Console.instance(); - const url = script.sourceURL; - const symbolsUrl = (script.debugSymbols && script.debugSymbols.externalURL) || ''; - if (symbolsUrl) { - console.log( - i18nString(UIStrings.loadingDebugSymbolsForVia, {PH1: plugin.name, PH2: url, PH3: symbolsUrl})); - } else { - console.log(i18nString(UIStrings.loadingDebugSymbolsFor, {PH1: plugin.name, PH2: url})); - } - try { - const code = (!symbolsUrl && Common.ParsedURL.schemeIs(url, 'wasm:')) ? await script.getWasmBytecode() : - undefined; - const addModuleResult = await plugin.addRawModule(rawModuleId, symbolsUrl, {url, code}); - // Check that the handle isn't stale by now. This works because the code that assigns to - // `rawModuleHandle` below will run before this code because of the `await` in the preceding - // line. This is primarily to avoid logging the message below, which would give the developer - // the misleading information that we're done, while in reality it was a stale call that finished. - if (rawModuleHandle !== this.#rawModuleHandles.get(rawModuleId)) { - return []; - } - if ('missingSymbolFiles' in addModuleResult) { - return {missingSymbolFiles: addModuleResult.missingSymbolFiles}; - } - const sourceFileURLs = addModuleResult as Platform.DevToolsPath.UrlString[]; - if (sourceFileURLs.length === 0) { - console.warn(i18nString(UIStrings.loadedDebugSymbolsForButDidnt, {PH1: plugin.name, PH2: url})); - } else { - console.log(i18nString( - UIStrings.loadedDebugSymbolsForFound, {PH1: plugin.name, PH2: url, PH3: sourceFileURLs.length})); - } - return sourceFileURLs; - } catch (error) { - console.error(i18nString( - UIStrings.failedToLoadDebugSymbolsFor, {PH1: plugin.name, PH2: url, PH3: error.message})); - this.#rawModuleHandles.delete(rawModuleId); - return []; - } - })(); + const sourceFileURLsPromise = (async () => { + const console = Common.Console.Console.instance(); + const url = script.sourceURL; + const symbolsUrl = (script.debugSymbols && script.debugSymbols.externalURL) || ''; + if (symbolsUrl) { + console.log(i18nString(UIStrings.loadingDebugSymbolsForVia, {PH1: plugin.name, PH2: url, PH3: symbolsUrl})); + } else { + console.log(i18nString(UIStrings.loadingDebugSymbolsFor, {PH1: plugin.name, PH2: url})); + } + try { + const code = + (!symbolsUrl && Common.ParsedURL.schemeIs(url, 'wasm:')) ? await script.getWasmBytecode() : undefined; + const addModuleResult = await plugin.addRawModule(rawModuleId, symbolsUrl, {url, code}); + // Check that the handle isn't stale by now. This works because the code that assigns to + // `rawModuleHandle` below will run before this code because of the `await` in the preceding + // line. This is primarily to avoid logging the message below, which would give the developer + // the misleading information that we're done, while in reality it was a stale call that finished. + if (rawModuleHandle !== this.#rawModuleHandles.get(rawModuleId)) { + return []; + } + if ('missingSymbolFiles' in addModuleResult) { + return {missingSymbolFiles: addModuleResult.missingSymbolFiles}; + } + const sourceFileURLs = addModuleResult as Platform.DevToolsPath.UrlString[]; + if (sourceFileURLs.length === 0) { + console.warn(i18nString(UIStrings.loadedDebugSymbolsForButDidnt, {PH1: plugin.name, PH2: url})); + } else { + console.log(i18nString( + UIStrings.loadedDebugSymbolsForFound, {PH1: plugin.name, PH2: url, PH3: sourceFileURLs.length})); + } + return sourceFileURLs; + } catch (error) { + console.error( + i18nString(UIStrings.failedToLoadDebugSymbolsFor, {PH1: plugin.name, PH2: url, PH3: error.message})); + this.#rawModuleHandles.delete(rawModuleId); + return []; + } + })(); rawModuleHandle = {rawModuleId, plugin, scripts: [script], addRawModulePromise: sourceFileURLsPromise}; this.#rawModuleHandles.set(rawModuleId, rawModuleHandle); } else { diff --git a/test/unittests/front_end/models/bindings/DebuggerWorkspaceBinding.test.ts b/front_end/models/bindings/DebuggerWorkspaceBinding.test.ts similarity index 81% rename from test/unittests/front_end/models/bindings/DebuggerWorkspaceBinding.test.ts rename to front_end/models/bindings/DebuggerWorkspaceBinding.test.ts index b22db87d2c..d7032af632 100644 --- a/test/unittests/front_end/models/bindings/DebuggerWorkspaceBinding.test.ts +++ b/front_end/models/bindings/DebuggerWorkspaceBinding.test.ts @@ -2,14 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import type * as Protocol from '../../../../../front_end/generated/protocol.js'; -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; -import {MockProtocolBackend} from '../../helpers/MockScopeChain.js'; +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import {MockProtocolBackend} from '../../../test/unittests/front_end/helpers/MockScopeChain.js'; +import type * as Platform from '../../core/platform/platform.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import type * as Protocol from '../../generated/protocol.js'; +import * as Workspace from '../workspace/workspace.js'; + +import * as Bindings from './bindings.js'; describeWithMockConnection('DebuggerWorkspaceBinding', () => { let target: SDK.Target.Target; diff --git a/test/unittests/front_end/models/bindings/DefaultScriptMapping.test.ts b/front_end/models/bindings/DefaultScriptMapping.test.ts similarity index 92% rename from test/unittests/front_end/models/bindings/DefaultScriptMapping.test.ts rename to front_end/models/bindings/DefaultScriptMapping.test.ts index c0dd6c082d..d4c69745d1 100644 --- a/test/unittests/front_end/models/bindings/DefaultScriptMapping.test.ts +++ b/front_end/models/bindings/DefaultScriptMapping.test.ts @@ -2,16 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import * as TextUtils from '../../../../../front_end/models/text_utils/text_utils.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import {MockProtocolBackend} from '../../../test/unittests/front_end/helpers/MockScopeChain.js'; +import type * as Platform from '../../core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../core/platform/platform.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as TextUtils from '../text_utils/text_utils.js'; +import * as Workspace from '../workspace/workspace.js'; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; -import {MockProtocolBackend} from '../../helpers/MockScopeChain.js'; +import * as Bindings from './bindings.js'; describeWithMockConnection('DefaultScriptMapping', () => { const url = 'file:///tmp/example.js' as Platform.DevToolsPath.UrlString; diff --git a/test/unittests/front_end/models/bindings/FileUtils.test.ts b/front_end/models/bindings/FileUtils.test.ts similarity index 95% rename from test/unittests/front_end/models/bindings/FileUtils.test.ts rename to front_end/models/bindings/FileUtils.test.ts index de9864368f..7d30583d4b 100644 --- a/test/unittests/front_end/models/bindings/FileUtils.test.ts +++ b/front_end/models/bindings/FileUtils.test.ts @@ -4,8 +4,8 @@ const {assert} = chai; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import * as Common from '../../../../../front_end/core/common/common.js'; +import * as Bindings from './bindings.js'; +import * as Common from '../../core/common/common.js'; const ChunkedFileReader = Bindings.FileUtils.ChunkedFileReader; const StringOutputStream = Common.StringOutputStream.StringOutputStream; diff --git a/test/unittests/front_end/models/bindings/IgnoreListManager.test.ts b/front_end/models/bindings/IgnoreListManager.test.ts similarity index 96% rename from test/unittests/front_end/models/bindings/IgnoreListManager.test.ts rename to front_end/models/bindings/IgnoreListManager.test.ts index 510d1eb68e..ada6ead38d 100644 --- a/test/unittests/front_end/models/bindings/IgnoreListManager.test.ts +++ b/front_end/models/bindings/IgnoreListManager.test.ts @@ -2,17 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Common from '../../../../../front_end/core/common/common.js'; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import type * as SDKModule from '../../../../../front_end/core/sdk/sdk.js'; -import type * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import {createContentProviderUISourceCode} from '../../../test/unittests/front_end/helpers/UISourceCodeHelpers.js'; +import * as Common from '../../core/common/common.js'; +import type * as Platform from '../../core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../core/platform/platform.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import type * as Protocol from '../../generated/protocol.js'; +import * as Workspace from '../workspace/workspace.js'; -import {createContentProviderUISourceCode} from '../../helpers/UISourceCodeHelpers.js'; +import * as Bindings from './bindings.js'; const {assert} = chai; @@ -49,12 +49,7 @@ function notNull(val: T|null|undefined): T { } describeWithMockConnection('IgnoreListManager', () => { - let SDK: typeof SDKModule; - before(async () => { - SDK = await import('../../../../../front_end/core/sdk/sdk.js'); - }); - - let debuggerModel: SDKModule.DebuggerModel.DebuggerModel; + let debuggerModel: SDK.DebuggerModel.DebuggerModel; let ignoreListManager: Bindings.IgnoreListManager.IgnoreListManager; let uiSourceCode: Workspace.UISourceCode.UISourceCode; @@ -150,7 +145,7 @@ describeWithMockConnection('IgnoreListManager', () => { const length = 0; const embedderName = url; const executionContextId = 1; - debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel) as SDKModule.DebuggerModel.DebuggerModel; + debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel) as SDK.DebuggerModel.DebuggerModel; SCRIPTS.forEach(({ scriptId, startLine, diff --git a/test/unittests/front_end/models/bindings/LiveLocation.test.ts b/front_end/models/bindings/LiveLocation.test.ts similarity index 95% rename from test/unittests/front_end/models/bindings/LiveLocation.test.ts rename to front_end/models/bindings/LiveLocation.test.ts index 08ea837ea8..8080ff9219 100644 --- a/test/unittests/front_end/models/bindings/LiveLocation.test.ts +++ b/front_end/models/bindings/LiveLocation.test.ts @@ -4,7 +4,7 @@ const {assert} = chai; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; +import * as Bindings from './bindings.js'; const LiveLocationPool = Bindings.LiveLocation.LiveLocationPool; const LiveLocationWithPool = Bindings.LiveLocation.LiveLocationWithPool; diff --git a/test/unittests/front_end/models/bindings/PresentationConsoleMessageHelper.test.ts b/front_end/models/bindings/PresentationConsoleMessageHelper.test.ts similarity index 95% rename from test/unittests/front_end/models/bindings/PresentationConsoleMessageHelper.test.ts rename to front_end/models/bindings/PresentationConsoleMessageHelper.test.ts index 248f8cbd1e..d773737c0e 100644 --- a/test/unittests/front_end/models/bindings/PresentationConsoleMessageHelper.test.ts +++ b/front_end/models/bindings/PresentationConsoleMessageHelper.test.ts @@ -2,15 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Common from '../../../../../front_end/core/common/common.js'; -import * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; -import {MockExecutionContext} from '../../helpers/MockExecutionContext.js'; +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import {MockExecutionContext} from '../../../test/unittests/front_end/helpers/MockExecutionContext.js'; +import * as Common from '../../core/common/common.js'; +import * as Platform from '../../core/platform/platform.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as Protocol from '../../generated/protocol.js'; +import * as Workspace from '../workspace/workspace.js'; + +import * as Bindings from './bindings.js'; async function addMessage( helper: Bindings.PresentationConsoleMessageHelper.PresentationSourceFrameMessageHelper, target: SDK.Target.Target, diff --git a/test/unittests/front_end/models/bindings/ResourceMapping.test.ts b/front_end/models/bindings/ResourceMapping.test.ts similarity index 90% rename from test/unittests/front_end/models/bindings/ResourceMapping.test.ts rename to front_end/models/bindings/ResourceMapping.test.ts index 9e9dc9a878..bbd7ced3a5 100644 --- a/test/unittests/front_end/models/bindings/ResourceMapping.test.ts +++ b/front_end/models/bindings/ResourceMapping.test.ts @@ -2,29 +2,25 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Common from '../../../../../front_end/core/common/common.js'; -import * as TextUtils from '../../../../../front_end/models/text_utils/text_utils.js'; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; -import type * as SDKModule from '../../../../../front_end/core/sdk/sdk.js'; -import type * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import * as Common from '../../core/common/common.js'; +import type * as Platform from '../../core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../core/platform/platform.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import type * as Protocol from '../../generated/protocol.js'; +import * as TextUtils from '../text_utils/text_utils.js'; +import * as Workspace from '../workspace/workspace.js'; + +import * as Bindings from './bindings.js'; const {assert} = chai; describeWithMockConnection('ResourceMapping', () => { - let SDK: typeof SDKModule; - before(async () => { - SDK = await import('../../../../../front_end/core/sdk/sdk.js'); - }); - - let debuggerModel: SDKModule.DebuggerModel.DebuggerModel; + let debuggerModel: SDK.DebuggerModel.DebuggerModel; let resourceMapping: Bindings.ResourceMapping.ResourceMapping; let uiSourceCode: Workspace.UISourceCode.UISourceCode; - let resourceTreeModel: SDKModule.ResourceTreeModel.ResourceTreeModel; + let resourceTreeModel: SDK.ResourceTreeModel.ResourceTreeModel; let workspace: Workspace.Workspace.WorkspaceImpl; // This test simulates the behavior of the ResourceMapping with the @@ -83,7 +79,7 @@ describeWithMockConnection('ResourceMapping', () => { const frameId = 'main' as Protocol.Page.FrameId; const mimeType = 'text/html'; resourceTreeModel = - target.model(SDK.ResourceTreeModel.ResourceTreeModel) as SDKModule.ResourceTreeModel.ResourceTreeModel; + target.model(SDK.ResourceTreeModel.ResourceTreeModel) as SDK.ResourceTreeModel.ResourceTreeModel; const frame = resourceTreeModel.frameAttached(frameId, null); frame?.addResource(new SDK.Resource.Resource( resourceTreeModel, null, url, url, frameId, null, Common.ResourceType.ResourceType.fromMimeType(mimeType), @@ -96,7 +92,7 @@ describeWithMockConnection('ResourceMapping', () => { const length = 0; const embedderName = url; const executionContextId = 1; - debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel) as SDKModule.DebuggerModel.DebuggerModel; + debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel) as SDK.DebuggerModel.DebuggerModel; SCRIPTS.forEach(({scriptId, startLine, startColumn, endLine, endColumn, sourceURL, hasSourceURLComment}) => { debuggerModel.parsedScriptSource( scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash, undefined, false, diff --git a/test/unittests/front_end/models/bindings/ResourceScriptMapping.test.ts b/front_end/models/bindings/ResourceScriptMapping.test.ts similarity index 87% rename from test/unittests/front_end/models/bindings/ResourceScriptMapping.test.ts rename to front_end/models/bindings/ResourceScriptMapping.test.ts index 50136f98e4..5832bf03c7 100644 --- a/test/unittests/front_end/models/bindings/ResourceScriptMapping.test.ts +++ b/front_end/models/bindings/ResourceScriptMapping.test.ts @@ -2,16 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import * as TextUtils from '../../../../../front_end/models/text_utils/text_utils.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import {MockProtocolBackend} from '../../../test/unittests/front_end/helpers/MockScopeChain.js'; +import type * as Platform from '../../core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../core/platform/platform.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as TextUtils from '../text_utils/text_utils.js'; +import * as Workspace from '../workspace/workspace.js'; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; -import {MockProtocolBackend} from '../../helpers/MockScopeChain.js'; +import * as Bindings from './bindings.js'; describeWithMockConnection('ResourceScriptMapping', () => { const url = 'http://localhost/example.js' as Platform.DevToolsPath.UrlString; diff --git a/test/unittests/front_end/models/bindings/ResourceUtils.test.ts b/front_end/models/bindings/ResourceUtils.test.ts similarity index 92% rename from test/unittests/front_end/models/bindings/ResourceUtils.test.ts rename to front_end/models/bindings/ResourceUtils.test.ts index 345f879f3b..142b2698c1 100644 --- a/test/unittests/front_end/models/bindings/ResourceUtils.test.ts +++ b/front_end/models/bindings/ResourceUtils.test.ts @@ -2,16 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import type * as Platform from '../../core/platform/platform.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as Workspace from '../workspace/workspace.js'; + +import * as Bindings from './bindings.js'; + const {assert} = chai; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; - -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; - describeWithMockConnection('ResourceUtils', () => { const displayNameForURL = (targetFactory: () => SDK.Target.Target) => { const INSPECTED_URL_SCHEME = 'http://'; diff --git a/front_end/models/breakpoints/BUILD.gn b/front_end/models/breakpoints/BUILD.gn index 762551022c..4c0c19ee4a 100644 --- a/front_end/models/breakpoints/BUILD.gn +++ b/front_end/models/breakpoints/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("breakpoints") { @@ -41,3 +42,14 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ "BreakpointManager.test.ts" ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + ] +} diff --git a/test/unittests/front_end/models/breakpoints/BreakpointManager.test.ts b/front_end/models/breakpoints/BreakpointManager.test.ts similarity index 98% rename from test/unittests/front_end/models/breakpoints/BreakpointManager.test.ts rename to front_end/models/breakpoints/BreakpointManager.test.ts index c385eecc15..c4d3037b88 100644 --- a/test/unittests/front_end/models/breakpoints/BreakpointManager.test.ts +++ b/front_end/models/breakpoints/BreakpointManager.test.ts @@ -2,34 +2,40 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import {type Chrome} from '../../../../../extension-api/ExtensionAPI.js'; -import * as Common from '../../../../../front_end/core/common/common.js'; -import * as Host from '../../../../../front_end/core/host/host.js'; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; -import * as Root from '../../../../../front_end/core/root/root.js'; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import * as Breakpoints from '../../../../../front_end/models/breakpoints/breakpoints.js'; -import * as Persistence from '../../../../../front_end/models/persistence/persistence.js'; -import * as TextUtils from '../../../../../front_end/models/text_utils/text_utils.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {TestPlugin} from '../../helpers/LanguagePluginHelpers.js'; +import {type Chrome} from '../../../extension-api/ExtensionAPI.js'; +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {TestPlugin} from '../../../test/unittests/front_end/helpers/LanguagePluginHelpers.js'; import { clearMockConnectionResponseHandler, describeWithMockConnection, dispatchEvent, registerListenerOnOutgoingMessage, setMockConnectionResponseHandler, -} from '../../helpers/MockConnection.js'; -import {MockProtocolBackend} from '../../helpers/MockScopeChain.js'; -import {createFileSystemFileForPersistenceTests} from '../../helpers/PersistenceHelpers.js'; -import {encodeSourceMap} from '../../helpers/SourceMapEncoder.js'; -import {setupPageResourceLoaderForSourceMap} from '../../helpers/SourceMapHelpers.js'; -import {createContentProviderUISourceCode, createFakeScriptMapping} from '../../helpers/UISourceCodeHelpers.js'; -import {recordedMetricsContain, resetRecordedMetrics} from '../../helpers/UserMetricsHelpers.js'; +} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import {MockProtocolBackend} from '../../../test/unittests/front_end/helpers/MockScopeChain.js'; +import {createFileSystemFileForPersistenceTests} from '../../../test/unittests/front_end/helpers/PersistenceHelpers.js'; +import {encodeSourceMap} from '../../../test/unittests/front_end/helpers/SourceMapEncoder.js'; +import {setupPageResourceLoaderForSourceMap} from '../../../test/unittests/front_end/helpers/SourceMapHelpers.js'; +import { + createContentProviderUISourceCode, + createFakeScriptMapping, +} from '../../../test/unittests/front_end/helpers/UISourceCodeHelpers.js'; +import { + recordedMetricsContain, + resetRecordedMetrics, +} from '../../../test/unittests/front_end/helpers/UserMetricsHelpers.js'; +import * as Common from '../../core/common/common.js'; +import * as Host from '../../core/host/host.js'; +import type * as Platform from '../../core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../core/platform/platform.js'; +import * as Root from '../../core/root/root.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as Protocol from '../../generated/protocol.js'; +import * as Bindings from '../bindings/bindings.js'; +import * as Breakpoints from '../breakpoints/breakpoints.js'; +import * as Persistence from '../persistence/persistence.js'; +import * as TextUtils from '../text_utils/text_utils.js'; +import * as Workspace from '../workspace/workspace.js'; const {assert} = chai; diff --git a/front_end/models/cpu_profile/BUILD.gn b/front_end/models/cpu_profile/BUILD.gn index e7f32aa037..f54289be85 100644 --- a/front_end/models/cpu_profile/BUILD.gn +++ b/front_end/models/cpu_profile/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") devtools_module("cpu_profile") { sources = [ @@ -34,3 +35,14 @@ devtools_entrypoint("bundle") { "../trace/*", ] } + +ts_library("unittests") { + testonly = true + + sources = [ "CPUProfileDataModel.test.ts" ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + ] +} diff --git a/test/unittests/front_end/models/cpu_profile/CPUProfileDataModel.test.ts b/front_end/models/cpu_profile/CPUProfileDataModel.test.ts similarity index 98% rename from test/unittests/front_end/models/cpu_profile/CPUProfileDataModel.test.ts rename to front_end/models/cpu_profile/CPUProfileDataModel.test.ts index 6c01f8c29b..28d8ada7ef 100644 --- a/test/unittests/front_end/models/cpu_profile/CPUProfileDataModel.test.ts +++ b/front_end/models/cpu_profile/CPUProfileDataModel.test.ts @@ -3,10 +3,10 @@ // found in the LICENSE file. const {assert} = chai; -import type * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as CPUProfile from '../../../../../front_end/models/cpu_profile/cpu_profile.js'; +import type * as Protocol from '../../generated/protocol.js'; +import * as CPUProfile from '../cpu_profile/cpu_profile.js'; -import {describeWithEnvironment} from '../../helpers/EnvironmentHelpers.js'; +import {describeWithEnvironment} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; function makeCallFrame(functionName: string): Protocol.Runtime.CallFrame { return { diff --git a/front_end/models/emulation/BUILD.gn b/front_end/models/emulation/BUILD.gn index 60ae7314d0..0cc9fd4443 100644 --- a/front_end/models/emulation/BUILD.gn +++ b/front_end/models/emulation/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("emulation") { @@ -38,3 +39,19 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ + "DeviceModeModel.test.ts", + "EmulatedDevices.test.ts", + ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + "../../core/platform:bundle", + "../../core/sdk:bundle", + ] +} diff --git a/test/unittests/front_end/models/emulation/DeviceModeModel.test.ts b/front_end/models/emulation/DeviceModeModel.test.ts similarity index 94% rename from test/unittests/front_end/models/emulation/DeviceModeModel.test.ts rename to front_end/models/emulation/DeviceModeModel.test.ts index 78179e2476..2c39c81ed9 100644 --- a/test/unittests/front_end/models/emulation/DeviceModeModel.test.ts +++ b/front_end/models/emulation/DeviceModeModel.test.ts @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as EmulationModel from '../../../../../front_end/models/emulation/emulation.js'; -import {createTarget, stubNoopSettings} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; +import {createTarget, stubNoopSettings} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as EmulationModel from '../emulation/emulation.js'; describe('Insets', () => { it('can be instantiated without issues', () => { diff --git a/test/unittests/front_end/models/emulation/EmulatedDevices.test.ts b/front_end/models/emulation/EmulatedDevices.test.ts similarity index 89% rename from test/unittests/front_end/models/emulation/EmulatedDevices.test.ts rename to front_end/models/emulation/EmulatedDevices.test.ts index 25cee99ab8..0be4ffcec7 100644 --- a/test/unittests/front_end/models/emulation/EmulatedDevices.test.ts +++ b/front_end/models/emulation/EmulatedDevices.test.ts @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as EmulationModel from '../../../../../front_end/models/emulation/emulation.js'; +import * as EmulationModel from '../emulation/emulation.js'; -const BASE_URL = new URL('../../../../../front_end/emulated_devices/', import.meta.url).toString(); +const BASE_URL = new URL('../../../front_end/emulated_devices/', import.meta.url).toString(); describe('EmulatedDevices can compute CSS image URLs', () => { it('as regular string', () => { diff --git a/front_end/models/extensions/BUILD.gn b/front_end/models/extensions/BUILD.gn index 47de280abc..619af7ecb7 100644 --- a/front_end/models/extensions/BUILD.gn +++ b/front_end/models/extensions/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("extensions") { @@ -46,6 +47,7 @@ devtools_entrypoint("bundle") { visibility = [ ":*", + "../../../test/unittests/front_end/helpers", "../../../test/unittests/front_end/models/extensions:extensions", "../../entrypoints/main/*", "../../panels/elements/*", @@ -56,3 +58,18 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ + "ExtensionServer.test.ts", + "HostUrlPattern.test.ts", + "RecorderPluginManager.test.ts", + ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + ] +} diff --git a/test/unittests/front_end/models/extensions/ExtensionServer.test.ts b/front_end/models/extensions/ExtensionServer.test.ts similarity index 96% rename from test/unittests/front_end/models/extensions/ExtensionServer.test.ts rename to front_end/models/extensions/ExtensionServer.test.ts index 7b8c4aeb36..5f2f6384e0 100644 --- a/test/unittests/front_end/models/extensions/ExtensionServer.test.ts +++ b/front_end/models/extensions/ExtensionServer.test.ts @@ -2,23 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Common from '../../../../../front_end/core/common/common.js'; -import * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import * as Extensions from '../../../../../front_end/models/extensions/extensions.js'; -import type * as HAR from '../../../../../front_end/models/har/har.js'; -import * as Logs from '../../../../../front_end/models/logs/logs.js'; -import * as TextUtils from '../../../../../front_end/models/text_utils/text_utils.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; -import * as UI from '../../../../../front_end/ui/legacy/legacy.js'; +import * as Common from '../../core/common/common.js'; +import * as Platform from '../../core/platform/platform.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as Protocol from '../../generated/protocol.js'; +import * as UI from '../../ui/legacy/legacy.js'; +import * as Bindings from '../bindings/bindings.js'; +import * as Extensions from '../extensions/extensions.js'; +import type * as HAR from '../har/har.js'; +import * as Logs from '../logs/logs.js'; +import * as TextUtils from '../text_utils/text_utils.js'; +import * as Workspace from '../workspace/workspace.js'; const {assert} = chai; -import {describeWithDevtoolsExtension} from './helpers.js'; -import {type Chrome} from '../../../../../extension-api/ExtensionAPI.js'; -import {createTarget, expectConsoleLogs} from '../../helpers/EnvironmentHelpers.js'; +import {describeWithDevtoolsExtension} from '../../../test/unittests/front_end/helpers/ExtensionHelpers.js'; +import {type Chrome} from '../../../extension-api/ExtensionAPI.js'; +import {createTarget, expectConsoleLogs} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; describeWithDevtoolsExtension('Extensions', {}, context => { it('are initialized after the target is initialized and navigated to a non-privileged URL', async () => { diff --git a/test/unittests/front_end/models/extensions/HostUrlPattern.test.ts b/front_end/models/extensions/HostUrlPattern.test.ts similarity index 99% rename from test/unittests/front_end/models/extensions/HostUrlPattern.test.ts rename to front_end/models/extensions/HostUrlPattern.test.ts index 07e8cd255f..ca24590088 100644 --- a/test/unittests/front_end/models/extensions/HostUrlPattern.test.ts +++ b/front_end/models/extensions/HostUrlPattern.test.ts @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as Extensions from '../../../../../front_end/models/extensions/extensions.js'; +import * as Platform from '../../core/platform/platform.js'; +import * as Extensions from '../extensions/extensions.js'; // The test expectations are from //extensions/common/url_pattern_unittest.cc but leave out tests for the unsupported // schemes and paths. Also left out are tests for whitespace and unicode urls since that doesn't go through the url diff --git a/test/unittests/front_end/models/extensions/RecorderPluginManager.test.ts b/front_end/models/extensions/RecorderPluginManager.test.ts similarity index 93% rename from test/unittests/front_end/models/extensions/RecorderPluginManager.test.ts rename to front_end/models/extensions/RecorderPluginManager.test.ts index 1099250c8e..89d135eb29 100644 --- a/test/unittests/front_end/models/extensions/RecorderPluginManager.test.ts +++ b/front_end/models/extensions/RecorderPluginManager.test.ts @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Extensions from '../../../../../front_end/models/extensions/extensions.js'; +import * as Extensions from '../extensions/extensions.js'; const {assert} = chai; diff --git a/front_end/models/formatter/BUILD.gn b/front_end/models/formatter/BUILD.gn index 9fa3104ce7..f1a06ac141 100644 --- a/front_end/models/formatter/BUILD.gn +++ b/front_end/models/formatter/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("formatter") { @@ -49,3 +50,18 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ "ScriptFormatter.test.ts" ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + "../../core/common:bundle", + "../../core/sdk:bundle", + "../../models/bindings:bundle", + "../../models/workspace:bundle", + ] +} diff --git a/test/unittests/front_end/models/formatter/ScriptFormatter.test.ts b/front_end/models/formatter/ScriptFormatter.test.ts similarity index 96% rename from test/unittests/front_end/models/formatter/ScriptFormatter.test.ts rename to front_end/models/formatter/ScriptFormatter.test.ts index 569fb97575..d843884a98 100644 --- a/test/unittests/front_end/models/formatter/ScriptFormatter.test.ts +++ b/front_end/models/formatter/ScriptFormatter.test.ts @@ -4,8 +4,8 @@ const {assert} = chai; -import * as Common from '../../../../../front_end/core/common/common.js'; -import * as Formatter from '../../../../../front_end/models/formatter/formatter.js'; +import * as Common from '../../core/common/common.js'; +import * as Formatter from '../formatter/formatter.js'; describe('ScriptFormatter', () => { const indentString = ' '; diff --git a/front_end/models/har/BUILD.gn b/front_end/models/har/BUILD.gn index 6478a9d3b7..d60ecb949a 100644 --- a/front_end/models/har/BUILD.gn +++ b/front_end/models/har/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") devtools_module("har") { sources = [ @@ -29,8 +30,27 @@ devtools_entrypoint("bundle") { deps = [ ":har" ] visibility = [ + ":*", "../../../test/unittests/front_end/models/har/*", "../../panels/network/*", "../extensions/*", ] } + +ts_library("unittests") { + testonly = true + + sources = [ + "Importer.test.ts", + "Log.test.ts", + "Writer.test.ts", + ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + "../../core/common:bundle", + "../../core/sdk:bundle", + "../../ui/legacy:bundle", + ] +} diff --git a/test/unittests/front_end/models/har/Importer.test.ts b/front_end/models/har/Importer.test.ts similarity index 96% rename from test/unittests/front_end/models/har/Importer.test.ts rename to front_end/models/har/Importer.test.ts index 1e7a2699c9..95fde27280 100644 --- a/test/unittests/front_end/models/har/Importer.test.ts +++ b/front_end/models/har/Importer.test.ts @@ -4,9 +4,9 @@ const {assert} = chai; -import * as HAR from '../../../../../front_end/models/har/har.js'; -import type * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; +import * as HAR from '../har/har.js'; +import type * as SDK from '../../core/sdk/sdk.js'; +import * as Protocol from '../../generated/protocol.js'; const exampleLog = new HAR.HARFormat.HARLog({ version: '1.2', diff --git a/test/unittests/front_end/models/har/Log.test.ts b/front_end/models/har/Log.test.ts similarity index 82% rename from test/unittests/front_end/models/har/Log.test.ts rename to front_end/models/har/Log.test.ts index 2dca1463f0..8ecefa0f30 100644 --- a/test/unittests/front_end/models/har/Log.test.ts +++ b/front_end/models/har/Log.test.ts @@ -4,10 +4,10 @@ const {assert} = chai; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as HAR from '../../../../../front_end/models/har/har.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as Platform from '../../core/platform/platform.js'; +import * as Protocol from '../../generated/protocol.js'; +import * as HAR from '../har/har.js'; describe('HAR.Log', () => { it('blocked time when no response received is returned in milliseconds (crbug.com/1145177)', async () => { diff --git a/test/unittests/front_end/models/har/Writer.test.ts b/front_end/models/har/Writer.test.ts similarity index 75% rename from test/unittests/front_end/models/har/Writer.test.ts rename to front_end/models/har/Writer.test.ts index 337ab83e77..53f056ad12 100644 --- a/test/unittests/front_end/models/har/Writer.test.ts +++ b/front_end/models/har/Writer.test.ts @@ -4,14 +4,14 @@ const {assert} = chai; -import * as Common from '../../../../../front_end/core/common/common.js'; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as UI from '../../../../../front_end/ui/legacy/legacy.js'; -import * as HAR from '../../../../../front_end/models/har/har.js'; -import * as TextUtils from '../../../../../front_end/models/text_utils/text_utils.js'; -import * as Platform from '../../../../../front_end/core/platform/platform.js'; -import type * as Protocol from '../../../../../front_end/generated/protocol.js'; -import {describeWithLocale} from '../../helpers/EnvironmentHelpers.js'; +import * as Common from '../../core/common/common.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as UI from '../../ui/legacy/legacy.js'; +import * as HAR from '../har/har.js'; +import * as TextUtils from '../text_utils/text_utils.js'; +import * as Platform from '../../core/platform/platform.js'; +import type * as Protocol from '../../generated/protocol.js'; +import {describeWithLocale} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; const simulateRequestWithStartTime = (startTime: number) => { const requestId = 'r0' as Protocol.Network.RequestId; diff --git a/front_end/models/issues_manager/BUILD.gn b/front_end/models/issues_manager/BUILD.gn index 1bda309c7e..5e1e219b91 100644 --- a/front_end/models/issues_manager/BUILD.gn +++ b/front_end/models/issues_manager/BUILD.gn @@ -5,6 +5,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") import("../../../scripts/build/ninja/devtools_pre_built.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("issues_manager") { @@ -208,3 +209,29 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ + "CheckFormsIssuesTrigger.test.ts", + "DeprecationIssue.test.ts", + "FederatedAuthUserInfoRequestIssue.test.ts", + "GenericIssue.test.ts", + "Issue.test.ts", + "IssueResolver.test.ts", + "IssuesManager.test.ts", + "LowTextContrastIssue.test.ts", + "MarkdownIssueDescription.test.ts", + "PropertyRuleIssue.test.ts", + "RelatedIssue.test.ts", + "StylesheetLoadingIssue.test.ts", + ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + "../../core/common:bundle", + "../../core/sdk:bundle", + ] +} diff --git a/test/unittests/front_end/models/issues_manager/CheckFormsIssuesTrigger.test.ts b/front_end/models/issues_manager/CheckFormsIssuesTrigger.test.ts similarity index 64% rename from test/unittests/front_end/models/issues_manager/CheckFormsIssuesTrigger.test.ts rename to front_end/models/issues_manager/CheckFormsIssuesTrigger.test.ts index c5948e5582..1daee66083 100644 --- a/test/unittests/front_end/models/issues_manager/CheckFormsIssuesTrigger.test.ts +++ b/front_end/models/issues_manager/CheckFormsIssuesTrigger.test.ts @@ -2,20 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; -import type * as SDKModule from '../../../../../front_end/core/sdk/sdk.js'; -import * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import {assertNotNullOrUndefined} from '../../core/platform/platform.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as IssuesManager from '../issues_manager/issues_manager.js'; const {assert} = chai; describeWithMockConnection('CheckFormsIssuesTrigger', () => { - let SDK: typeof SDKModule; - before(async () => { - SDK = await import('../../../../../front_end/core/sdk/sdk.js'); - }); - it('should call `checkFormsIssues` on devtools open.', async () => { const parentTarget = createTarget(); const target = createTarget({parentTarget}); diff --git a/test/unittests/front_end/models/issues_manager/DeprecationIssue.test.ts b/front_end/models/issues_manager/DeprecationIssue.test.ts similarity index 83% rename from test/unittests/front_end/models/issues_manager/DeprecationIssue.test.ts rename to front_end/models/issues_manager/DeprecationIssue.test.ts index a2701d162a..f57cbc150d 100644 --- a/test/unittests/front_end/models/issues_manager/DeprecationIssue.test.ts +++ b/front_end/models/issues_manager/DeprecationIssue.test.ts @@ -4,13 +4,13 @@ const {assert} = chai; -import * as Issues from '../../../../../front_end/panels/issues/issues.js'; -import * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; -import type * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import {MockIssuesModel} from '../../models/issues_manager/MockIssuesModel.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; -import {describeWithLocale} from '../../helpers/EnvironmentHelpers.js'; -import {MockIssuesManager} from '../../models/issues_manager/MockIssuesManager.js'; +import * as Issues from '../../panels/issues/issues.js'; +import * as IssuesManager from '../issues_manager/issues_manager.js'; +import type * as SDK from '../../core/sdk/sdk.js'; +import {MockIssuesModel} from '../../../test/unittests/front_end/helpers/MockIssuesModel.js'; +import * as Protocol from '../../generated/protocol.js'; +import {describeWithLocale} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {MockIssuesManager} from '../../../test/unittests/front_end/helpers/MockIssuesManager.js'; describeWithLocale('DeprecationIssue', () => { const mockModel = new MockIssuesModel([]) as unknown as SDK.IssuesModel.IssuesModel; diff --git a/test/unittests/front_end/models/issues_manager/FederatedAuthUserInfoRequestIssue.test.ts b/front_end/models/issues_manager/FederatedAuthUserInfoRequestIssue.test.ts similarity index 86% rename from test/unittests/front_end/models/issues_manager/FederatedAuthUserInfoRequestIssue.test.ts rename to front_end/models/issues_manager/FederatedAuthUserInfoRequestIssue.test.ts index da7f305119..2cdf55e630 100644 --- a/test/unittests/front_end/models/issues_manager/FederatedAuthUserInfoRequestIssue.test.ts +++ b/front_end/models/issues_manager/FederatedAuthUserInfoRequestIssue.test.ts @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import type * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; -import {describeWithLocale} from '../../helpers/EnvironmentHelpers.js'; -import {MockIssuesModel} from '../../models/issues_manager/MockIssuesModel.js'; +import {describeWithLocale} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {MockIssuesModel} from '../../../test/unittests/front_end/helpers/MockIssuesModel.js'; +import type * as SDK from '../../core/sdk/sdk.js'; +import * as Protocol from '../../generated/protocol.js'; +import * as IssuesManager from '../issues_manager/issues_manager.js'; function createProtocolIssue( federatedAuthUserInfoRequestIssueDetails: Protocol.Audits.FederatedAuthUserInfoRequestIssueDetails): diff --git a/test/unittests/front_end/models/issues_manager/GenericIssue.test.ts b/front_end/models/issues_manager/GenericIssue.test.ts similarity index 89% rename from test/unittests/front_end/models/issues_manager/GenericIssue.test.ts rename to front_end/models/issues_manager/GenericIssue.test.ts index 711fd6614c..dd0456788e 100644 --- a/test/unittests/front_end/models/issues_manager/GenericIssue.test.ts +++ b/front_end/models/issues_manager/GenericIssue.test.ts @@ -4,11 +4,11 @@ const {assert} = chai; -import * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; -import type * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import {MockIssuesModel} from '../../models/issues_manager/MockIssuesModel.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; -import {describeWithLocale} from '../../helpers/EnvironmentHelpers.js'; +import * as IssuesManager from '../issues_manager/issues_manager.js'; +import type * as SDK from '../../core/sdk/sdk.js'; +import {MockIssuesModel} from '../../../test/unittests/front_end/helpers/MockIssuesModel.js'; +import * as Protocol from '../../generated/protocol.js'; +import {describeWithLocale} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; describeWithLocale('GenericIssue', async () => { const mockModel = new MockIssuesModel([]) as unknown as SDK.IssuesModel.IssuesModel; diff --git a/test/unittests/front_end/models/issues_manager/Issue.test.ts b/front_end/models/issues_manager/Issue.test.ts similarity index 90% rename from test/unittests/front_end/models/issues_manager/Issue.test.ts rename to front_end/models/issues_manager/Issue.test.ts index 9f6e3fc488..cc591add8c 100644 --- a/test/unittests/front_end/models/issues_manager/Issue.test.ts +++ b/front_end/models/issues_manager/Issue.test.ts @@ -4,9 +4,9 @@ const {assert} = chai; -import * as IssueManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; -import type * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import {StubIssue} from './StubIssue.js'; +import * as IssueManager from '../issues_manager/issues_manager.js'; +import type * as SDK from '../../core/sdk/sdk.js'; +import {StubIssue} from '../../../test/unittests/front_end/helpers/StubIssue.js'; describe('Issue', () => { it('should store the code', () => { diff --git a/test/unittests/front_end/models/issues_manager/IssueResolver.test.ts b/front_end/models/issues_manager/IssueResolver.test.ts similarity index 93% rename from test/unittests/front_end/models/issues_manager/IssueResolver.test.ts rename to front_end/models/issues_manager/IssueResolver.test.ts index d23da11d42..53760d601f 100644 --- a/test/unittests/front_end/models/issues_manager/IssueResolver.test.ts +++ b/front_end/models/issues_manager/IssueResolver.test.ts @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -const {assert} = chai; +import {MockIssuesManager} from '../../../test/unittests/front_end/helpers/MockIssuesManager.js'; +import {StubIssue} from '../../../test/unittests/front_end/helpers/StubIssue.js'; +import type * as Protocol from '../../generated/protocol.js'; +import * as IssuesManager from '../issues_manager/issues_manager.js'; -import type * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; -import {StubIssue} from './StubIssue.js'; -import {MockIssuesManager} from './MockIssuesManager.js'; +const {assert} = chai; describe('IssueResolver', () => { const issueId1 = 'foo' as Protocol.Audits.IssueId; diff --git a/test/unittests/front_end/models/issues_manager/IssuesManager.test.ts b/front_end/models/issues_manager/IssuesManager.test.ts similarity index 94% rename from test/unittests/front_end/models/issues_manager/IssuesManager.test.ts rename to front_end/models/issues_manager/IssuesManager.test.ts index cf1410ac7b..6e229b082a 100644 --- a/test/unittests/front_end/models/issues_manager/IssuesManager.test.ts +++ b/front_end/models/issues_manager/IssuesManager.test.ts @@ -4,14 +4,18 @@ const {assert} = chai; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as IssuesManager from '../issues_manager/issues_manager.js'; -import {createFakeSetting, createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection, dispatchEvent} from '../../helpers/MockConnection.js'; -import {mkInspectorCspIssue, StubIssue, ThirdPartyStubIssue} from './StubIssue.js'; -import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; +import {createFakeSetting, createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection, dispatchEvent} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import { + mkInspectorCspIssue, + StubIssue, + ThirdPartyStubIssue, +} from '../../../test/unittests/front_end/helpers/StubIssue.js'; +import {assertNotNullOrUndefined} from '../../core/platform/platform.js'; +import * as Protocol from '../../generated/protocol.js'; describeWithMockConnection('IssuesManager', () => { let target: SDK.Target.Target; @@ -270,12 +274,12 @@ describeWithMockConnection('IssuesManager', () => { 'UnhiddenStubIssue1': IssuesManager.IssuesManager.IssueStatus.Hidden, 'UnhiddenStubIssue2': IssuesManager.IssuesManager.IssueStatus.Hidden, }); - let UnhiddenIssues: string[] = []; + let unhiddenIssues: string[] = []; issuesManager.addEventListener(IssuesManager.IssuesManager.Events.FullUpdateRequired, () => { - UnhiddenIssues = []; + unhiddenIssues = []; for (const issue of issuesManager.issues()) { if (!issue.isHidden()) { - UnhiddenIssues.push(issue.code()); + unhiddenIssues.push(issue.code()); } } }); @@ -287,7 +291,7 @@ describeWithMockConnection('IssuesManager', () => { 'UnhiddenStubIssue1': IssuesManager.IssuesManager.IssueStatus.Unhidden, 'UnhiddenStubIssue2': IssuesManager.IssuesManager.IssueStatus.Hidden, }); - assert.deepStrictEqual(UnhiddenIssues, ['UnhiddenStubIssue1']); + assert.deepStrictEqual(unhiddenIssues, ['UnhiddenStubIssue1']); hideIssueByCodeSetting.set({ 'HiddenStubIssue1': IssuesManager.IssuesManager.IssueStatus.Hidden, @@ -295,7 +299,7 @@ describeWithMockConnection('IssuesManager', () => { 'UnhiddenStubIssue1': IssuesManager.IssuesManager.IssueStatus.Unhidden, 'UnhiddenStubIssue2': IssuesManager.IssuesManager.IssueStatus.Unhidden, }); - assert.deepStrictEqual(UnhiddenIssues, ['UnhiddenStubIssue1', 'UnhiddenStubIssue2']); + assert.deepStrictEqual(unhiddenIssues, ['UnhiddenStubIssue1', 'UnhiddenStubIssue2']); }); it('unhides all issues correctly', () => { @@ -319,18 +323,18 @@ describeWithMockConnection('IssuesManager', () => { 'UnhiddenStubIssue1': IssuesManager.IssuesManager.IssueStatus.Hidden, 'UnhiddenStubIssue2': IssuesManager.IssuesManager.IssueStatus.Hidden, }); - let UnhiddenIssues: string[] = []; + let unhiddenIssues: string[] = []; issuesManager.addEventListener(IssuesManager.IssuesManager.Events.FullUpdateRequired, () => { - UnhiddenIssues = []; + unhiddenIssues = []; for (const issue of issuesManager.issues()) { if (!issue.isHidden()) { - UnhiddenIssues.push(issue.code()); + unhiddenIssues.push(issue.code()); } } }); issuesManager.unhideAllIssues(); assert.deepStrictEqual( - UnhiddenIssues, ['HiddenStubIssue1', 'HiddenStubIssue2', 'UnhiddenStubIssue1', 'UnhiddenStubIssue2']); + unhiddenIssues, ['HiddenStubIssue1', 'HiddenStubIssue2', 'UnhiddenStubIssue1', 'UnhiddenStubIssue2']); }); it('send update event on scope change', async () => { diff --git a/test/unittests/front_end/models/issues_manager/LowTextContrastIssue.test.ts b/front_end/models/issues_manager/LowTextContrastIssue.test.ts similarity index 81% rename from test/unittests/front_end/models/issues_manager/LowTextContrastIssue.test.ts rename to front_end/models/issues_manager/LowTextContrastIssue.test.ts index 9e012cb025..3812b75e63 100644 --- a/test/unittests/front_end/models/issues_manager/LowTextContrastIssue.test.ts +++ b/front_end/models/issues_manager/LowTextContrastIssue.test.ts @@ -4,12 +4,12 @@ const {assert} = chai; -import * as Issues from '../../../../../front_end/panels/issues/issues.js'; -import * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; -import type * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import type * as Protocol from '../../../../../front_end/generated/protocol.js'; -import {MockIssuesModel} from './MockIssuesModel.js'; -import {MockIssuesManager} from './MockIssuesManager.js'; +import * as Issues from '../../panels/issues/issues.js'; +import * as IssuesManager from '../issues_manager/issues_manager.js'; +import type * as SDK from '../../core/sdk/sdk.js'; +import type * as Protocol from '../../generated/protocol.js'; +import {MockIssuesModel} from '../../../test/unittests/front_end/helpers/MockIssuesModel.js'; +import {MockIssuesManager} from '../../../test/unittests/front_end/helpers/MockIssuesManager.js'; describe('LowTextContrastIssue', async () => { it('aggregates multiple issues with duplicates correctly', () => { diff --git a/test/unittests/front_end/models/issues_manager/MarkdownIssueDescription.test.ts b/front_end/models/issues_manager/MarkdownIssueDescription.test.ts similarity index 97% rename from test/unittests/front_end/models/issues_manager/MarkdownIssueDescription.test.ts rename to front_end/models/issues_manager/MarkdownIssueDescription.test.ts index 972b643bf1..ec50fd746a 100644 --- a/test/unittests/front_end/models/issues_manager/MarkdownIssueDescription.test.ts +++ b/front_end/models/issues_manager/MarkdownIssueDescription.test.ts @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; +import * as IssuesManager from '../issues_manager/issues_manager.js'; const {assert} = chai; diff --git a/test/unittests/front_end/models/issues_manager/PropertyRuleIssue.test.ts b/front_end/models/issues_manager/PropertyRuleIssue.test.ts similarity index 87% rename from test/unittests/front_end/models/issues_manager/PropertyRuleIssue.test.ts rename to front_end/models/issues_manager/PropertyRuleIssue.test.ts index 2a7998f924..beb3ac54e4 100644 --- a/test/unittests/front_end/models/issues_manager/PropertyRuleIssue.test.ts +++ b/front_end/models/issues_manager/PropertyRuleIssue.test.ts @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import type * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; -import * as Issues from '../../../../../front_end/panels/issues/issues.js'; -import {describeWithLocale} from '../../helpers/EnvironmentHelpers.js'; -import {MockIssuesManager} from '../../models/issues_manager/MockIssuesManager.js'; -import {MockIssuesModel} from '../../models/issues_manager/MockIssuesModel.js'; +import {describeWithLocale} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {MockIssuesManager} from '../../../test/unittests/front_end/helpers/MockIssuesManager.js'; +import {MockIssuesModel} from '../../../test/unittests/front_end/helpers/MockIssuesModel.js'; +import type * as SDK from '../../core/sdk/sdk.js'; +import * as Protocol from '../../generated/protocol.js'; +import * as Issues from '../../panels/issues/issues.js'; +import * as IssuesManager from '../issues_manager/issues_manager.js'; function createProtocolIssue(propertyRuleIssueDetails: Protocol.Audits.PropertyRuleIssueDetails): Protocol.Audits.InspectorIssue { diff --git a/test/unittests/front_end/models/issues_manager/RelatedIssue.test.ts b/front_end/models/issues_manager/RelatedIssue.test.ts similarity index 88% rename from test/unittests/front_end/models/issues_manager/RelatedIssue.test.ts rename to front_end/models/issues_manager/RelatedIssue.test.ts index cb1978b9c8..f162092080 100644 --- a/test/unittests/front_end/models/issues_manager/RelatedIssue.test.ts +++ b/front_end/models/issues_manager/RelatedIssue.test.ts @@ -4,11 +4,11 @@ const {assert} = chai; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Platform from '../../../../../front_end/core/platform/platform.js'; -import type * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; -import {StubIssue} from './StubIssue.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as Platform from '../../core/platform/platform.js'; +import type * as Protocol from '../../generated/protocol.js'; +import * as IssuesManager from '../issues_manager/issues_manager.js'; +import {StubIssue} from '../../../test/unittests/front_end/helpers/StubIssue.js'; describe('issuesAssociatedWith', () => { const requestId1 = 'r0' as Protocol.Network.RequestId; diff --git a/test/unittests/front_end/models/issues_manager/StylesheetLoadingIssue.test.ts b/front_end/models/issues_manager/StylesheetLoadingIssue.test.ts similarity index 90% rename from test/unittests/front_end/models/issues_manager/StylesheetLoadingIssue.test.ts rename to front_end/models/issues_manager/StylesheetLoadingIssue.test.ts index 3e4c63b568..99441fbe27 100644 --- a/test/unittests/front_end/models/issues_manager/StylesheetLoadingIssue.test.ts +++ b/front_end/models/issues_manager/StylesheetLoadingIssue.test.ts @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Platform from '../../../../../front_end/core/platform/platform.js'; -import type * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; -import * as Issues from '../../../../../front_end/panels/issues/issues.js'; -import {describeWithLocale} from '../../helpers/EnvironmentHelpers.js'; -import {MockIssuesManager} from './MockIssuesManager.js'; -import {MockIssuesModel} from './MockIssuesModel.js'; +import {describeWithLocale} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {MockIssuesManager} from '../../../test/unittests/front_end/helpers/MockIssuesManager.js'; +import {MockIssuesModel} from '../../../test/unittests/front_end/helpers/MockIssuesModel.js'; +import * as Platform from '../../core/platform/platform.js'; +import type * as SDK from '../../core/sdk/sdk.js'; +import * as Protocol from '../../generated/protocol.js'; +import * as Issues from '../../panels/issues/issues.js'; +import * as IssuesManager from '../issues_manager/issues_manager.js'; function createProtocolIssue(stylesheetLoadingIssueDetails: Protocol.Audits.StylesheetLoadingIssueDetails): Protocol.Audits.InspectorIssue { diff --git a/front_end/models/javascript_metadata/BUILD.gn b/front_end/models/javascript_metadata/BUILD.gn index 009262f89b..927274e64b 100644 --- a/front_end/models/javascript_metadata/BUILD.gn +++ b/front_end/models/javascript_metadata/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("javascript_metadata") { @@ -24,10 +25,16 @@ devtools_entrypoint("bundle") { visibility = [ ":*", "../../../test/unittests/front_end/entrypoints/missing_entrypoints/*", - "../../../test/unittests/front_end/models/javascript_metadata/*", "../../ui/components/text_editor/*", "../../ui/legacy/components/object_ui/*", ] visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + sources = [ "JavaScriptMetadata.test.ts" ] + + deps = [ ":bundle" ] +} diff --git a/test/unittests/front_end/models/javascript_metadata/JavaScriptMetadata.test.ts b/front_end/models/javascript_metadata/JavaScriptMetadata.test.ts similarity index 95% rename from test/unittests/front_end/models/javascript_metadata/JavaScriptMetadata.test.ts rename to front_end/models/javascript_metadata/JavaScriptMetadata.test.ts index 3e527da3c1..abc8519220 100644 --- a/test/unittests/front_end/models/javascript_metadata/JavaScriptMetadata.test.ts +++ b/front_end/models/javascript_metadata/JavaScriptMetadata.test.ts @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as JavascriptMetadata from '../../../../../front_end/models/javascript_metadata/javascript_metadata.js'; +import * as JavascriptMetadata from './javascript_metadata.js'; describe('JavaScriptMetadata', () => { let metadata: JavascriptMetadata.JavaScriptMetadata.JavaScriptMetadataImpl; diff --git a/front_end/models/logs/BUILD.gn b/front_end/models/logs/BUILD.gn index af377ea4dc..7bf09c4281 100644 --- a/front_end/models/logs/BUILD.gn +++ b/front_end/models/logs/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("logs") { @@ -56,3 +57,19 @@ devtools_entrypoint("meta") { visibility = [ "../../entrypoints/*" ] } + +ts_library("unittests") { + testonly = true + + sources = [ + "NetworkLog.test.ts", + "RequestResolver.test.ts", + ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + "../../core/platform:bundle", + "../../core/sdk:bundle", + ] +} diff --git a/test/unittests/front_end/models/logs/NetworkLog.test.ts b/front_end/models/logs/NetworkLog.test.ts similarity index 96% rename from test/unittests/front_end/models/logs/NetworkLog.test.ts rename to front_end/models/logs/NetworkLog.test.ts index d5447b5fe5..c9bd9563bf 100644 --- a/test/unittests/front_end/models/logs/NetworkLog.test.ts +++ b/front_end/models/logs/NetworkLog.test.ts @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Common from '../../../../../front_end/core/common/common.js'; -import * as Platform from '../../../../../front_end/core/platform/platform.js'; -import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as Logs from '../../../../../front_end/models/logs/logs.js'; -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import * as Common from '../../core/common/common.js'; +import * as Platform from '../../core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../core/platform/platform.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as Protocol from '../../generated/protocol.js'; +import * as Logs from '../logs/logs.js'; const {assert} = chai; diff --git a/test/unittests/front_end/models/logs/RequestResolver.test.ts b/front_end/models/logs/RequestResolver.test.ts similarity index 93% rename from test/unittests/front_end/models/logs/RequestResolver.test.ts rename to front_end/models/logs/RequestResolver.test.ts index 12ac7bd03f..e3518666c3 100644 --- a/test/unittests/front_end/models/logs/RequestResolver.test.ts +++ b/front_end/models/logs/RequestResolver.test.ts @@ -4,10 +4,10 @@ const {assert} = chai; -import type * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import type * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as Logs from '../../../../../front_end/models/logs/logs.js'; -import {MockNetworkLog, createNetworkRequest} from './MockNetworkLog.js'; +import type * as SDK from '../../core/sdk/sdk.js'; +import type * as Protocol from '../../generated/protocol.js'; +import * as Logs from '../logs/logs.js'; +import {MockNetworkLog, createNetworkRequest} from '../../../test/unittests/front_end/helpers/MockNetworkLog.js'; describe('RequestResolver', () => { const requestId1 = 'foo' as Protocol.Network.RequestId; diff --git a/front_end/models/persistence/BUILD.gn b/front_end/models/persistence/BUILD.gn index f745230a80..41eacb7ef3 100644 --- a/front_end/models/persistence/BUILD.gn +++ b/front_end/models/persistence/BUILD.gn @@ -5,6 +5,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") import("../../../scripts/build/ninja/generate_css.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") generate_css("css_files") { @@ -61,6 +62,8 @@ devtools_entrypoint("bundle") { "../../panels/recorder/*", "../../panels/snippets/*", "../../panels/sources/*", + "../bindings:unittests", + "../workspace:unittests", "../workspace_diff/*", ] @@ -81,3 +84,20 @@ devtools_entrypoint("meta") { visibility = [ "../../entrypoints/*" ] } + +ts_library("unittests") { + testonly = true + + sources = [ + "NetworkPersistenceManager.test.ts", + "PersistenceImpl.test.ts", + "PlatformFileSystem.test.ts", + ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + "../../core/platform:bundle", + "../../core/sdk:bundle", + ] +} diff --git a/test/unittests/front_end/models/persistence/NetworkPersistenceManager.test.ts b/front_end/models/persistence/NetworkPersistenceManager.test.ts similarity index 97% rename from test/unittests/front_end/models/persistence/NetworkPersistenceManager.test.ts rename to front_end/models/persistence/NetworkPersistenceManager.test.ts index 5467bd5be9..55a1fa9789 100644 --- a/test/unittests/front_end/models/persistence/NetworkPersistenceManager.test.ts +++ b/front_end/models/persistence/NetworkPersistenceManager.test.ts @@ -4,17 +4,21 @@ const {assert} = chai; -import * as Common from '../../../../../front_end/core/common/common.js'; -import * as Host from '../../../../../front_end/core/host/host.js'; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Persistence from '../../../../../front_end/models/persistence/persistence.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; -import {createTarget, deinitializeGlobalVars, initializeGlobalVars} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; -import {createWorkspaceProject, setUpEnvironment} from '../../helpers/OverridesHelpers.js'; -import {createFileSystemUISourceCode} from '../../helpers/UISourceCodeHelpers.js'; +import * as Common from '../../core/common/common.js'; +import * as Host from '../../core/host/host.js'; +import type * as Platform from '../../core/platform/platform.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as Persistence from '../persistence/persistence.js'; +import * as Workspace from '../workspace/workspace.js'; +import * as Protocol from '../../generated/protocol.js'; +import { + createTarget, + deinitializeGlobalVars, + initializeGlobalVars, +} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import {createWorkspaceProject, setUpEnvironment} from '../../../test/unittests/front_end/helpers/OverridesHelpers.js'; +import {createFileSystemUISourceCode} from '../../../test/unittests/front_end/helpers/UISourceCodeHelpers.js'; const setUpEnvironmentWithUISourceCode = (url: string, resourceType: Common.ResourceType.ResourceType, project?: Workspace.Workspace.Project) => { diff --git a/test/unittests/front_end/models/persistence/PersistenceImpl.test.ts b/front_end/models/persistence/PersistenceImpl.test.ts similarity index 89% rename from test/unittests/front_end/models/persistence/PersistenceImpl.test.ts rename to front_end/models/persistence/PersistenceImpl.test.ts index f5455c64ba..583d66d806 100644 --- a/test/unittests/front_end/models/persistence/PersistenceImpl.test.ts +++ b/front_end/models/persistence/PersistenceImpl.test.ts @@ -3,23 +3,26 @@ // found in the LICENSE file. const {assert} = chai; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; -import * as Persistence from '../../../../../front_end/models/persistence/persistence.js'; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import * as Breakpoints from '../../../../../front_end/models/breakpoints/breakpoints.js'; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import type * as Protocol from '../../../../../front_end/generated/protocol.js'; -import {MockProtocolBackend} from '../../helpers/MockScopeChain.js'; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; +import * as Workspace from '../workspace/workspace.js'; +import * as Persistence from '../persistence/persistence.js'; +import * as Bindings from '../bindings/bindings.js'; +import * as Breakpoints from '../breakpoints/breakpoints.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import type * as Protocol from '../../generated/protocol.js'; +import {MockProtocolBackend} from '../../../test/unittests/front_end/helpers/MockScopeChain.js'; +import type * as Platform from '../../core/platform/platform.js'; import { describeWithMockConnection, -} from '../../helpers/MockConnection.js'; -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; +} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; -import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; -import {createFileSystemFileForPersistenceTests} from '../../helpers/PersistenceHelpers.js'; -import {createContentProviderUISourceCode, createFileSystemUISourceCode} from '../../helpers/UISourceCodeHelpers.js'; +import {assertNotNullOrUndefined} from '../../core/platform/platform.js'; +import {createFileSystemFileForPersistenceTests} from '../../../test/unittests/front_end/helpers/PersistenceHelpers.js'; +import { + createContentProviderUISourceCode, + createFileSystemUISourceCode, +} from '../../../test/unittests/front_end/helpers/UISourceCodeHelpers.js'; describeWithMockConnection('PersistenceImpl', () => { const FILE_SYSTEM_BREAK_ID = 'BREAK_ID' as Protocol.Debugger.BreakpointId; diff --git a/test/unittests/front_end/models/persistence/PlatformFileSystem.test.ts b/front_end/models/persistence/PlatformFileSystem.test.ts similarity index 80% rename from test/unittests/front_end/models/persistence/PlatformFileSystem.test.ts rename to front_end/models/persistence/PlatformFileSystem.test.ts index d88d33ad13..d6ae416a84 100644 --- a/test/unittests/front_end/models/persistence/PlatformFileSystem.test.ts +++ b/front_end/models/persistence/PlatformFileSystem.test.ts @@ -4,8 +4,8 @@ const {assert} = chai; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as Persistence from '../../../../../front_end/models/persistence/persistence.js'; +import type * as Platform from '../../core/platform/platform.js'; +import * as Persistence from '../persistence/persistence.js'; describe('PlatformFileSystem', () => { it('can be instantiated successfully', () => { diff --git a/front_end/models/source_map_scopes/BUILD.gn b/front_end/models/source_map_scopes/BUILD.gn index 924e09db0f..d1f7dd3e72 100644 --- a/front_end/models/source_map_scopes/BUILD.gn +++ b/front_end/models/source_map_scopes/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("source_map_scopes") { @@ -41,3 +42,19 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + sources = [ + "NamesResolver.test.ts", + "ScopeTreeCache.test.ts", + ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + "../../core/platform:bundle", + "../../core/sdk:bundle", + "../formatter:bundle", + ] +} diff --git a/test/unittests/front_end/models/source_map_scopes/NamesResolver.test.ts b/front_end/models/source_map_scopes/NamesResolver.test.ts similarity index 97% rename from test/unittests/front_end/models/source_map_scopes/NamesResolver.test.ts rename to front_end/models/source_map_scopes/NamesResolver.test.ts index b799a5e427..47433504ec 100644 --- a/test/unittests/front_end/models/source_map_scopes/NamesResolver.test.ts +++ b/front_end/models/source_map_scopes/NamesResolver.test.ts @@ -4,16 +4,16 @@ const {assert} = chai; -import * as SourceMapScopes from '../../../../../front_end/models/source_map_scopes/source_map_scopes.js'; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as Root from '../../../../../front_end/core/root/root.js'; -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {MockProtocolBackend} from '../../helpers/MockScopeChain.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; -import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; +import * as SourceMapScopes from '../source_map_scopes/source_map_scopes.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as Workspace from '../workspace/workspace.js'; +import * as Bindings from '../bindings/bindings.js'; +import type * as Platform from '../../core/platform/platform.js'; +import * as Root from '../../core/root/root.js'; +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {MockProtocolBackend} from '../../../test/unittests/front_end/helpers/MockScopeChain.js'; +import {describeWithMockConnection} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import {assertNotNullOrUndefined} from '../../core/platform/platform.js'; describeWithMockConnection('NameResolver', () => { const URL = 'file:///tmp/example.js' as Platform.DevToolsPath.UrlString; diff --git a/test/unittests/front_end/models/source_map_scopes/ScopeTreeCache.test.ts b/front_end/models/source_map_scopes/ScopeTreeCache.test.ts similarity index 88% rename from test/unittests/front_end/models/source_map_scopes/ScopeTreeCache.test.ts rename to front_end/models/source_map_scopes/ScopeTreeCache.test.ts index 0ac037dda4..a2cc5aa2f7 100644 --- a/test/unittests/front_end/models/source_map_scopes/ScopeTreeCache.test.ts +++ b/front_end/models/source_map_scopes/ScopeTreeCache.test.ts @@ -4,10 +4,10 @@ const {assert} = chai; -import * as SourceMapScopes from '../../../../../front_end/models/source_map_scopes/source_map_scopes.js'; -import * as Formatter from '../../../../../front_end/models/formatter/formatter.js'; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Platform from '../../../../../front_end/core/platform/platform.js'; +import * as SourceMapScopes from '../source_map_scopes/source_map_scopes.js'; +import * as Formatter from '../formatter/formatter.js'; +import * as SDK from '../../core/sdk/sdk.js'; +import * as Platform from '../../core/platform/platform.js'; describe('ScopeTreeCache', () => { describe('scopeTreeForScript', () => { diff --git a/front_end/models/text_utils/BUILD.gn b/front_end/models/text_utils/BUILD.gn index 7f35704a21..e442d082f8 100644 --- a/front_end/models/text_utils/BUILD.gn +++ b/front_end/models/text_utils/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("text_utils") { @@ -53,3 +54,22 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ + "ContentData.test.ts", + "StaticContentProvider.test.ts", + "StreamingContentData.test.ts", + "Text.test.ts", + "TextCursor.test.ts", + "TextRange.test.ts", + "TextUtils.test.ts", + ] + + deps = [ + ":bundle", + "../../core/platform:bundle", + ] +} diff --git a/test/unittests/front_end/models/text_utils/ContentData.test.ts b/front_end/models/text_utils/ContentData.test.ts similarity index 96% rename from test/unittests/front_end/models/text_utils/ContentData.test.ts rename to front_end/models/text_utils/ContentData.test.ts index 9e2a344376..2c1e235660 100644 --- a/test/unittests/front_end/models/text_utils/ContentData.test.ts +++ b/front_end/models/text_utils/ContentData.test.ts @@ -2,8 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as TextUtils from '../../../../../front_end/models/text_utils/text_utils.js'; +import * as Platform from '../../core/platform/platform.js'; + +import * as TextUtils from './text_utils.js'; describe('ContentData', () => { const {ContentData} = TextUtils.ContentData; diff --git a/test/unittests/front_end/models/text_utils/StaticContentProvider.test.ts b/front_end/models/text_utils/StaticContentProvider.test.ts similarity index 81% rename from test/unittests/front_end/models/text_utils/StaticContentProvider.test.ts rename to front_end/models/text_utils/StaticContentProvider.test.ts index 45b19664bb..d19026544c 100644 --- a/test/unittests/front_end/models/text_utils/StaticContentProvider.test.ts +++ b/front_end/models/text_utils/StaticContentProvider.test.ts @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Common from '../../../../../front_end/core/common/common.js'; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as TextUtils from '../../../../../front_end/models/text_utils/text_utils.js'; +import * as Common from '../../core/common/common.js'; +import type * as Platform from '../../core/platform/platform.js'; + +import * as TextUtils from './text_utils.js'; const {assert} = chai; diff --git a/test/unittests/front_end/models/text_utils/StreamingContentData.test.ts b/front_end/models/text_utils/StreamingContentData.test.ts similarity index 97% rename from test/unittests/front_end/models/text_utils/StreamingContentData.test.ts rename to front_end/models/text_utils/StreamingContentData.test.ts index c7aea08000..e447c193b6 100644 --- a/test/unittests/front_end/models/text_utils/StreamingContentData.test.ts +++ b/front_end/models/text_utils/StreamingContentData.test.ts @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as TextUtils from '../../../../../front_end/models/text_utils/text_utils.js'; +import * as TextUtils from './text_utils.js'; describe('StreamingContentData', () => { it('notifies listeners when new chunks are added', () => { diff --git a/test/unittests/front_end/models/text_utils/Text.test.ts b/front_end/models/text_utils/Text.test.ts similarity index 98% rename from test/unittests/front_end/models/text_utils/Text.test.ts rename to front_end/models/text_utils/Text.test.ts index d7ea4d66f1..2ce1d62181 100644 --- a/test/unittests/front_end/models/text_utils/Text.test.ts +++ b/front_end/models/text_utils/Text.test.ts @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -const {assert} = chai; +import * as TextUtils from './text_utils.js'; -import * as TextUtils from '../../../../../front_end/models/text_utils/text_utils.js'; +const {assert} = chai; describe('Text', () => { it('can be instantiated successfully', () => { diff --git a/test/unittests/front_end/models/text_utils/TextCursor.test.ts b/front_end/models/text_utils/TextCursor.test.ts similarity index 95% rename from test/unittests/front_end/models/text_utils/TextCursor.test.ts rename to front_end/models/text_utils/TextCursor.test.ts index f3f936e38a..a7685281b8 100644 --- a/test/unittests/front_end/models/text_utils/TextCursor.test.ts +++ b/front_end/models/text_utils/TextCursor.test.ts @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -const {assert} = chai; +import * as TextUtils from './text_utils.js'; -import * as TextUtils from '../../../../../front_end/models/text_utils/text_utils.js'; +const {assert} = chai; describe('TextCursor', () => { it('can be instantiated successfully', () => { diff --git a/test/unittests/front_end/models/text_utils/TextRange.test.ts b/front_end/models/text_utils/TextRange.test.ts similarity index 99% rename from test/unittests/front_end/models/text_utils/TextRange.test.ts rename to front_end/models/text_utils/TextRange.test.ts index be9ad3c1c1..b89eea0036 100644 --- a/test/unittests/front_end/models/text_utils/TextRange.test.ts +++ b/front_end/models/text_utils/TextRange.test.ts @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -const {assert} = chai; +import * as TextUtils from './text_utils.js'; -import * as TextUtils from '../../../../../front_end/models/text_utils/text_utils.js'; +const {assert} = chai; interface ExpectedTextRange { startLine: number; diff --git a/test/unittests/front_end/models/text_utils/TextUtils.test.ts b/front_end/models/text_utils/TextUtils.test.ts similarity index 99% rename from test/unittests/front_end/models/text_utils/TextUtils.test.ts rename to front_end/models/text_utils/TextUtils.test.ts index a0b6773660..1e42810ea6 100644 --- a/test/unittests/front_end/models/text_utils/TextUtils.test.ts +++ b/front_end/models/text_utils/TextUtils.test.ts @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -const {assert} = chai; +import * as TextUtils from './text_utils.js'; -import * as TextUtils from '../../../../../front_end/models/text_utils/text_utils.js'; +const {assert} = chai; describe('TextUtils', () => { describe('Utils', () => { diff --git a/front_end/models/timeline_model/BUILD.gn b/front_end/models/timeline_model/BUILD.gn index ec005b5d0e..c8490f0940 100644 --- a/front_end/models/timeline_model/BUILD.gn +++ b/front_end/models/timeline_model/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("timeline_model") { @@ -42,3 +43,19 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ + "TimelineModel.test.ts", + "TimelineModelFilter.test.ts", + "TimelineProfileTree.test.ts", + ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + "../trace:bundle", + ] +} diff --git a/test/unittests/front_end/models/timeline_model/TimelineModel.test.ts b/front_end/models/timeline_model/TimelineModel.test.ts similarity index 97% rename from test/unittests/front_end/models/timeline_model/TimelineModel.test.ts rename to front_end/models/timeline_model/TimelineModel.test.ts index be3abd1136..4a5962abc8 100644 --- a/test/unittests/front_end/models/timeline_model/TimelineModel.test.ts +++ b/front_end/models/timeline_model/TimelineModel.test.ts @@ -4,17 +4,17 @@ const {assert} = chai; -import * as Platform from '../../../../../front_end/core/platform/platform.js'; -import type * as Protocol from '../../../../../front_end/generated/protocol.js'; -import * as TimelineModel from '../../../../../front_end/models/timeline_model/timeline_model.js'; -import * as TraceEngine from '../../../../../front_end/models/trace/trace.js'; -import {describeWithEnvironment} from '../../helpers/EnvironmentHelpers.js'; +import * as Platform from '../../core/platform/platform.js'; +import type * as Protocol from '../../generated/protocol.js'; +import * as TimelineModel from '../timeline_model/timeline_model.js'; +import * as TraceEngine from '../trace/trace.js'; +import {describeWithEnvironment} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; import { DevToolsTimelineCategory, makeFakeSDKEventFromPayload, StubbedThread, -} from '../../helpers/TraceHelpers.js'; -import {TraceLoader} from '../../helpers/TraceLoader.js'; +} from '../../../test/unittests/front_end/helpers/TraceHelpers.js'; +import {TraceLoader} from '../../../test/unittests/front_end/helpers/TraceLoader.js'; // Various events listing processes and threads used by all the tests. const preamble = [ diff --git a/test/unittests/front_end/models/timeline_model/TimelineModelFilter.test.ts b/front_end/models/timeline_model/TimelineModelFilter.test.ts similarity index 95% rename from test/unittests/front_end/models/timeline_model/TimelineModelFilter.test.ts rename to front_end/models/timeline_model/TimelineModelFilter.test.ts index e9a2c1e6f5..8c9c40a371 100644 --- a/test/unittests/front_end/models/timeline_model/TimelineModelFilter.test.ts +++ b/front_end/models/timeline_model/TimelineModelFilter.test.ts @@ -4,12 +4,12 @@ const {assert} = chai; -import * as TraceEngine from '../../../../../front_end/models/trace/trace.js'; -import * as TimelineModel from '../../../../../front_end/models/timeline_model/timeline_model.js'; +import * as TraceEngine from '../trace/trace.js'; +import * as TimelineModel from '../timeline_model/timeline_model.js'; import { DevToolsTimelineCategory, makeFakeSDKEventFromPayload, -} from '../../helpers/TraceHelpers.js'; +} from '../../../test/unittests/front_end/helpers/TraceHelpers.js'; const consoleEvent = makeFakeSDKEventFromPayload({ categories: [DevToolsTimelineCategory, TimelineModel.TimelineModel.TimelineModelImpl.Category.Console], diff --git a/test/unittests/front_end/models/timeline_model/TimelineProfileTree.test.ts b/front_end/models/timeline_model/TimelineProfileTree.test.ts similarity index 96% rename from test/unittests/front_end/models/timeline_model/TimelineProfileTree.test.ts rename to front_end/models/timeline_model/TimelineProfileTree.test.ts index 2a4e46c5da..510de6d726 100644 --- a/test/unittests/front_end/models/timeline_model/TimelineProfileTree.test.ts +++ b/front_end/models/timeline_model/TimelineProfileTree.test.ts @@ -2,15 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -const {assert} = chai; +import {describeWithEnvironment} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import { + getMainThread, + makeCompleteEvent, + makeProfileCall, +} from '../../../test/unittests/front_end/helpers/TraceHelpers.js'; +import {TraceLoader} from '../../../test/unittests/front_end/helpers/TraceLoader.js'; +import type * as Protocol from '../../generated/protocol.js'; +import * as Timeline from '../../panels/timeline/timeline.js'; +import * as TimelineModel from '../timeline_model/timeline_model.js'; +import * as TraceEngine from '../trace/trace.js'; -import * as TimelineModel from '../../../../../front_end/models/timeline_model/timeline_model.js'; -import * as TraceEngine from '../../../../../front_end/models/trace/trace.js'; -import * as Timeline from '../../../../../front_end/panels/timeline/timeline.js'; -import type * as Protocol from '../../../../../front_end/generated/protocol.js'; -import {describeWithEnvironment} from '../../helpers/EnvironmentHelpers.js'; -import {getMainThread, makeCompleteEvent, makeProfileCall} from '../../helpers/TraceHelpers.js'; -import {TraceLoader} from '../../helpers/TraceLoader.js'; +const {assert} = chai; describeWithEnvironment('TimelineProfileTree', () => { describe('TopDownRootNode', () => { diff --git a/front_end/models/trace/BUILD.gn b/front_end/models/trace/BUILD.gn index 42a8160a99..0fa4caa5fe 100644 --- a/front_end/models/trace/BUILD.gn +++ b/front_end/models/trace/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("trace") { @@ -44,7 +45,25 @@ devtools_entrypoint("bundle") { "../../services/tracing/*", "../../ui/components/docs/*", "../timeline_model/*", + "./*", ] visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ + "EntriesFilter.test.ts", + "LegacyTracingModel.test.ts", + "ModelImpl.test.ts", + "Processor.test.ts", + "TracingManager.test.ts", + ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + ] +} diff --git a/test/unittests/front_end/models/trace/EntriesFilter.test.ts b/front_end/models/trace/EntriesFilter.test.ts similarity index 99% rename from test/unittests/front_end/models/trace/EntriesFilter.test.ts rename to front_end/models/trace/EntriesFilter.test.ts index 44b66e3633..adaa25a23a 100644 --- a/test/unittests/front_end/models/trace/EntriesFilter.test.ts +++ b/front_end/models/trace/EntriesFilter.test.ts @@ -6,8 +6,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as TraceEngine from '../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../helpers/TraceLoader.js'; +import {TraceLoader} from '../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as TraceEngine from '../trace/trace.js'; function getMainThread(data: TraceEngine.Handlers.ModelHandlers.Renderer.RendererHandlerData): TraceEngine.Handlers.ModelHandlers.Renderer.RendererThread { diff --git a/test/unittests/front_end/models/trace/LegacyTracingModel.test.ts b/front_end/models/trace/LegacyTracingModel.test.ts similarity index 97% rename from test/unittests/front_end/models/trace/LegacyTracingModel.test.ts rename to front_end/models/trace/LegacyTracingModel.test.ts index 8a1b331127..8bce65a42f 100644 --- a/test/unittests/front_end/models/trace/LegacyTracingModel.test.ts +++ b/front_end/models/trace/LegacyTracingModel.test.ts @@ -4,13 +4,13 @@ const {assert} = chai; -import * as TraceEngine from '../../../../../front_end/models/trace/trace.js'; -import {describeWithEnvironment} from '../../helpers/EnvironmentHelpers.js'; +import * as TraceEngine from '../trace/trace.js'; +import {describeWithEnvironment} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; import { StubbedThread, makeFakeEventPayload, -} from '../../helpers/TraceHelpers.js'; -import {TraceLoader} from '../../helpers/TraceLoader.js'; +} from '../../../test/unittests/front_end/helpers/TraceHelpers.js'; +import {TraceLoader} from '../../../test/unittests/front_end/helpers/TraceLoader.js'; describeWithEnvironment('TracingModel', function() { it('can create events from an EventPayload[] and finds the correct number of processes', async function() { diff --git a/test/unittests/front_end/models/trace/ModelImpl.test.ts b/front_end/models/trace/ModelImpl.test.ts similarity index 94% rename from test/unittests/front_end/models/trace/ModelImpl.test.ts rename to front_end/models/trace/ModelImpl.test.ts index 42386aeec0..58bdd9ece5 100644 --- a/test/unittests/front_end/models/trace/ModelImpl.test.ts +++ b/front_end/models/trace/ModelImpl.test.ts @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as TraceModel from '../../../../../front_end/models/trace/trace.js'; -import {describeWithEnvironment} from '../../helpers/EnvironmentHelpers.js'; -import {TraceLoader} from '../../helpers/TraceLoader.js'; +import {describeWithEnvironment} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {TraceLoader} from '../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as TraceModel from '../trace/trace.js'; const {assert} = chai; diff --git a/test/unittests/front_end/models/trace/Processor.test.ts b/front_end/models/trace/Processor.test.ts similarity index 97% rename from test/unittests/front_end/models/trace/Processor.test.ts rename to front_end/models/trace/Processor.test.ts index 32a2f1ca41..52baed83c2 100644 --- a/test/unittests/front_end/models/trace/Processor.test.ts +++ b/front_end/models/trace/Processor.test.ts @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as TraceModel from '../../../../../front_end/models/trace/trace.js'; -import {describeWithEnvironment} from '../../helpers/EnvironmentHelpers.js'; -import {TraceLoader} from '../../helpers/TraceLoader.js'; +import {describeWithEnvironment} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {TraceLoader} from '../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as TraceModel from '../trace/trace.js'; const {assert} = chai; diff --git a/test/unittests/front_end/models/trace/TracingManager.test.ts b/front_end/models/trace/TracingManager.test.ts similarity index 93% rename from test/unittests/front_end/models/trace/TracingManager.test.ts rename to front_end/models/trace/TracingManager.test.ts index 5da93c5416..e6c9b3b192 100644 --- a/test/unittests/front_end/models/trace/TracingManager.test.ts +++ b/front_end/models/trace/TracingManager.test.ts @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as TraceEngine from '../../../../../front_end/models/trace/trace.js'; -import {createTarget} from '../../helpers/EnvironmentHelpers.js'; +import {createTarget} from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; import { describeWithMockConnection, setMockConnectionResponseHandler, -} from '../../helpers/MockConnection.js'; -import {makeFakeEventPayload} from '../../helpers/TraceHelpers.js'; +} from '../../../test/unittests/front_end/helpers/MockConnection.js'; +import {makeFakeEventPayload} from '../../../test/unittests/front_end/helpers/TraceHelpers.js'; +import * as TraceEngine from '../trace/trace.js'; class FakeClient implements TraceEngine.TracingManager.TracingManagerClient { traceEventsCollected(_events: TraceEngine.TracingManager.EventPayload[]): void { diff --git a/front_end/models/trace/extras/BUILD.gn b/front_end/models/trace/extras/BUILD.gn index 80891ddc7d..9f4f0ea789 100644 --- a/front_end/models/trace/extras/BUILD.gn +++ b/front_end/models/trace/extras/BUILD.gn @@ -4,6 +4,7 @@ import("../../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../../scripts/build/ninja/devtools_module.gni") +import("../../../../third_party/typescript/typescript.gni") import("../../visibility.gni") devtools_module("extras") { @@ -33,3 +34,20 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ + "FetchNodes.test.ts", + "FilmStrip.test.ts", + "MainThreadActivity.test.ts", + "Metadata.test.ts", + ] + + deps = [ + "../../../../test/unittests/front_end/helpers", + "../../../core/platform:bundle", + "../../../models/trace:bundle", + ] +} diff --git a/test/unittests/front_end/models/trace/extras/FetchNodes.test.ts b/front_end/models/trace/extras/FetchNodes.test.ts similarity index 94% rename from test/unittests/front_end/models/trace/extras/FetchNodes.test.ts rename to front_end/models/trace/extras/FetchNodes.test.ts index b638605b4f..7aed499f1c 100644 --- a/test/unittests/front_end/models/trace/extras/FetchNodes.test.ts +++ b/front_end/models/trace/extras/FetchNodes.test.ts @@ -4,18 +4,18 @@ const {assert} = chai; -import * as SDK from '../../../../../../front_end/core/sdk/sdk.js'; -import * as TraceEngine from '../../../../../../front_end/models/trace/trace.js'; -import {assertNotNullOrUndefined} from '../../../../../../front_end/core/platform/platform.js'; -import type * as Protocol from '../../../../../../front_end/generated/protocol.js'; -import {createTarget} from '../../../helpers/EnvironmentHelpers.js'; +import * as SDK from '../../../core/sdk/sdk.js'; +import * as TraceEngine from '../trace.js'; +import {assertNotNullOrUndefined} from '../../../core/platform/platform.js'; +import type * as Protocol from '../../../generated/protocol.js'; +import {createTarget} from '../../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; import { clearAllMockConnectionResponseHandlers, clearMockConnectionResponseHandler, describeWithMockConnection, setMockConnectionResponseHandler, -} from '../../../helpers/MockConnection.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +} from '../../../../test/unittests/front_end/helpers/MockConnection.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; function nodeId(x: number): T { return x as T; diff --git a/test/unittests/front_end/models/trace/extras/FilmStrip.test.ts b/front_end/models/trace/extras/FilmStrip.test.ts similarity index 94% rename from test/unittests/front_end/models/trace/extras/FilmStrip.test.ts rename to front_end/models/trace/extras/FilmStrip.test.ts index 5006568460..ecaa2cd70c 100644 --- a/test/unittests/front_end/models/trace/extras/FilmStrip.test.ts +++ b/front_end/models/trace/extras/FilmStrip.test.ts @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as TraceEngine from '../../../../../../front_end/models/trace/trace.js'; -import {describeWithEnvironment} from '../../../helpers/EnvironmentHelpers.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import {describeWithEnvironment} from '../../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as TraceEngine from '../trace.js'; const {assert} = chai; diff --git a/test/unittests/front_end/models/trace/extras/MainThreadActivity.test.ts b/front_end/models/trace/extras/MainThreadActivity.test.ts similarity index 97% rename from test/unittests/front_end/models/trace/extras/MainThreadActivity.test.ts rename to front_end/models/trace/extras/MainThreadActivity.test.ts index bae201e6b5..e9b321f68e 100644 --- a/test/unittests/front_end/models/trace/extras/MainThreadActivity.test.ts +++ b/front_end/models/trace/extras/MainThreadActivity.test.ts @@ -2,8 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as TraceEngine from '../../../../../../front_end/models/trace/trace.js'; -import {type FakeEventPayload, makeFakeEventPayload} from '../../../helpers/TraceHelpers.js'; +import { + type FakeEventPayload, + makeFakeEventPayload, +} from '../../../../test/unittests/front_end/helpers/TraceHelpers.js'; +import * as TraceEngine from '../trace.js'; const {assert} = chai; diff --git a/test/unittests/front_end/models/trace/extras/Metadata.test.ts b/front_end/models/trace/extras/Metadata.test.ts similarity index 93% rename from test/unittests/front_end/models/trace/extras/Metadata.test.ts rename to front_end/models/trace/extras/Metadata.test.ts index 366cb4d5e3..151104bca9 100644 --- a/test/unittests/front_end/models/trace/extras/Metadata.test.ts +++ b/front_end/models/trace/extras/Metadata.test.ts @@ -4,9 +4,9 @@ const {assert} = chai; -import * as SDK from '../../../../../../front_end/core/sdk/sdk.js'; -import * as TraceEngine from '../../../../../../front_end/models/trace/trace.js'; -import {describeWithEnvironment} from '../../../helpers/EnvironmentHelpers.js'; +import * as SDK from '../../../core/sdk/sdk.js'; +import * as TraceEngine from '../trace.js'; +import {describeWithEnvironment} from '../../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; describeWithEnvironment('Trace Metadata', () => { it('returns the associated metadata', async () => { const cpuThrottlingManager = SDK.CPUThrottlingManager.CPUThrottlingManager.instance({forceNew: true}); diff --git a/test/unittests/front_end/models/trace/handlers/AnimationHandler.test.ts b/front_end/models/trace/handlers/AnimationHandler.test.ts similarity index 93% rename from test/unittests/front_end/models/trace/handlers/AnimationHandler.test.ts rename to front_end/models/trace/handlers/AnimationHandler.test.ts index b85fcafd92..7d83de97c9 100644 --- a/test/unittests/front_end/models/trace/handlers/AnimationHandler.test.ts +++ b/front_end/models/trace/handlers/AnimationHandler.test.ts @@ -3,8 +3,8 @@ // found in the LICENSE file. const {assert} = chai; -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import * as TraceModel from '../trace.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; describe('AnimationHandler', function() { it('calculates the amount of animation events correctly', async function() { diff --git a/test/unittests/front_end/models/trace/handlers/AuctionWorkletsHandler.test.ts b/front_end/models/trace/handlers/AuctionWorkletsHandler.test.ts similarity index 98% rename from test/unittests/front_end/models/trace/handlers/AuctionWorkletsHandler.test.ts rename to front_end/models/trace/handlers/AuctionWorkletsHandler.test.ts index 67003d9273..3ae12cb305 100644 --- a/test/unittests/front_end/models/trace/handlers/AuctionWorkletsHandler.test.ts +++ b/front_end/models/trace/handlers/AuctionWorkletsHandler.test.ts @@ -3,8 +3,8 @@ // found in the LICENSE file. const {assert} = chai; -import * as TraceEngine from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import * as TraceEngine from '../trace.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; describe('AuctionWorkletsHandler', function() { beforeEach(() => { diff --git a/front_end/models/trace/handlers/BUILD.gn b/front_end/models/trace/handlers/BUILD.gn index 21a5e2a00c..a126a7f81b 100644 --- a/front_end/models/trace/handlers/BUILD.gn +++ b/front_end/models/trace/handlers/BUILD.gn @@ -4,6 +4,7 @@ import("../../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../../scripts/build/ninja/devtools_module.gni") +import("../../../../third_party/typescript/typescript.gni") import("../../visibility.gni") devtools_module("handlers") { @@ -53,3 +54,40 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ + "AnimationHandler.test.ts", + "AuctionWorkletsHandler.test.ts", + "FramesHandler.test.ts", + "GPUHandler.test.ts", + "InitiatorsHandler.test.ts", + "InvalidationsHandler.test.ts", + "LargestImagePaintHandler.test.ts", + "LargestTextPaintHandler.test.ts", + "LayerTreeHandler.test.ts", + "LayoutShiftsHandler.test.ts", + "MemoryHandler.test.ts", + "MetaHandler.test.ts", + "NetworkRequestsHandler.test.ts", + "PageLoadMetricsHandler.test.ts", + "RendererHandler.test.ts", + "SamplesHandler.test.ts", + "ScreenshotsHandler.test.ts", + "Threads.test.ts", + "UserInteractionsHandler.test.ts", + "UserTimingsHandler.test.ts", + "WarningsHandler.test.ts", + "WorkersHandler.test.ts", + ] + + deps = [ + "../../../../test/unittests/front_end/helpers", + "../../../core/platform:bundle", + "../../../generated", + "../../../models/trace:bundle", + "../../../panels/timeline:bundle", + ] +} diff --git a/test/unittests/front_end/models/timeline_model/TimelineFrameBeginFrameQueue.test.ts b/front_end/models/trace/handlers/FramesHandler.test.ts similarity index 69% rename from test/unittests/front_end/models/timeline_model/TimelineFrameBeginFrameQueue.test.ts rename to front_end/models/trace/handlers/FramesHandler.test.ts index 0733b5f6c1..e1391b2788 100644 --- a/test/unittests/front_end/models/timeline_model/TimelineFrameBeginFrameQueue.test.ts +++ b/front_end/models/trace/handlers/FramesHandler.test.ts @@ -1,14 +1,101 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2023 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. const {assert} = chai; +import * as TraceEngine from '../trace.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import {describeWithMockConnection} from '../../../../test/unittests/front_end/helpers/MockConnection.js'; -// TODO(jacktfranklin): move these tests into the models/trace tests folder. +async function processTrace(events: readonly TraceEngine.Types.TraceEvents.TraceEventData[]): Promise { + // The FramesHandler depends on a few other handlers, so we run all of them as part of these tests. + const handlersInOrder: TraceEngine.Handlers.Types.TraceEventHandlerName[] = [ + 'Meta', + 'Samples', + 'AuctionWorklets', + 'Renderer', + 'LayerTree', + 'Frames', + ]; + for (const handlerName of handlersInOrder) { + const handler = TraceEngine.Handlers.ModelHandlers[handlerName]; + handler.reset(); + if ('initialize' in handler) { + handler.initialize(); + } + } + for (const event of events) { + for (const handlerName of handlersInOrder) { + TraceEngine.Handlers.ModelHandlers[handlerName].handleEvent(event); + } + } + for (const handlerName of handlersInOrder) { + const handler = TraceEngine.Handlers.ModelHandlers[handlerName]; + if ('finalize' in handler) { + await handler.finalize(); + } + } +} -import * as TraceEngine from '../../../../../front_end/models/trace/trace.js'; +describeWithMockConnection('FramesHandler', () => { + it('can parse out a trace and return the frames', async function() { + const rawEvents = await TraceLoader.rawEvents(this, 'web-dev-with-commit.json.gz'); + await processTrace(rawEvents); -describe('TimelineFrameBeginFrameQueue', () => { + const parsedFrames = TraceEngine.Handlers.ModelHandlers.Frames.data().frames; + assert.lengthOf(parsedFrames, 18); + + // Assert a couple of frames to check the data, including one that is partial and was dropped. + assert.strictEqual(parsedFrames[0].startTime, 122411104714); + assert.strictEqual(parsedFrames[0].duration, 37847); + assert.isFalse(parsedFrames[0].isPartial); + assert.isFalse(parsedFrames[0].isPartial); + + assert.strictEqual(parsedFrames[2].startTime, 122411159244); + assert.strictEqual(parsedFrames[2].duration, 16683); + assert.isTrue(parsedFrames[2].isPartial); + assert.isTrue(parsedFrames[2].dropped); + }); + + it('can create LayerPaintEvents from Paint and snapshot events', async function() { + // Advanced instrumentation trace file is large: allow the bots more time + // to process it. + this.timeout(20_000); + + const rawEvents = await TraceLoader.rawEvents(this, 'web-dev-with-advanced-instrumentation.json.gz'); + await processTrace(rawEvents); + const parsedFrames = TraceEngine.Handlers.ModelHandlers.Frames.data().frames; + assert.lengthOf(parsedFrames, 25); + const frameWithPaints = parsedFrames.at(2); + if (!frameWithPaints) { + throw new Error('Could not find frame at index 2'); + } + // Check we have the right one. + assert.strictEqual(frameWithPaints.seqId, 1127448); + assert.lengthOf(frameWithPaints.paints, 7); + }); + + it('can return frames within a given window', async function() { + const rawEvents = await TraceLoader.rawEvents(this, 'web-dev-with-commit.json.gz'); + await processTrace(rawEvents); + + const parsedFrames = TraceEngine.Handlers.ModelHandlers.Frames.data().frames; + assert.lengthOf(parsedFrames, 18); + + const startTime = TraceEngine.Types.Timing.MicroSeconds(parsedFrames[0].startTime); + const endTime = TraceEngine.Types.Timing.MicroSeconds(parsedFrames[3].endTime); + const framesWithinWindow = + TraceEngine.Handlers.ModelHandlers.Frames.framesWithinWindow(parsedFrames, startTime, endTime); + assert.deepEqual(framesWithinWindow, [ + parsedFrames[0], + parsedFrames[1], + parsedFrames[2], + parsedFrames[3], + ]); + }); +}); + +describe('FramesHandler', () => { it('visualizes zero frames when no BeginFrames are added', () => { const beginFrameQueue = new TraceEngine.Handlers.ModelHandlers.Frames.TimelineFrameBeginFrameQueue(); const framesToVisualize = beginFrameQueue.processPendingBeginFramesOnDrawFrame(100); diff --git a/test/unittests/front_end/models/trace/handlers/GPUHandler.test.ts b/front_end/models/trace/handlers/GPUHandler.test.ts similarity index 86% rename from test/unittests/front_end/models/trace/handlers/GPUHandler.test.ts rename to front_end/models/trace/handlers/GPUHandler.test.ts index 4469088c8a..90ca922182 100644 --- a/test/unittests/front_end/models/trace/handlers/GPUHandler.test.ts +++ b/front_end/models/trace/handlers/GPUHandler.test.ts @@ -3,8 +3,8 @@ // found in the LICENSE file. const {assert} = chai; -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import * as TraceModel from '../trace.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; describe('GPUHandler', function() { beforeEach(() => { diff --git a/test/unittests/front_end/models/trace/handlers/InitiatorsHandler.test.ts b/front_end/models/trace/handlers/InitiatorsHandler.test.ts similarity index 98% rename from test/unittests/front_end/models/trace/handlers/InitiatorsHandler.test.ts rename to front_end/models/trace/handlers/InitiatorsHandler.test.ts index de4b986d00..9f15fec7b8 100644 --- a/test/unittests/front_end/models/trace/handlers/InitiatorsHandler.test.ts +++ b/front_end/models/trace/handlers/InitiatorsHandler.test.ts @@ -3,8 +3,8 @@ // found in the LICENSE file. const {assert} = chai; -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import * as TraceModel from '../trace.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; describe('InitiatorsHandler', () => { beforeEach(() => { diff --git a/test/unittests/front_end/models/trace/handlers/InvalidationsHandler.test.ts b/front_end/models/trace/handlers/InvalidationsHandler.test.ts similarity index 95% rename from test/unittests/front_end/models/trace/handlers/InvalidationsHandler.test.ts rename to front_end/models/trace/handlers/InvalidationsHandler.test.ts index adf6ab10e4..dbfe14d6f8 100644 --- a/test/unittests/front_end/models/trace/handlers/InvalidationsHandler.test.ts +++ b/front_end/models/trace/handlers/InvalidationsHandler.test.ts @@ -3,9 +3,9 @@ // found in the LICENSE file. const {assert} = chai; -import * as TraceEngine from '../../../../../../front_end/models/trace/trace.js'; -import type * as Protocol from '../../../../../../front_end/generated/protocol.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import * as TraceEngine from '../trace.js'; +import type * as Protocol from '../../../generated/protocol.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; function invalidationDataForTestAssertion(invalidation: TraceEngine.Types.TraceEvents.SyntheticInvalidation): { nodeId: Protocol.DOM.BackendNodeId, diff --git a/test/unittests/front_end/models/trace/handlers/LargestImagePaintHandler.test.ts b/front_end/models/trace/handlers/LargestImagePaintHandler.test.ts similarity index 82% rename from test/unittests/front_end/models/trace/handlers/LargestImagePaintHandler.test.ts rename to front_end/models/trace/handlers/LargestImagePaintHandler.test.ts index ae2a026682..6e16edb51a 100644 --- a/test/unittests/front_end/models/trace/handlers/LargestImagePaintHandler.test.ts +++ b/front_end/models/trace/handlers/LargestImagePaintHandler.test.ts @@ -4,9 +4,9 @@ const {assert} = chai; -import type * as Protocol from '../../../../../../front_end/generated/protocol.js'; -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import type * as Protocol from '../../../generated/protocol.js'; +import * as TraceModel from '../trace.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; describe('LargestImagePaintHandler', async function() { beforeEach(async () => { diff --git a/test/unittests/front_end/models/trace/handlers/LargestTextPaintHandler.test.ts b/front_end/models/trace/handlers/LargestTextPaintHandler.test.ts similarity index 80% rename from test/unittests/front_end/models/trace/handlers/LargestTextPaintHandler.test.ts rename to front_end/models/trace/handlers/LargestTextPaintHandler.test.ts index 471f6bd92f..7484f05a7f 100644 --- a/test/unittests/front_end/models/trace/handlers/LargestTextPaintHandler.test.ts +++ b/front_end/models/trace/handlers/LargestTextPaintHandler.test.ts @@ -4,9 +4,9 @@ const {assert} = chai; -import type * as Protocol from '../../../../../../front_end/generated/protocol.js'; -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import type * as Protocol from '../../../generated/protocol.js'; +import * as TraceModel from '../trace.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; describe('LargestTextPaintHandler', async function() { beforeEach(() => { diff --git a/test/unittests/front_end/models/trace/handlers/LayerTreeHandler.test.ts b/front_end/models/trace/handlers/LayerTreeHandler.test.ts similarity index 93% rename from test/unittests/front_end/models/trace/handlers/LayerTreeHandler.test.ts rename to front_end/models/trace/handlers/LayerTreeHandler.test.ts index d68d8dd8ac..65aba0c946 100644 --- a/test/unittests/front_end/models/trace/handlers/LayerTreeHandler.test.ts +++ b/front_end/models/trace/handlers/LayerTreeHandler.test.ts @@ -3,8 +3,8 @@ // found in the LICENSE file. const {assert} = chai; -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import * as TraceModel from '../trace.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; describe('LayerTreeHandler', function() { // The trace file used here is large because it has all the diff --git a/test/unittests/front_end/models/trace/handlers/LayoutShiftsHandler.test.ts b/front_end/models/trace/handlers/LayoutShiftsHandler.test.ts similarity index 98% rename from test/unittests/front_end/models/trace/handlers/LayoutShiftsHandler.test.ts rename to front_end/models/trace/handlers/LayoutShiftsHandler.test.ts index 526d08e7c5..fd03620efe 100644 --- a/test/unittests/front_end/models/trace/handlers/LayoutShiftsHandler.test.ts +++ b/front_end/models/trace/handlers/LayoutShiftsHandler.test.ts @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as TraceModel from '../trace.js'; async function processTrace(context: Mocha.Suite|Mocha.Context|null, url: string): Promise { TraceModel.Handlers.ModelHandlers.Meta.reset(); diff --git a/test/unittests/front_end/models/trace/handlers/MemoryHandler.test.ts b/front_end/models/trace/handlers/MemoryHandler.test.ts similarity index 89% rename from test/unittests/front_end/models/trace/handlers/MemoryHandler.test.ts rename to front_end/models/trace/handlers/MemoryHandler.test.ts index dfcb43a284..b927760dd3 100644 --- a/test/unittests/front_end/models/trace/handlers/MemoryHandler.test.ts +++ b/front_end/models/trace/handlers/MemoryHandler.test.ts @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. const {assert} = chai; -import * as TraceEngine from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import * as TraceEngine from '../trace.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; describe('MemoryHandler', function() { beforeEach(() => { diff --git a/test/unittests/front_end/models/trace/handlers/MetaHandler.test.ts b/front_end/models/trace/handlers/MetaHandler.test.ts similarity index 99% rename from test/unittests/front_end/models/trace/handlers/MetaHandler.test.ts rename to front_end/models/trace/handlers/MetaHandler.test.ts index 3ab7431121..f44ff93e62 100644 --- a/test/unittests/front_end/models/trace/handlers/MetaHandler.test.ts +++ b/front_end/models/trace/handlers/MetaHandler.test.ts @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; +import * as TraceModel from '../trace.js'; const {assert} = chai; -import {defaultTraceEvent} from '../../../helpers/TraceHelpers.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import {defaultTraceEvent} from '../../../../test/unittests/front_end/helpers/TraceHelpers.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; describe('MetaHandler', function() { let baseEvents: TraceModel.Types.TraceEvents.TraceEventData[]; diff --git a/test/unittests/front_end/models/trace/handlers/NetworkRequestsHandler.test.ts b/front_end/models/trace/handlers/NetworkRequestsHandler.test.ts similarity index 99% rename from test/unittests/front_end/models/trace/handlers/NetworkRequestsHandler.test.ts rename to front_end/models/trace/handlers/NetworkRequestsHandler.test.ts index a4b3576c16..7b5afde87b 100644 --- a/test/unittests/front_end/models/trace/handlers/NetworkRequestsHandler.test.ts +++ b/front_end/models/trace/handlers/NetworkRequestsHandler.test.ts @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as TraceModel from '../trace.js'; + const {assert} = chai; -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; type DataArgs = TraceModel.Types.TraceEvents.SyntheticNetworkRequest['args']['data']; type DataArgsProcessedData = TraceModel.Types.TraceEvents.SyntheticNetworkRequest['args']['data']['syntheticData']; diff --git a/test/unittests/front_end/models/trace/handlers/PageLoadMetricsHandler.test.ts b/front_end/models/trace/handlers/PageLoadMetricsHandler.test.ts similarity index 98% rename from test/unittests/front_end/models/trace/handlers/PageLoadMetricsHandler.test.ts rename to front_end/models/trace/handlers/PageLoadMetricsHandler.test.ts index b7ee18e15c..7ef4cd70b2 100644 --- a/test/unittests/front_end/models/trace/handlers/PageLoadMetricsHandler.test.ts +++ b/front_end/models/trace/handlers/PageLoadMetricsHandler.test.ts @@ -4,9 +4,9 @@ const {assert} = chai; -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import {describeWithEnvironment} from '../../../helpers/EnvironmentHelpers.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import * as TraceModel from '../trace.js'; +import {describeWithEnvironment} from '../../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; function countMetricOcurrences( scoresByMetricName: diff --git a/test/unittests/front_end/models/trace/handlers/RendererHandler.test.ts b/front_end/models/trace/handlers/RendererHandler.test.ts similarity index 99% rename from test/unittests/front_end/models/trace/handlers/RendererHandler.test.ts rename to front_end/models/trace/handlers/RendererHandler.test.ts index b5c1bb8519..839d4f389a 100644 --- a/test/unittests/front_end/models/trace/handlers/RendererHandler.test.ts +++ b/front_end/models/trace/handlers/RendererHandler.test.ts @@ -2,11 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -const {assert} = chai; - -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import * as Timeline from '../../../../../../front_end/panels/timeline/timeline.js'; -import {describeWithEnvironment} from '../../../helpers/EnvironmentHelpers.js'; +import {describeWithEnvironment} from '../../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; import { getAllNodes, getEventsIn, @@ -16,8 +12,12 @@ import { makeEndEvent, makeInstantEvent, prettyPrint, -} from '../../../helpers/TraceHelpers.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +} from '../../../../test/unittests/front_end/helpers/TraceHelpers.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as Timeline from '../../../panels/timeline/timeline.js'; +import * as TraceModel from '../trace.js'; + +const {assert} = chai; const MAIN_FRAME_PID = 2154214; const SUB_FRAME_PID = 2236065; diff --git a/test/unittests/front_end/models/trace/handlers/SamplesHandler.test.ts b/front_end/models/trace/handlers/SamplesHandler.test.ts similarity index 97% rename from test/unittests/front_end/models/trace/handlers/SamplesHandler.test.ts rename to front_end/models/trace/handlers/SamplesHandler.test.ts index cc731bb3dd..762e204711 100644 --- a/test/unittests/front_end/models/trace/handlers/SamplesHandler.test.ts +++ b/front_end/models/trace/handlers/SamplesHandler.test.ts @@ -2,15 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import {describeWithEnvironment} from '../../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {getAllNodes, getMainThread} from '../../../../test/unittests/front_end/helpers/TraceHelpers.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import type * as CPUProfile from '../../../models/cpu_profile/cpu_profile.js'; +import * as TraceModel from '../trace.js'; + const {assert} = chai; -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import type * as CPUProfile from '../../../../../../front_end/models/cpu_profile/cpu_profile.js'; - -import {describeWithEnvironment} from '../../../helpers/EnvironmentHelpers.js'; -import {getMainThread, getAllNodes} from '../../../helpers/TraceHelpers.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; - async function handleEventsFromTraceFile(context: Mocha.Context|Mocha.Suite|null, name: string): Promise { const traceEvents = await TraceLoader.rawEvents(context, name); diff --git a/test/unittests/front_end/models/trace/handlers/ScreenshotsHandler.test.ts b/front_end/models/trace/handlers/ScreenshotsHandler.test.ts similarity index 95% rename from test/unittests/front_end/models/trace/handlers/ScreenshotsHandler.test.ts rename to front_end/models/trace/handlers/ScreenshotsHandler.test.ts index 58dba47a43..3c215256e4 100644 --- a/test/unittests/front_end/models/trace/handlers/ScreenshotsHandler.test.ts +++ b/front_end/models/trace/handlers/ScreenshotsHandler.test.ts @@ -2,10 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import {defaultTraceEvent} from '../../../../test/unittests/front_end/helpers/TraceHelpers.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as TraceModel from '../trace.js'; + const {assert} = chai; -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import {defaultTraceEvent} from '../../../helpers/TraceHelpers.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; describe('ScreenshotsHandler', function() { const baseEvent = { @@ -122,5 +123,4 @@ describe('ScreenshotsHandler', function() { ]); }); }); - }); diff --git a/test/unittests/front_end/models/trace/handlers/Threads.test.ts b/front_end/models/trace/handlers/Threads.test.ts similarity index 90% rename from test/unittests/front_end/models/trace/handlers/Threads.test.ts rename to front_end/models/trace/handlers/Threads.test.ts index 4e40cd0c0e..09939c1e1d 100644 --- a/test/unittests/front_end/models/trace/handlers/Threads.test.ts +++ b/front_end/models/trace/handlers/Threads.test.ts @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import {describeWithEnvironment} from '../../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as TimelineModel from '../../../models/timeline_model/timeline_model.js'; +import * as TraceEngine from '../trace.js'; + const {assert} = chai; -import * as TraceEngine from '../../../../../../front_end/models/trace/trace.js'; -import * as TimelineModel from '../../../../../../front_end/models/timeline_model/timeline_model.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; -import {describeWithEnvironment} from '../../../helpers/EnvironmentHelpers.js'; describeWithEnvironment('Handler Threads helper', function() { it('returns all the threads for a trace that used tracing', async function() { diff --git a/test/unittests/front_end/models/trace/handlers/UserInteractionsHandler.test.ts b/front_end/models/trace/handlers/UserInteractionsHandler.test.ts similarity index 99% rename from test/unittests/front_end/models/trace/handlers/UserInteractionsHandler.test.ts rename to front_end/models/trace/handlers/UserInteractionsHandler.test.ts index b09c5ec7ac..119d2355df 100644 --- a/test/unittests/front_end/models/trace/handlers/UserInteractionsHandler.test.ts +++ b/front_end/models/trace/handlers/UserInteractionsHandler.test.ts @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -const {assert} = chai; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as TraceModel from '../trace.js'; -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +const {assert} = chai; async function processTrace(context: Mocha.Suite|Mocha.Context|null, path: string): Promise { const traceEvents = await TraceLoader.rawEvents(context, path); diff --git a/test/unittests/front_end/models/trace/handlers/UserTimingsHandler.test.ts b/front_end/models/trace/handlers/UserTimingsHandler.test.ts similarity index 98% rename from test/unittests/front_end/models/trace/handlers/UserTimingsHandler.test.ts rename to front_end/models/trace/handlers/UserTimingsHandler.test.ts index f6764db548..e2e45e7cec 100644 --- a/test/unittests/front_end/models/trace/handlers/UserTimingsHandler.test.ts +++ b/front_end/models/trace/handlers/UserTimingsHandler.test.ts @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -const {assert} = chai; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as TraceModel from '../trace.js'; -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +const {assert} = chai; describe('UserTimingsHandler', function() { let timingsData: TraceModel.Handlers.ModelHandlers.UserTimings.UserTimingsData; diff --git a/test/unittests/front_end/models/trace/handlers/WarningsHandler.test.ts b/front_end/models/trace/handlers/WarningsHandler.test.ts similarity index 96% rename from test/unittests/front_end/models/trace/handlers/WarningsHandler.test.ts rename to front_end/models/trace/handlers/WarningsHandler.test.ts index 86541bf210..7962910c9a 100644 --- a/test/unittests/front_end/models/trace/handlers/WarningsHandler.test.ts +++ b/front_end/models/trace/handlers/WarningsHandler.test.ts @@ -1,9 +1,11 @@ // Copyright 2023 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 {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as TraceEngine from '../trace.js'; + const {assert} = chai; -import * as TraceEngine from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; describe('WarningsHandler', function() { beforeEach(() => { diff --git a/test/unittests/front_end/models/trace/handlers/WorkersHandler.test.ts b/front_end/models/trace/handlers/WorkersHandler.test.ts similarity index 96% rename from test/unittests/front_end/models/trace/handlers/WorkersHandler.test.ts rename to front_end/models/trace/handlers/WorkersHandler.test.ts index 240ee1050a..8b2b813ec6 100644 --- a/test/unittests/front_end/models/trace/handlers/WorkersHandler.test.ts +++ b/front_end/models/trace/handlers/WorkersHandler.test.ts @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. const {assert} = chai; -import * as TraceEngine from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import * as TraceEngine from '../trace.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; describe('WorkersHandler', () => { beforeEach(async function() { diff --git a/front_end/models/trace/helpers/BUILD.gn b/front_end/models/trace/helpers/BUILD.gn index b72f193ca4..3182de617a 100644 --- a/front_end/models/trace/helpers/BUILD.gn +++ b/front_end/models/trace/helpers/BUILD.gn @@ -4,6 +4,7 @@ import("../../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../../scripts/build/ninja/devtools_module.gni") +import("../../../../third_party/typescript/typescript.gni") import("../../visibility.gni") devtools_module("helpers") { @@ -33,3 +34,20 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ + "SamplesIntegrator.test.ts", + "Timing.test.ts", + "Trace.test.ts", + "TreeHelpers.test.ts", + ] + + deps = [ + "../../../../test/unittests/front_end/helpers", + "../../../core/platform:bundle", + "../../../models/trace:bundle", + ] +} diff --git a/test/unittests/front_end/models/trace/helpers/SamplesIntegrator.test.ts b/front_end/models/trace/helpers/SamplesIntegrator.test.ts similarity index 96% rename from test/unittests/front_end/models/trace/helpers/SamplesIntegrator.test.ts rename to front_end/models/trace/helpers/SamplesIntegrator.test.ts index 7e0dfb6f1b..eeb644d013 100644 --- a/test/unittests/front_end/models/trace/helpers/SamplesIntegrator.test.ts +++ b/front_end/models/trace/helpers/SamplesIntegrator.test.ts @@ -4,12 +4,12 @@ const {assert} = chai; -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import * as CPUProfile from '../../../../../../front_end/models/cpu_profile/cpu_profile.js'; -import {describeWithEnvironment} from '../../../helpers/EnvironmentHelpers.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; -import {makeCompleteEvent} from '../../../helpers/TraceHelpers.js'; -import type * as Protocol from '../../../../../../front_end/generated/protocol.js'; +import * as TraceModel from '../trace.js'; +import * as CPUProfile from '../../../models/cpu_profile/cpu_profile.js'; +import {describeWithEnvironment} from '../../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import {makeCompleteEvent} from '../../../../test/unittests/front_end/helpers/TraceHelpers.js'; +import type * as Protocol from '../../../generated/protocol.js'; describeWithEnvironment('SamplesIntegrator', function() { const scriptId = 'Peperoni' as Protocol.Runtime.ScriptId; diff --git a/test/unittests/front_end/models/trace/helpers/Timing.test.ts b/front_end/models/trace/helpers/Timing.test.ts similarity index 97% rename from test/unittests/front_end/models/trace/helpers/Timing.test.ts rename to front_end/models/trace/helpers/Timing.test.ts index ab1dd6b580..1b8811440b 100644 --- a/test/unittests/front_end/models/trace/helpers/Timing.test.ts +++ b/front_end/models/trace/helpers/Timing.test.ts @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import {describeWithEnvironment} from '../../../helpers/EnvironmentHelpers.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import {describeWithEnvironment} from '../../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as TraceModel from '../trace.js'; const {assert} = chai; function milliToMicro(value: number) { diff --git a/test/unittests/front_end/models/trace/helpers/Trace.test.ts b/front_end/models/trace/helpers/Trace.test.ts similarity index 98% rename from test/unittests/front_end/models/trace/helpers/Trace.test.ts rename to front_end/models/trace/helpers/Trace.test.ts index f0b61caf10..56a06ffa3f 100644 --- a/test/unittests/front_end/models/trace/helpers/Trace.test.ts +++ b/front_end/models/trace/helpers/Trace.test.ts @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; -import {describeWithEnvironment} from '../../../helpers/EnvironmentHelpers.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import {describeWithEnvironment} from '../../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as TraceModel from '../trace.js'; + const {assert} = chai; describeWithEnvironment('TraceModel helpers', function() { diff --git a/test/unittests/front_end/models/trace/helpers/TreeHelpers.test.ts b/front_end/models/trace/helpers/TreeHelpers.test.ts similarity index 99% rename from test/unittests/front_end/models/trace/helpers/TreeHelpers.test.ts rename to front_end/models/trace/helpers/TreeHelpers.test.ts index 6561dd0019..d433e3352e 100644 --- a/test/unittests/front_end/models/trace/helpers/TreeHelpers.test.ts +++ b/front_end/models/trace/helpers/TreeHelpers.test.ts @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as TraceModel from '../../../../../../front_end/models/trace/trace.js'; import { getEventsIn, makeCompleteEvent, makeProfileCall, prettyPrint, -} from '../../../helpers/TraceHelpers.js'; +} from '../../../../test/unittests/front_end/helpers/TraceHelpers.js'; +import * as TraceModel from '../trace.js'; describe('TreeHelpers', () => { describe('treify', () => { diff --git a/front_end/models/trace/root-causes/BUILD.gn b/front_end/models/trace/root-causes/BUILD.gn index 2ba1a07aae..b0a29fce51 100644 --- a/front_end/models/trace/root-causes/BUILD.gn +++ b/front_end/models/trace/root-causes/BUILD.gn @@ -4,6 +4,7 @@ import("../../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../../scripts/build/ninja/devtools_module.gni") +import("../../../../third_party/typescript/typescript.gni") import("../../visibility.gni") devtools_module("root-causes") { @@ -33,3 +34,15 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ "LayoutShift.test.ts" ] + + deps = [ + "../../../../test/unittests/front_end/helpers", + "../../../core/platform:bundle", + "../../../models/trace:bundle", + ] +} diff --git a/test/unittests/front_end/models/trace/root-causes/LayoutShift.test.ts b/front_end/models/trace/root-causes/LayoutShift.test.ts similarity index 98% rename from test/unittests/front_end/models/trace/root-causes/LayoutShift.test.ts rename to front_end/models/trace/root-causes/LayoutShift.test.ts index c1fb8f186d..d75fcbee68 100644 --- a/test/unittests/front_end/models/trace/root-causes/LayoutShift.test.ts +++ b/front_end/models/trace/root-causes/LayoutShift.test.ts @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Protocol from '../../../../../../front_end/generated/protocol.js'; -import * as TraceEngine from '../../../../../../front_end/models/trace/trace.js'; import { describeWithMockConnection, -} from '../../../helpers/MockConnection.js'; -import {getBaseTraceParseModelData} from '../../../helpers/TraceHelpers.js'; +} from '../../../../test/unittests/front_end/helpers/MockConnection.js'; +import {getBaseTraceParseModelData} from '../../../../test/unittests/front_end/helpers/TraceHelpers.js'; +import * as Protocol from '../../../generated/protocol.js'; +import * as TraceEngine from '../trace.js'; type TraceParseData = TraceEngine.Handlers.Types.TraceParseData; type TraceParseDataMutable = TraceEngine.Handlers.Types.TraceParseDataMutable; diff --git a/front_end/models/trace/types/BUILD.gn b/front_end/models/trace/types/BUILD.gn index 6651f5958b..747882cdef 100644 --- a/front_end/models/trace/types/BUILD.gn +++ b/front_end/models/trace/types/BUILD.gn @@ -4,6 +4,7 @@ import("../../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../../scripts/build/ninja/devtools_module.gni") +import("../../../../third_party/typescript/typescript.gni") import("../../visibility.gni") devtools_module("types") { @@ -27,3 +28,15 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ "TraceEvents.test.ts" ] + + deps = [ + "../../../../test/unittests/front_end/helpers", + "../../../core/platform:bundle", + "../../../models/trace:bundle", + ] +} diff --git a/test/unittests/front_end/models/trace/types/TraceEvents.test.ts b/front_end/models/trace/types/TraceEvents.test.ts similarity index 94% rename from test/unittests/front_end/models/trace/types/TraceEvents.test.ts rename to front_end/models/trace/types/TraceEvents.test.ts index ef6c9c7f9d..5b3d1cf4ec 100644 --- a/test/unittests/front_end/models/trace/types/TraceEvents.test.ts +++ b/front_end/models/trace/types/TraceEvents.test.ts @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as TraceEngine from '../../../../../../front_end/models/trace/trace.js'; -import {describeWithEnvironment} from '../../../helpers/EnvironmentHelpers.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; +import {describeWithEnvironment} from '../../../../test/unittests/front_end/helpers/EnvironmentHelpers.js'; +import {TraceLoader} from '../../../../test/unittests/front_end/helpers/TraceLoader.js'; +import * as TraceEngine from '../trace.js'; + const {assert} = chai; describeWithEnvironment('TraceEvent types', function() { diff --git a/front_end/models/workspace/BUILD.gn b/front_end/models/workspace/BUILD.gn index 8494ab1483..daec351027 100644 --- a/front_end/models/workspace/BUILD.gn +++ b/front_end/models/workspace/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("workspace") { @@ -62,3 +63,20 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ + "SearchConfig.test.ts", + "UISourceCode.test.ts", + "WorkspaceImpl.test.ts", + ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + "../../core/common:bundle", + "../persistence:bundle", + ] +} diff --git a/test/unittests/front_end/models/workspace/SearchConfig.test.ts b/front_end/models/workspace/SearchConfig.test.ts similarity index 96% rename from test/unittests/front_end/models/workspace/SearchConfig.test.ts rename to front_end/models/workspace/SearchConfig.test.ts index 73a1c691e5..d845c7530d 100644 --- a/test/unittests/front_end/models/workspace/SearchConfig.test.ts +++ b/front_end/models/workspace/SearchConfig.test.ts @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; +import type * as Platform from '../../core/platform/platform.js'; +import * as Workspace from '../workspace/workspace.js'; const {SearchConfig} = Workspace.SearchConfig; diff --git a/test/unittests/front_end/models/workspace/UISourceCode.test.ts b/front_end/models/workspace/UISourceCode.test.ts similarity index 97% rename from test/unittests/front_end/models/workspace/UISourceCode.test.ts rename to front_end/models/workspace/UISourceCode.test.ts index 836c75a41e..3d524c19ab 100644 --- a/test/unittests/front_end/models/workspace/UISourceCode.test.ts +++ b/front_end/models/workspace/UISourceCode.test.ts @@ -4,10 +4,10 @@ const {assert} = chai; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import type * as TextUtils from '../../../../../front_end/models/text_utils/text_utils.js'; -import {setupMockedUISourceCode} from '../../helpers/UISourceCodeHelpers.js'; +import {setupMockedUISourceCode} from '../../../test/unittests/front_end/helpers/UISourceCodeHelpers.js'; +import type * as Platform from '../../core/platform/platform.js'; +import type * as TextUtils from '../text_utils/text_utils.js'; +import * as Workspace from './workspace.js'; describe('UISourceCode', () => { it('can return name', async () => { diff --git a/test/unittests/front_end/models/workspace/WorkspaceImpl.test.ts b/front_end/models/workspace/WorkspaceImpl.test.ts similarity index 97% rename from test/unittests/front_end/models/workspace/WorkspaceImpl.test.ts rename to front_end/models/workspace/WorkspaceImpl.test.ts index 9d72a71cd5..253f9370f6 100644 --- a/test/unittests/front_end/models/workspace/WorkspaceImpl.test.ts +++ b/front_end/models/workspace/WorkspaceImpl.test.ts @@ -4,9 +4,9 @@ const {assert} = chai; -import * as Bindings from '../../../../../front_end/models/bindings/bindings.js'; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; +import * as Bindings from '../bindings/bindings.js'; +import type * as Platform from '../../core/platform/platform.js'; +import * as Workspace from '../workspace/workspace.js'; describe('WorkspaceImpl', () => { it('can remove the current instance', () => { diff --git a/front_end/models/workspace_diff/BUILD.gn b/front_end/models/workspace_diff/BUILD.gn index 691ce4bba3..0b14290c63 100644 --- a/front_end/models/workspace_diff/BUILD.gn +++ b/front_end/models/workspace_diff/BUILD.gn @@ -4,6 +4,7 @@ import("../../../scripts/build/ninja/devtools_entrypoint.gni") import("../../../scripts/build/ninja/devtools_module.gni") +import("../../../third_party/typescript/typescript.gni") import("../visibility.gni") devtools_module("workspace_diff") { @@ -34,3 +35,17 @@ devtools_entrypoint("bundle") { visibility += devtools_models_visibility } + +ts_library("unittests") { + testonly = true + + sources = [ "WorkspaceDiff.test.ts" ] + + deps = [ + ":bundle", + "../../../test/unittests/front_end/helpers", + "../../core/common:bundle", + "../persistence:bundle", + "../workspace:bundle", + ] +} diff --git a/test/unittests/front_end/models/workspace_diff/WorkspaceDiff.test.ts b/front_end/models/workspace_diff/WorkspaceDiff.test.ts similarity index 76% rename from test/unittests/front_end/models/workspace_diff/WorkspaceDiff.test.ts rename to front_end/models/workspace_diff/WorkspaceDiff.test.ts index b5eff24b6d..d2b09928d5 100644 --- a/test/unittests/front_end/models/workspace_diff/WorkspaceDiff.test.ts +++ b/front_end/models/workspace_diff/WorkspaceDiff.test.ts @@ -4,12 +4,12 @@ const {assert} = chai; -import type * as Platform from '../../../../../front_end/core/platform/platform.js'; -import * as Workspace from '../../../../../front_end/models/workspace/workspace.js'; -import * as WorkspaceDiff from '../../../../../front_end/models/workspace_diff/workspace_diff.js'; +import type * as Platform from '../../core/platform/platform.js'; +import * as Workspace from '../workspace/workspace.js'; +import * as WorkspaceDiff from '../workspace_diff/workspace_diff.js'; -import {describeWithRealConnection} from '../../helpers/RealConnection.js'; -import {createFileSystemUISourceCode} from '../../helpers/UISourceCodeHelpers.js'; +import {describeWithRealConnection} from '../../../test/unittests/front_end/helpers/RealConnection.js'; +import {createFileSystemUISourceCode} from '../../../test/unittests/front_end/helpers/UISourceCodeHelpers.js'; describeWithRealConnection('UISourceCodeDiff', () => { it('returns formatted mapping with a diff', async () => { diff --git a/front_end/panels/timeline/BUILD.gn b/front_end/panels/timeline/BUILD.gn index 132654ffeb..eddc5806b9 100644 --- a/front_end/panels/timeline/BUILD.gn +++ b/front_end/panels/timeline/BUILD.gn @@ -132,9 +132,9 @@ devtools_entrypoint("bundle") { "../../../test/perf/*", "../../../test/unittests/front_end/entrypoints/missing_entrypoints/*", "../../../test/unittests/front_end/helpers", - "../../../test/unittests/front_end/models/trace/*", "../../../test/unittests/front_end/panels/timeline/*", "../../entrypoints/*", + "../../models/trace/handlers:unittests", "../../ui/components/docs/performance_panel/*", "../input/*", "../js_profiler/*", diff --git a/front_end/ui/legacy/BUILD.gn b/front_end/ui/legacy/BUILD.gn index db05d747cb..d3229af1a3 100644 --- a/front_end/ui/legacy/BUILD.gn +++ b/front_end/ui/legacy/BUILD.gn @@ -162,6 +162,7 @@ devtools_entrypoint("bundle") { "../../models/autofill_manager:*", "../../models/emulation:*", "../../models/extensions:*", + "../../models/har:unittests", "../../models/persistence:*", "../../panels/*", "../../services/window_bounds/*", diff --git a/scripts/eslint_rules/lib/es_modules_import.js b/scripts/eslint_rules/lib/es_modules_import.js index 708d8312ec..2a86f2b6a0 100644 --- a/scripts/eslint_rules/lib/es_modules_import.js +++ b/scripts/eslint_rules/lib/es_modules_import.js @@ -90,12 +90,14 @@ function checkStarImport(context, node, importPath, importPathForErrorMessage, i if (invalidSameFolderUsage) { // Meta files import their entrypoints and are considered separate entrypoints. - // Additionally, any file ending with `-entrypoint.ts` is considered an entrypoint as well. - // Therefore, they are allowed to import using a same-namespace star-import. - const importingFileIsEntrypoint = - importingFileName.endsWith('-entrypoint.ts') || importingFileName.endsWith('-meta.ts'); + // Additionally, any file ending with `-entrypoint.ts` is considered an entrypoint + // as well. Therefore, they are allowed to import using a same-namespace star-import. + // For `.test.ts` files we also need to use the namespace import syntax, to access + // the module itself, so we need to allow this as well. + const importingFileIsEntrypointOrTest = importingFileName.endsWith('-entrypoint.ts') || + importingFileName.endsWith('-meta.ts') || importingFileName.endsWith('.test.ts'); - if (!importingFileIsEntrypoint) { + if (!importingFileIsEntrypointOrTest) { context.report({ node, message: @@ -198,6 +200,13 @@ module.exports = { checkStarImport(context, node, importPath, importPathForErrorMessage, importingFileName, exportingFileName); } else { if (computeTopLevelFolder(importingFileName) !== computeTopLevelFolder(exportingFileName)) { + if (importingFileName.endsWith('.test.ts') && + importPath.includes([path.sep, 'helpers', path.sep].join(''))) { + /** Within test files we allow the direct import of test helpers. + */ + return; + } + let message = CROSS_NAMESPACE_MESSAGE; if (importPath.endsWith(path.join('common', 'ls.js'))) { diff --git a/scripts/eslint_rules/tests/es_modules_import_test.js b/scripts/eslint_rules/tests/es_modules_import_test.js index 4795a09bc5..fd19d556f7 100644 --- a/scripts/eslint_rules/tests/es_modules_import_test.js +++ b/scripts/eslint_rules/tests/es_modules_import_test.js @@ -115,6 +115,12 @@ ruleTester.run('es_modules_import', rule, { code: 'import * as UI from \'../../../front_end/ui/ui.js\';', filename: 'test/unittests/front_end/foo.js', }, + // Tests are allowed to import helpers + { + code: + 'import {createContentProviderUISourceCode} from \'../../../test/unittests/front_end/helpers/UISourceCodeHelpers.js\';', + filename: 'front_end/models/bindings/IgnoreListManager.test.ts', + }, // Component doc files can reach into the test directory to use the helpers { code: 'import * as FrontendHelpers from \'../../../test/unittests/front_end/helpers/EnvironmentHelpers.js\'', diff --git a/test/interactions/panels/recorder/injected/injected_test.ts b/test/interactions/panels/recorder/injected/injected_test.ts index 880bebc7ed..f34a0761c0 100644 --- a/test/interactions/panels/recorder/injected/injected_test.ts +++ b/test/interactions/panels/recorder/injected/injected_test.ts @@ -4,6 +4,8 @@ import {assert} from 'chai'; +import {type DevToolsRecorder} from '../../../../../front_end/panels/recorder/injected/injected.js'; +import {type Schema} from '../../../../../front_end/panels/recorder/models/models.js'; import { loadComponentDocExample, preloadForCodeCoverage, @@ -13,11 +15,8 @@ import { describe, it, } from '../../../../../test/shared/mocha-extensions.js'; -import {type Schema} from '../../../../../front_end/panels/recorder/models/models.js'; import {assertMatchesJSONSnapshot} from '../../../../../test/shared/snapshots.js'; -import {type DevToolsRecorder} from '../../../../../front_end/panels/recorder/injected/injected.js'; - describe('Injected', () => { preloadForCodeCoverage('recorder_injected/basic.html'); diff --git a/test/unittests/front_end/BUILD.gn b/test/unittests/front_end/BUILD.gn index a27afb0060..68d80de148 100644 --- a/test/unittests/front_end/BUILD.gn +++ b/test/unittests/front_end/BUILD.gn @@ -5,6 +5,29 @@ group("front_end") { deps = [ "../../../front_end/Images:optimize_images", + "../../../front_end/models/autofill_manager:unittests", + "../../../front_end/models/bindings:unittests", + "../../../front_end/models/breakpoints:unittests", + "../../../front_end/models/cpu_profile:unittests", + "../../../front_end/models/emulation:unittests", + "../../../front_end/models/extensions:unittests", + "../../../front_end/models/formatter:unittests", + "../../../front_end/models/har:unittests", + "../../../front_end/models/issues_manager:unittests", + "../../../front_end/models/javascript_metadata:unittests", + "../../../front_end/models/logs:unittests", + "../../../front_end/models/persistence:unittests", + "../../../front_end/models/source_map_scopes:unittests", + "../../../front_end/models/text_utils:unittests", + "../../../front_end/models/timeline_model:unittests", + "../../../front_end/models/trace:unittests", + "../../../front_end/models/trace/extras:unittests", + "../../../front_end/models/trace/handlers:unittests", + "../../../front_end/models/trace/helpers:unittests", + "../../../front_end/models/trace/root-causes:unittests", + "../../../front_end/models/trace/types:unittests", + "../../../front_end/models/workspace:unittests", + "../../../front_end/models/workspace_diff:unittests", "core/common", "core/dom_extension", "core/i18n", @@ -17,29 +40,6 @@ group("front_end") { "entrypoints/main", "entrypoints/meta", "entrypoints/missing_entrypoints", - "models/autofill_manager", - "models/bindings", - "models/breakpoints", - "models/cpu_profile", - "models/emulation", - "models/extensions", - "models/formatter", - "models/har", - "models/issues_manager", - "models/javascript_metadata", - "models/logs", - "models/persistence", - "models/source_map_scopes", - "models/text_utils", - "models/timeline_model", - "models/trace", - "models/trace/extras", - "models/trace/handlers", - "models/trace/helpers", - "models/trace/root-causes", - "models/trace/types", - "models/workspace", - "models/workspace_diff", "panels/accessibility", "panels/animation", "panels/application", diff --git a/test/unittests/front_end/helpers/BUILD.gn b/test/unittests/front_end/helpers/BUILD.gn index 751137a0e4..a72321a1ff 100644 --- a/test/unittests/front_end/helpers/BUILD.gn +++ b/test/unittests/front_end/helpers/BUILD.gn @@ -11,10 +11,14 @@ ts_library("helpers") { "Cookies.ts", "DOMHelpers.ts", "EnvironmentHelpers.ts", + "ExtensionHelpers.ts", "InspectorOverlayHelpers.ts", "LanguagePluginHelpers.ts", "MockConnection.ts", "MockExecutionContext.ts", + "MockIssuesManager.ts", + "MockIssuesModel.ts", + "MockNetworkLog.ts", "MockScopeChain.test.ts", "MockScopeChain.ts", "MutationHelpers.test.ts", @@ -25,6 +29,7 @@ ts_library("helpers") { "SourceMapEncoder.test.ts", "SourceMapEncoder.ts", "SourceMapHelpers.ts", + "StubIssue.ts", "TraceHelpers.ts", "TraceLoader.ts", "TrackAsyncOperations.ts", @@ -34,6 +39,7 @@ ts_library("helpers") { ] deps = [ + "../../../../extension-api", "../../../../front_end/core/common:bundle", "../../../../front_end/core/host:bundle", "../../../../front_end/core/i18n:bundle", @@ -46,6 +52,7 @@ ts_library("helpers") { "../../../../front_end/entrypoints/shell", "../../../../front_end/generated:protocol", "../../../../front_end/models/bindings:bundle", + "../../../../front_end/models/extensions:bundle", "../../../../front_end/models/issues_manager:bundle", "../../../../front_end/models/text_utils:bundle", "../../../../front_end/models/timeline_model:bundle", diff --git a/test/unittests/front_end/models/extensions/helpers.ts b/test/unittests/front_end/helpers/ExtensionHelpers.ts similarity index 85% rename from test/unittests/front_end/models/extensions/helpers.ts rename to test/unittests/front_end/helpers/ExtensionHelpers.ts index a1ea8ec8b4..3ba3f7aebc 100644 --- a/test/unittests/front_end/models/extensions/helpers.ts +++ b/test/unittests/front_end/helpers/ExtensionHelpers.ts @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import {type Chrome} from '../../../../../extension-api/ExtensionAPI.js'; -import * as Host from '../../../../../front_end/core/host/host.js'; -import * as Extensions from '../../../../../front_end/models/extensions/extensions.js'; -import {describeWithEnvironment, setupActionRegistry} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; +import {type Chrome} from '../../../../extension-api/ExtensionAPI.js'; +import * as Host from '../../../../front_end/core/host/host.js'; +import * as Extensions from '../../../../front_end/models/extensions/extensions.js'; +import {describeWithEnvironment, setupActionRegistry} from './EnvironmentHelpers.js'; +import {describeWithMockConnection} from './MockConnection.js'; interface ExtensionContext { chrome: Partial; diff --git a/test/unittests/front_end/models/issues_manager/MockIssuesManager.ts b/test/unittests/front_end/helpers/MockIssuesManager.ts similarity index 89% rename from test/unittests/front_end/models/issues_manager/MockIssuesManager.ts rename to test/unittests/front_end/helpers/MockIssuesManager.ts index de229eac85..5f102d1067 100644 --- a/test/unittests/front_end/models/issues_manager/MockIssuesManager.ts +++ b/test/unittests/front_end/helpers/MockIssuesManager.ts @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Common from '../../../../../front_end/core/common/common.js'; -import * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; -import {type StubIssue} from './StubIssue.js'; -import type * as SDK from '../../../../../front_end/core/sdk/sdk.js'; +import * as Common from '../../../../front_end/core/common/common.js'; +import type * as SDK from '../../../../front_end/core/sdk/sdk.js'; +import * as IssuesManager from '../../../../front_end/models/issues_manager/issues_manager.js'; + import {MockIssuesModel} from './MockIssuesModel.js'; +import {type StubIssue} from './StubIssue.js'; export class MockIssuesManager extends Common.ObjectWrapper.ObjectWrapper { private mockIssues: IssuesManager.Issue.Issue[]; diff --git a/test/unittests/front_end/models/issues_manager/MockIssuesModel.ts b/test/unittests/front_end/helpers/MockIssuesModel.ts similarity index 68% rename from test/unittests/front_end/models/issues_manager/MockIssuesModel.ts rename to test/unittests/front_end/helpers/MockIssuesModel.ts index 6f00ebd08f..4ad0ccc909 100644 --- a/test/unittests/front_end/models/issues_manager/MockIssuesModel.ts +++ b/test/unittests/front_end/helpers/MockIssuesModel.ts @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Common from '../../../../../front_end/core/common/common.js'; -import type * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; -import type * as SDK from '../../../../../front_end/core/sdk/sdk.js'; +import * as Common from '../../../../front_end/core/common/common.js'; +import type * as SDK from '../../../../front_end/core/sdk/sdk.js'; +import type * as IssuesManager from '../../../../front_end/models/issues_manager/issues_manager.js'; export class MockIssuesModel extends Common.ObjectWrapper.ObjectWrapper { private mockIssues: Iterable; diff --git a/test/unittests/front_end/models/logs/MockNetworkLog.ts b/test/unittests/front_end/helpers/MockNetworkLog.ts similarity index 83% rename from test/unittests/front_end/models/logs/MockNetworkLog.ts rename to test/unittests/front_end/helpers/MockNetworkLog.ts index 2c149e8b2d..fb90138d8b 100644 --- a/test/unittests/front_end/models/logs/MockNetworkLog.ts +++ b/test/unittests/front_end/helpers/MockNetworkLog.ts @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Common from '../../../../../front_end/core/common/common.js'; -import type * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import * as Logs from '../../../../../front_end/models/logs/logs.js'; +import * as Common from '../../../../front_end/core/common/common.js'; +import type * as SDK from '../../../../front_end/core/sdk/sdk.js'; +import * as Logs from '../../../../front_end/models/logs/logs.js'; interface MockNetworkRequest { requestId(): string; diff --git a/test/unittests/front_end/models/issues_manager/StubIssue.ts b/test/unittests/front_end/helpers/StubIssue.ts similarity index 95% rename from test/unittests/front_end/models/issues_manager/StubIssue.ts rename to test/unittests/front_end/helpers/StubIssue.ts index b7f5fcbb4b..911502654c 100644 --- a/test/unittests/front_end/models/issues_manager/StubIssue.ts +++ b/test/unittests/front_end/helpers/StubIssue.ts @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import * as Protocol from '../../../../../front_end/generated/protocol.js'; +import * as Protocol from '../../../../front_end/generated/protocol.js'; // eslint-disable-next-line rulesdir/es_modules_import import { Issue, IssueCategory, IssueKind, -} from '../../../../../front_end/models/issues_manager/Issue.js'; +} from '../../../../front_end/models/issues_manager/Issue.js'; export class StubIssue extends Issue { private requestIds: string[]; diff --git a/test/unittests/front_end/models/autofill_manager/BUILD.gn b/test/unittests/front_end/models/autofill_manager/BUILD.gn deleted file mode 100644 index 7af4e8e164..0000000000 --- a/test/unittests/front_end/models/autofill_manager/BUILD.gn +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2023 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("autofill_manager") { - testonly = true - sources = [ "AutofillManager.test.ts" ] - - deps = [ - "../../../../../front_end/models/autofill_manager:bundle", - "../../core/common", - "../../core/sdk", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/bindings/BUILD.gn b/test/unittests/front_end/models/bindings/BUILD.gn deleted file mode 100644 index a02cf4b607..0000000000 --- a/test/unittests/front_end/models/bindings/BUILD.gn +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright 2021 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("bindings") { - testonly = true - sources = [ - "CompilerScriptMapping.test.ts", - "ContentProviderBasedProject.test.ts", - "DebuggerLanguagePlugins.test.ts", - "DebuggerWorkspaceBinding.test.ts", - "DefaultScriptMapping.test.ts", - "FileUtils.test.ts", - "IgnoreListManager.test.ts", - "LiveLocation.test.ts", - "PresentationConsoleMessageHelper.test.ts", - "ResourceMapping.test.ts", - "ResourceScriptMapping.test.ts", - "ResourceUtils.test.ts", - ] - - deps = [ - "../../../../../front_end/core/common:bundle", - "../../../../../front_end/models/bindings:bundle", - "../../../../../front_end/models/persistence:bundle", - "../../../../../front_end/models/workspace:bundle", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/breakpoints/BUILD.gn b/test/unittests/front_end/models/breakpoints/BUILD.gn deleted file mode 100644 index 75b6e5d9dd..0000000000 --- a/test/unittests/front_end/models/breakpoints/BUILD.gn +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2023 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("breakpoints") { - testonly = true - sources = [ "BreakpointManager.test.ts" ] - - deps = [ - "../../../../../front_end/models/breakpoints:bundle", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/cpu_profile/BUILD.gn b/test/unittests/front_end/models/cpu_profile/BUILD.gn deleted file mode 100644 index 3a4438058c..0000000000 --- a/test/unittests/front_end/models/cpu_profile/BUILD.gn +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2023 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("cpu_profile") { - testonly = true - sources = [ "CPUProfileDataModel.test.ts" ] - - deps = [ - "../../../../../front_end/models/cpu_profile:bundle", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/emulation/BUILD.gn b/test/unittests/front_end/models/emulation/BUILD.gn deleted file mode 100644 index 4de8877763..0000000000 --- a/test/unittests/front_end/models/emulation/BUILD.gn +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2021 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("emulation") { - testonly = true - sources = [ - "DeviceModeModel.test.ts", - "EmulatedDevices.test.ts", - ] - - deps = [ - "../../../../../front_end/core/platform:bundle", - "../../../../../front_end/core/sdk:bundle", - "../../../../../front_end/models/emulation:bundle", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/extensions/BUILD.gn b/test/unittests/front_end/models/extensions/BUILD.gn deleted file mode 100644 index 7425c3c009..0000000000 --- a/test/unittests/front_end/models/extensions/BUILD.gn +++ /dev/null @@ -1,20 +0,0 @@ -# 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("extensions") { - testonly = true - sources = [ - "ExtensionServer.test.ts", - "HostUrlPattern.test.ts", - "RecorderPluginManager.test.ts", - "helpers.ts", - ] - - deps = [ - "../../../../../front_end/models/extensions:bundle", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/formatter/BUILD.gn b/test/unittests/front_end/models/formatter/BUILD.gn deleted file mode 100644 index 468b5c1d30..0000000000 --- a/test/unittests/front_end/models/formatter/BUILD.gn +++ /dev/null @@ -1,18 +0,0 @@ -# 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. - -import("../../../../../third_party/typescript/typescript.gni") - -ts_library("formatter") { - testonly = true - sources = [ "ScriptFormatter.test.ts" ] - deps = [ - "../../../../../front_end/core/common:bundle", - "../../../../../front_end/core/sdk:bundle", - "../../../../../front_end/models/bindings:bundle", - "../../../../../front_end/models/formatter:bundle", - "../../../../../front_end/models/workspace:bundle", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/har/BUILD.gn b/test/unittests/front_end/models/har/BUILD.gn deleted file mode 100644 index 0be1d69d6b..0000000000 --- a/test/unittests/front_end/models/har/BUILD.gn +++ /dev/null @@ -1,21 +0,0 @@ -# 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. - -import("../../../../../third_party/typescript/typescript.gni") - -ts_library("har") { - testonly = true - sources = [ - "Importer.test.ts", - "Log.test.ts", - "Writer.test.ts", - ] - deps = [ - "../../../../../front_end/core/common:bundle", - "../../../../../front_end/core/sdk:bundle", - "../../../../../front_end/models/har:bundle", - "../../../../../front_end/ui/legacy:bundle", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/issues_manager/BUILD.gn b/test/unittests/front_end/models/issues_manager/BUILD.gn deleted file mode 100644 index 13b401de27..0000000000 --- a/test/unittests/front_end/models/issues_manager/BUILD.gn +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2021 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("issues_manager") { - testonly = true - sources = [ - "CheckFormsIssuesTrigger.test.ts", - "DeprecationIssue.test.ts", - "FederatedAuthUserInfoRequestIssue.test.ts", - "GenericIssue.test.ts", - "Issue.test.ts", - "IssueResolver.test.ts", - "IssuesManager.test.ts", - "LowTextContrastIssue.test.ts", - "MarkdownIssueDescription.test.ts", - "MockIssuesManager.ts", - "MockIssuesModel.ts", - "PropertyRuleIssue.test.ts", - "RelatedIssue.test.ts", - "StubIssue.ts", - "StylesheetLoadingIssue.test.ts", - ] - - deps = [ - "../../../../../front_end/models/issues_manager:bundle", - "../../core/common", - "../../core/sdk", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/javascript_metadata/BUILD.gn b/test/unittests/front_end/models/javascript_metadata/BUILD.gn deleted file mode 100644 index 215971c8ce..0000000000 --- a/test/unittests/front_end/models/javascript_metadata/BUILD.gn +++ /dev/null @@ -1,14 +0,0 @@ -# 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. -import("../../../../../third_party/typescript/typescript.gni") - -ts_library("javascript_metadata") { - testonly = true - sources = [ "JavaScriptMetadata.test.ts" ] - - deps = [ - "../../../../../front_end/models/javascript_metadata:bundle", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/logs/BUILD.gn b/test/unittests/front_end/models/logs/BUILD.gn deleted file mode 100644 index b3ee28f6bd..0000000000 --- a/test/unittests/front_end/models/logs/BUILD.gn +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2021 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("logs") { - testonly = true - sources = [ - "MockNetworkLog.ts", - "NetworkLog.test.ts", - "RequestResolver.test.ts", - ] - - deps = [ - "../../../../../front_end/core/platform:bundle", - "../../../../../front_end/core/sdk:bundle", - "../../../../../front_end/models/logs:bundle", - "../../core/common", - "../../core/sdk", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/persistence/BUILD.gn b/test/unittests/front_end/models/persistence/BUILD.gn deleted file mode 100644 index 8a4e4592fc..0000000000 --- a/test/unittests/front_end/models/persistence/BUILD.gn +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2021 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("persistence") { - testonly = true - sources = [ - "NetworkPersistenceManager.test.ts", - "PersistenceImpl.test.ts", - "PlatformFileSystem.test.ts", - ] - - deps = [ - "../../../../../front_end/core/platform:bundle", - "../../../../../front_end/core/sdk:bundle", - "../../../../../front_end/models/persistence:bundle", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/source_map_scopes/BUILD.gn b/test/unittests/front_end/models/source_map_scopes/BUILD.gn deleted file mode 100644 index f0ac7ebc59..0000000000 --- a/test/unittests/front_end/models/source_map_scopes/BUILD.gn +++ /dev/null @@ -1,21 +0,0 @@ -# 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("source_map_scopes") { - testonly = true - sources = [ - "NamesResolver.test.ts", - "ScopeTreeCache.test.ts", - ] - - deps = [ - "../../../../../front_end/core/platform:bundle", - "../../../../../front_end/core/sdk:bundle", - "../../../../../front_end/models/formatter:bundle", - "../../../../../front_end/models/source_map_scopes:bundle", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/text_utils/BUILD.gn b/test/unittests/front_end/models/text_utils/BUILD.gn deleted file mode 100644 index c4c3b9313a..0000000000 --- a/test/unittests/front_end/models/text_utils/BUILD.gn +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2021 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("text_utils") { - testonly = true - sources = [ - "ContentData.test.ts", - "StaticContentProvider.test.ts", - "StreamingContentData.test.ts", - "Text.test.ts", - "TextCursor.test.ts", - "TextRange.test.ts", - "TextUtils.test.ts", - ] - - deps = [ - "../../../../../front_end/core/platform:bundle", - "../../../../../front_end/models/text_utils:bundle", - ] -} diff --git a/test/unittests/front_end/models/timeline_model/BUILD.gn b/test/unittests/front_end/models/timeline_model/BUILD.gn deleted file mode 100644 index 9f0e679330..0000000000 --- a/test/unittests/front_end/models/timeline_model/BUILD.gn +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2021 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("timeline_model") { - testonly = true - sources = [ - "Initiators.test.ts", - "TimelineFrameBeginFrameQueue.test.ts", - "TimelineModel.test.ts", - "TimelineModelFilter.test.ts", - "TimelineProfileTree.test.ts", - ] - - deps = [ - "../../../../../front_end/models/timeline_model:bundle", - "../../../../../front_end/models/trace:bundle", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/trace/BUILD.gn b/test/unittests/front_end/models/trace/BUILD.gn deleted file mode 100644 index 7c69f10d18..0000000000 --- a/test/unittests/front_end/models/trace/BUILD.gn +++ /dev/null @@ -1,21 +0,0 @@ -# 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("trace") { - testonly = true - sources = [ - "EntriesFilter.test.ts", - "LegacyTracingModel.test.ts", - "ModelImpl.test.ts", - "Processor.test.ts", - "TracingManager.test.ts", - ] - - deps = [ - "../../../../../front_end/models/trace:bundle", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/trace/extras/BUILD.gn b/test/unittests/front_end/models/trace/extras/BUILD.gn deleted file mode 100644 index 7f939ac088..0000000000 --- a/test/unittests/front_end/models/trace/extras/BUILD.gn +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2023 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("../../../../../../third_party/typescript/typescript.gni") - -ts_library("extras") { - testonly = true - sources = [ - "FetchNodes.test.ts", - "FilmStrip.test.ts", - "MainThreadActivity.test.ts", - "Metadata.test.ts", - ] - - deps = [ - "../../../../../../front_end/core/platform:bundle", - "../../../../../../front_end/models/trace:bundle", - "../../../helpers", - ] -} diff --git a/test/unittests/front_end/models/trace/handlers/BUILD.gn b/test/unittests/front_end/models/trace/handlers/BUILD.gn deleted file mode 100644 index 5941f8cba8..0000000000 --- a/test/unittests/front_end/models/trace/handlers/BUILD.gn +++ /dev/null @@ -1,41 +0,0 @@ -# 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("../../../../../../third_party/typescript/typescript.gni") - -ts_library("handlers") { - testonly = true - sources = [ - "AnimationHandler.test.ts", - "AuctionWorkletsHandler.test.ts", - "FramesHandler.test.ts", - "GPUHandler.test.ts", - "InitiatorsHandler.test.ts", - "InvalidationsHandler.test.ts", - "LargestImagePaintHandler.test.ts", - "LargestTextPaintHandler.test.ts", - "LayerTreeHandler.test.ts", - "LayoutShiftsHandler.test.ts", - "MemoryHandler.test.ts", - "MetaHandler.test.ts", - "NetworkRequestsHandler.test.ts", - "PageLoadMetricsHandler.test.ts", - "RendererHandler.test.ts", - "SamplesHandler.test.ts", - "ScreenshotsHandler.test.ts", - "Threads.test.ts", - "UserInteractionsHandler.test.ts", - "UserTimingsHandler.test.ts", - "WarningsHandler.test.ts", - "WorkersHandler.test.ts", - ] - - deps = [ - "../../../../../../front_end/core/platform:bundle", - "../../../../../../front_end/generated", - "../../../../../../front_end/models/trace:bundle", - "../../../../../../front_end/panels/timeline:bundle", - "../../../helpers", - ] -} diff --git a/test/unittests/front_end/models/trace/handlers/FramesHandler.test.ts b/test/unittests/front_end/models/trace/handlers/FramesHandler.test.ts deleted file mode 100644 index 4991842b42..0000000000 --- a/test/unittests/front_end/models/trace/handlers/FramesHandler.test.ts +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2023 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. - -const {assert} = chai; -import * as TraceEngine from '../../../../../../front_end/models/trace/trace.js'; -import {TraceLoader} from '../../../helpers/TraceLoader.js'; -import {describeWithMockConnection} from '../../../helpers/MockConnection.js'; - -async function processTrace(events: readonly TraceEngine.Types.TraceEvents.TraceEventData[]): Promise { - // The FramesHandler depends on a few other handlers, so we run all of them as part of these tests. - const handlersInOrder: TraceEngine.Handlers.Types.TraceEventHandlerName[] = [ - 'Meta', - 'Samples', - 'AuctionWorklets', - 'Renderer', - 'LayerTree', - 'Frames', - ]; - for (const handlerName of handlersInOrder) { - const handler = TraceEngine.Handlers.ModelHandlers[handlerName]; - handler.reset(); - if ('initialize' in handler) { - handler.initialize(); - } - } - for (const event of events) { - for (const handlerName of handlersInOrder) { - TraceEngine.Handlers.ModelHandlers[handlerName].handleEvent(event); - } - } - for (const handlerName of handlersInOrder) { - const handler = TraceEngine.Handlers.ModelHandlers[handlerName]; - if ('finalize' in handler) { - await handler.finalize(); - } - } -} - -describeWithMockConnection('FramesHandler', () => { - it('can parse out a trace and return the frames', async function() { - const rawEvents = await TraceLoader.rawEvents(this, 'web-dev-with-commit.json.gz'); - await processTrace(rawEvents); - - const parsedFrames = TraceEngine.Handlers.ModelHandlers.Frames.data().frames; - assert.lengthOf(parsedFrames, 18); - - // Assert a couple of frames to check the data, including one that is partial and was dropped. - assert.strictEqual(parsedFrames[0].startTime, 122411104714); - assert.strictEqual(parsedFrames[0].duration, 37847); - assert.isFalse(parsedFrames[0].isPartial); - assert.isFalse(parsedFrames[0].isPartial); - - assert.strictEqual(parsedFrames[2].startTime, 122411159244); - assert.strictEqual(parsedFrames[2].duration, 16683); - assert.isTrue(parsedFrames[2].isPartial); - assert.isTrue(parsedFrames[2].dropped); - }); - - it('can create LayerPaintEvents from Paint and snapshot events', async function() { - // Advanced instrumentation trace file is large: allow the bots more time - // to process it. - this.timeout(20_000); - - const rawEvents = await TraceLoader.rawEvents(this, 'web-dev-with-advanced-instrumentation.json.gz'); - await processTrace(rawEvents); - const parsedFrames = TraceEngine.Handlers.ModelHandlers.Frames.data().frames; - assert.lengthOf(parsedFrames, 25); - const frameWithPaints = parsedFrames.at(2); - if (!frameWithPaints) { - throw new Error('Could not find frame at index 2'); - } - // Check we have the right one. - assert.strictEqual(frameWithPaints.seqId, 1127448); - assert.lengthOf(frameWithPaints.paints, 7); - }); - - it('can return frames within a given window', async function() { - const rawEvents = await TraceLoader.rawEvents(this, 'web-dev-with-commit.json.gz'); - await processTrace(rawEvents); - - const parsedFrames = TraceEngine.Handlers.ModelHandlers.Frames.data().frames; - assert.lengthOf(parsedFrames, 18); - - const startTime = TraceEngine.Types.Timing.MicroSeconds(parsedFrames[0].startTime); - const endTime = TraceEngine.Types.Timing.MicroSeconds(parsedFrames[3].endTime); - const framesWithinWindow = - TraceEngine.Handlers.ModelHandlers.Frames.framesWithinWindow(parsedFrames, startTime, endTime); - assert.deepEqual(framesWithinWindow, [ - parsedFrames[0], - parsedFrames[1], - parsedFrames[2], - parsedFrames[3], - ]); - }); -}); diff --git a/test/unittests/front_end/models/trace/helpers/BUILD.gn b/test/unittests/front_end/models/trace/helpers/BUILD.gn deleted file mode 100644 index 15195d5e7e..0000000000 --- a/test/unittests/front_end/models/trace/helpers/BUILD.gn +++ /dev/null @@ -1,21 +0,0 @@ -# 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("../../../../../../third_party/typescript/typescript.gni") - -ts_library("helpers") { - testonly = true - sources = [ - "SamplesIntegrator.test.ts", - "Timing.test.ts", - "Trace.test.ts", - "TreeHelpers.test.ts", - ] - - deps = [ - "../../../../../../front_end/core/platform:bundle", - "../../../../../../front_end/models/trace:bundle", - "../../../helpers", - ] -} diff --git a/test/unittests/front_end/models/trace/root-causes/BUILD.gn b/test/unittests/front_end/models/trace/root-causes/BUILD.gn deleted file mode 100644 index 078178512e..0000000000 --- a/test/unittests/front_end/models/trace/root-causes/BUILD.gn +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2023 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("../../../../../../third_party/typescript/typescript.gni") - -ts_library("root-causes") { - testonly = true - sources = [ "LayoutShift.test.ts" ] - - deps = [ - "../../../../../../front_end/core/platform:bundle", - "../../../../../../front_end/models/trace:bundle", - "../../../helpers", - ] -} diff --git a/test/unittests/front_end/models/trace/types/BUILD.gn b/test/unittests/front_end/models/trace/types/BUILD.gn deleted file mode 100644 index e9129d6980..0000000000 --- a/test/unittests/front_end/models/trace/types/BUILD.gn +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2023 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("../../../../../../third_party/typescript/typescript.gni") - -ts_library("types") { - testonly = true - sources = [ "TraceEvents.test.ts" ] - - deps = [ - "../../../../../../front_end/core/platform:bundle", - "../../../../../../front_end/models/trace:bundle", - "../../../helpers", - ] -} diff --git a/test/unittests/front_end/models/workspace/BUILD.gn b/test/unittests/front_end/models/workspace/BUILD.gn deleted file mode 100644 index 6f8a3078ca..0000000000 --- a/test/unittests/front_end/models/workspace/BUILD.gn +++ /dev/null @@ -1,21 +0,0 @@ -# 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("workspace") { - testonly = true - sources = [ - "SearchConfig.test.ts", - "UISourceCode.test.ts", - "WorkspaceImpl.test.ts", - ] - - deps = [ - "../../../../../front_end/core/common:bundle", - "../../../../../front_end/models/persistence:bundle", - "../../../../../front_end/models/workspace:bundle", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/models/workspace_diff/BUILD.gn b/test/unittests/front_end/models/workspace_diff/BUILD.gn deleted file mode 100644 index 08523a8d2c..0000000000 --- a/test/unittests/front_end/models/workspace_diff/BUILD.gn +++ /dev/null @@ -1,18 +0,0 @@ -# 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("../../../../../third_party/typescript/typescript.gni") - -ts_library("workspace_diff") { - testonly = true - sources = [ "WorkspaceDiff.test.ts" ] - - deps = [ - "../../../../../front_end/core/common:bundle", - "../../../../../front_end/models/persistence:bundle", - "../../../../../front_end/models/workspace:bundle", - "../../../../../front_end/models/workspace_diff:bundle", - "../../helpers", - ] -} diff --git a/test/unittests/front_end/panels/issues/BUILD.gn b/test/unittests/front_end/panels/issues/BUILD.gn index 90570b03f4..b5845df623 100644 --- a/test/unittests/front_end/panels/issues/BUILD.gn +++ b/test/unittests/front_end/panels/issues/BUILD.gn @@ -18,6 +18,5 @@ ts_library("issues") { "../../../../../front_end/panels/issues:bundle", "../../core/sdk", "../../helpers", - "../../models/issues_manager", ] } diff --git a/test/unittests/front_end/panels/issues/IssueAggregator.test.ts b/test/unittests/front_end/panels/issues/IssueAggregator.test.ts index 4314799ca9..9c500d0fec 100644 --- a/test/unittests/front_end/panels/issues/IssueAggregator.test.ts +++ b/test/unittests/front_end/panels/issues/IssueAggregator.test.ts @@ -2,18 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -const {assert} = chai; - -import * as Issues from '../../../../../front_end/panels/issues/issues.js'; import type * as Common from '../../../../../front_end/core/common/common.js'; -import * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; -import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import {StubIssue} from '../../models/issues_manager/StubIssue.js'; -import {MockIssuesManager} from '../../models/issues_manager/MockIssuesManager.js'; -import * as Protocol from '../../../../../front_end/generated/protocol.js'; -import {createFakeSetting, describeWithEnvironment, createTarget} from '../../helpers/EnvironmentHelpers.js'; -import {describeWithMockConnection} from '../../helpers/MockConnection.js'; import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; +import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; +import * as Protocol from '../../../../../front_end/generated/protocol.js'; +import * as IssuesManager from '../../../../../front_end/models/issues_manager/issues_manager.js'; +import * as Issues from '../../../../../front_end/panels/issues/issues.js'; +import {createFakeSetting, createTarget, describeWithEnvironment} from '../../helpers/EnvironmentHelpers.js'; +import {describeWithMockConnection} from '../../helpers/MockConnection.js'; +import {MockIssuesManager} from '../../helpers/MockIssuesManager.js'; +import {StubIssue} from '../../helpers/StubIssue.js'; + +const {assert} = chai; describeWithEnvironment('AggregatedIssue', async () => { const aggregationKey = 'key' as unknown as Issues.IssueAggregator.AggregationKey; diff --git a/test/unittests/front_end/panels/issues/IssueView.test.ts b/test/unittests/front_end/panels/issues/IssueView.test.ts index 4e55dbe19e..c3dcb72c29 100644 --- a/test/unittests/front_end/panels/issues/IssueView.test.ts +++ b/test/unittests/front_end/panels/issues/IssueView.test.ts @@ -6,8 +6,8 @@ import * as Host from '../../../../../front_end/core/host/host.js'; import * as Issues from '../../../../../front_end/panels/issues/issues.js'; import * as UI from '../../../../../front_end/ui/legacy/legacy.js'; import {describeWithRealConnection} from '../../helpers/RealConnection.js'; +import {StubIssue} from '../../helpers/StubIssue.js'; import {recordedMetricsContain} from '../../helpers/UserMetricsHelpers.js'; -import {StubIssue} from '../../models/issues_manager/StubIssue.js'; const {assert} = chai; diff --git a/test/unittests/front_end/panels/timeline/BUILD.gn b/test/unittests/front_end/panels/timeline/BUILD.gn index 4a6f00bb87..8606bb6760 100644 --- a/test/unittests/front_end/panels/timeline/BUILD.gn +++ b/test/unittests/front_end/panels/timeline/BUILD.gn @@ -9,6 +9,7 @@ ts_library("timeline") { sources = [ "Breadcrumbs.test.ts", "EventTypeHelpers.test.ts", + "Initiators.test.ts", "SaveFileFormatter.test.ts", "SourceMapsResolver.test.ts", "TimelineController.test.ts", diff --git a/test/unittests/front_end/models/timeline_model/Initiators.test.ts b/test/unittests/front_end/panels/timeline/Initiators.test.ts similarity index 100% rename from test/unittests/front_end/models/timeline_model/Initiators.test.ts rename to test/unittests/front_end/panels/timeline/Initiators.test.ts diff --git a/test/unittests/front_end/ui/components/issue_counter/BUILD.gn b/test/unittests/front_end/ui/components/issue_counter/BUILD.gn index db006d802e..9602f0fd6b 100644 --- a/test/unittests/front_end/ui/components/issue_counter/BUILD.gn +++ b/test/unittests/front_end/ui/components/issue_counter/BUILD.gn @@ -17,6 +17,5 @@ ts_library("issue_counter") { "../../../../../../front_end/ui/components/issue_counter:bundle", "../../../../../../front_end/ui/legacy:bundle", "../../../helpers", - "../../../models/issues_manager", ] } diff --git a/test/unittests/front_end/ui/components/issue_counter/IssueCounter.test.ts b/test/unittests/front_end/ui/components/issue_counter/IssueCounter.test.ts index cd33df2b87..4970396344 100644 --- a/test/unittests/front_end/ui/components/issue_counter/IssueCounter.test.ts +++ b/test/unittests/front_end/ui/components/issue_counter/IssueCounter.test.ts @@ -8,7 +8,7 @@ import * as IconButton from '../../../../../../front_end/ui/components/icon_butt import * as IssueCounter from '../../../../../../front_end/ui/components/issue_counter/issue_counter.js'; import {assertElement, assertElements, assertShadowRoot, renderElementIntoDOM} from '../../../helpers/DOMHelpers.js'; import {describeWithLocale} from '../../../helpers/EnvironmentHelpers.js'; -import {MockIssuesManager} from '../../../models/issues_manager/MockIssuesManager.js'; +import {MockIssuesManager} from '../../../helpers/MockIssuesManager.js'; const {assert} = chai; diff --git a/test/unittests/karma.conf.js b/test/unittests/karma.conf.js index a1ea42e1eb..cafb0c923f 100644 --- a/test/unittests/karma.conf.js +++ b/test/unittests/karma.conf.js @@ -76,12 +76,11 @@ if (HTML_COVERAGE_ENABLED) { istanbulReportOutputs.push({type: 'html'}); } -const UNIT_TESTS_ROOT_FOLDER = path.join(ROOT_DIRECTORY, 'test', 'unittests'); -const UNIT_TESTS_FOLDERS = [ - path.join(UNIT_TESTS_ROOT_FOLDER, 'front_end'), - path.join(UNIT_TESTS_ROOT_FOLDER, 'inspector_overlay'), -]; -const TEST_SOURCES = UNIT_TESTS_FOLDERS.map(folder => path.join(folder, '**/*.ts')); +const TEST_SOURCES = [ + path.join('front_end', '**/*.test.ts'), + path.join('test', 'unittests', 'front_end', '**/*.ts'), + path.join('test', 'unittests', 'inspector_overlay', '**/*.ts'), +].map(relativePath => path.join(ROOT_DIRECTORY, relativePath)); // To make sure that any leftover JavaScript files (e.g. that were outputs from now-removed tests) // aren't incorrectly included, we glob for the TypeScript files instead and use that @@ -91,7 +90,7 @@ const TEST_FILES = .map(source => { return glob.sync(source).map(fileName => { const jsFile = fileName.replace(/\.ts$/, '.js'); - const generatedJsFile = path.join(__dirname, path.relative(UNIT_TESTS_ROOT_FOLDER, jsFile)); + const generatedJsFile = path.join(GEN_DIRECTORY, path.relative(ROOT_DIRECTORY, jsFile)); if (!fs.existsSync(generatedJsFile)) { throw new Error(`Test file ${fileName} is not included in a BUILD.gn and therefore will not be run.`); } diff --git a/third_party/i18n/collect-strings.js b/third_party/i18n/collect-strings.js index bc2afe8f57..2c622eb99f 100644 --- a/third_party/i18n/collect-strings.js +++ b/third_party/i18n/collect-strings.js @@ -27,6 +27,7 @@ const IGNORED_PATH_COMPONENTS = [ '**/.git/**', '**/*_test_runner/**', '**/third_party/**', + '**/*.test.ts', ]; /**