From 465ceddbdbf2cb894c455de132fa13c9fade7e53 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Mon, 14 Jun 2021 12:22:40 +0100 Subject: [PATCH] Update assertNotNull to also check for `undefined` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `NonNullable` type in TypeScript already excludes `undefined` from the possible types, but we weren't properly checking for it in the if-statement. R=szuend@chromium.org CC=pfaffe@chromium.org Bug: none Change-Id: I9320f0c7662d46d562d6544f35d45380043d4409 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2960173 Auto-Submit: Tim van der Lippe Reviewed-by: Simon Zünd Commit-Queue: Tim van der Lippe --- front_end/core/platform/platform.ts | 2 +- .../core/platform/typescript-utilities.ts | 6 +-- scripts/eslint_rules/lib/es_modules_import.js | 2 +- .../front_end/core/common/Color_test.ts | 44 +++++++++---------- .../core/common/ResourceType_test.ts | 16 +++---- .../front_end/core/sdk/Cookie_test.ts | 6 +-- .../front_end/core/sdk/SourceMap_test.ts | 8 ++-- .../components/RequestTrustTokensView_test.ts | 6 +-- test/unittests/front_end/ui/Geometry_test.ts | 4 +- .../front_end/ui/Treeoutline-keyboard_test.ts | 8 ++-- .../ui/components/DataGridController_test.ts | 4 +- .../ui/components/SurveyLink_test.ts | 14 +++--- .../issue_counter/IssueCounter_test.ts | 4 +- .../LinearMemoryInspectorPane_test.ts | 4 +- .../inline_editor/CSSVarSwatch_test.ts | 6 +-- .../inline_editor/ColorSwatch_test.ts | 6 +-- .../components/perf_ui/PieChart_test.ts | 24 +++++----- .../legacy/components/utils/Linkifier_test.ts | 24 +++++----- 18 files changed, 94 insertions(+), 94 deletions(-) diff --git a/front_end/core/platform/platform.ts b/front_end/core/platform/platform.ts index 8f115921d6..70997dc395 100644 --- a/front_end/core/platform/platform.ts +++ b/front_end/core/platform/platform.ts @@ -46,7 +46,7 @@ export {DCHECK} from './dcheck.js'; * (e.g. `Platform.TypeScriptUtilities.assertNotNull` causes a * compiler error) */ -export {assertNotNull, assertUnhandled} from './typescript-utilities.js'; +export {assertNotNullOrUndefined, assertUnhandled} from './typescript-utilities.js'; export {assertNever, runOnWindowLoad} from './utilities.js'; export { ArrayUtilities, diff --git a/front_end/core/platform/typescript-utilities.ts b/front_end/core/platform/typescript-utilities.ts index bc0ee6ffe2..1f72457ee8 100644 --- a/front_end/core/platform/typescript-utilities.ts +++ b/front_end/core/platform/typescript-utilities.ts @@ -7,9 +7,9 @@ * that's potentially `null` you can use this function to assert that it isn't, * and satisfy TypeScript that the value is present. */ -export function assertNotNull(val: T): asserts val is NonNullable { - if (val === null) { - throw new Error(`Expected given value to not be null but it was: ${val}`); +export function assertNotNullOrUndefined(val: T): asserts val is NonNullable { + if (val === null || val === undefined) { + throw new Error(`Expected given value to not be null/undefined but it was: ${val}`); } } diff --git a/scripts/eslint_rules/lib/es_modules_import.js b/scripts/eslint_rules/lib/es_modules_import.js index 83687d7a4d..f8e36ec7b8 100644 --- a/scripts/eslint_rules/lib/es_modules_import.js +++ b/scripts/eslint_rules/lib/es_modules_import.js @@ -64,7 +64,7 @@ function checkImportExtension(importPath, context, node) { function nodeSpecifiersSpecialImportsOnly(specifiers) { return specifiers.length === 1 && specifiers[0].type === 'ImportSpecifier' && - ['ls', 'assertNotNull'].includes(specifiers[0].imported.name); + ['ls', 'assertNotNullOrUndefined'].includes(specifiers[0].imported.name); } function checkStarImport(context, node, importPath, importingFileName, exportingFileName) { diff --git a/test/unittests/front_end/core/common/Color_test.ts b/test/unittests/front_end/core/common/Color_test.ts index e15d527aed..cd75808db0 100644 --- a/test/unittests/front_end/core/common/Color_test.ts +++ b/test/unittests/front_end/core/common/Color_test.ts @@ -5,13 +5,13 @@ const {assert} = chai; import * as Common from '../../../../../front_end/core/common/common.js'; -import {assertNotNull} from '../../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; const Color = Common.Color; const parseAndAssertNotNull = (value: string) => { const result = Color.Color.parse(value); - assertNotNull(result); + assertNotNullOrUndefined(result); return result; }; @@ -84,53 +84,53 @@ describe('Color', () => { it('parses rgb(a) values', () => { const colorOne = Color.Color.parse('rgb(255, 255, 0)'); - assertNotNull(colorOne); + assertNotNullOrUndefined(colorOne); assert.deepEqual(colorOne.rgba(), [1, 1, 0, 1]); const colorTwo = Color.Color.parse('rgba(0, 255, 255, 0.5)'); - assertNotNull(colorTwo); + assertNotNullOrUndefined(colorTwo); assert.deepEqual(colorTwo.rgba(), [0, 1, 1, 0.5]); const colorThree = Color.Color.parse('rgb(255 255 255)'); - assertNotNull(colorThree); + assertNotNullOrUndefined(colorThree); assert.deepEqual(colorThree.rgba(), [1, 1, 1, 1]); const colorFour = Color.Color.parse('rgb(10% 10% 10%)'); - assertNotNull(colorFour); + assertNotNullOrUndefined(colorFour); assert.deepEqual(colorFour.rgba(), [0.1, 0.1, 0.1, 1]); const colorFive = Color.Color.parse('rgb(10% 10% 10% / 0.4)'); - assertNotNull(colorFive); + assertNotNullOrUndefined(colorFive); assert.deepEqual(colorFive.rgba(), [0.1, 0.1, 0.1, 0.4]); const colorSix = Color.Color.parse('rgb(10% 10% 10% / 40%)'); - assertNotNull(colorSix); + assertNotNullOrUndefined(colorSix); assert.deepEqual(colorSix.rgba(), [0.1, 0.1, 0.1, 0.4]); }); it('parses hsl(a) values', () => { const colorOne = Color.Color.parse('hsl(0, 100%, 50%)'); - assertNotNull(colorOne); + assertNotNullOrUndefined(colorOne); assert.deepEqual(colorOne.rgba(), [1, 0, 0, 1]); const colorTwo = Color.Color.parse('hsla(0, 100%, 50%, 0.5)'); - assertNotNull(colorTwo); + assertNotNullOrUndefined(colorTwo); assert.deepEqual(colorTwo.rgba(), [1, 0, 0, 0.5]); const colorThree = Color.Color.parse('hsla(50deg 100% 100% / 50%)'); - assertNotNull(colorThree); + assertNotNullOrUndefined(colorThree); assert.deepEqual(colorThree.rgba(), [1, 1, 1, 0.5]); const colorFour = Color.Color.parse('hsl(0 100% 50% / 0.5)'); - assertNotNull(colorFour); + assertNotNullOrUndefined(colorFour); assert.deepEqual(colorFour.rgba(), [1, 0, 0, 0.5]); const colorFive = Color.Color.parse('hsl(0 100% 50% / 50%)'); - assertNotNull(colorFive); + assertNotNullOrUndefined(colorFive); assert.deepEqual(colorFive.rgba(), [1, 0, 0, 0.5]); const colorSix = Color.Color.parse('hsl(0deg 100% 50% / 50%)'); - assertNotNull(colorSix); + assertNotNullOrUndefined(colorSix); assert.deepEqual(colorSix.rgba(), [1, 0, 0, 0.5]); }); @@ -338,10 +338,10 @@ describe('Color', () => { for (const {fgColor, bgColor, contrast, result} of colors) { const fgParsed = Color.Color.parse(fgColor); const bgParsed = Color.Color.parse(bgColor); - assertNotNull(fgParsed); - assertNotNull(bgParsed); + assertNotNullOrUndefined(fgParsed); + assertNotNullOrUndefined(bgParsed); const suggestedColor = Color.Color.findFgColorForContrast(fgParsed, bgParsed, contrast); - assertNotNull(suggestedColor); + assertNotNullOrUndefined(suggestedColor); assert.strictEqual( suggestedColor.asString(), result, `incorrect color suggestion for ${fgColor}/${bgColor} with contrast ${contrast}`); @@ -379,10 +379,10 @@ describe('Color', () => { for (const test of tests) { const fg = Common.Color.Color.parse(test.fgColor); const bg = Common.Color.Color.parse(test.bgColor); - assertNotNull(fg); - assertNotNull(bg); + assertNotNullOrUndefined(fg); + assertNotNullOrUndefined(bg); const result = Common.Color.Color.findFgColorForContrastAPCA(fg, bg, test.requiredContrast); - assertNotNull(result); + assertNotNullOrUndefined(result); const absContrast = Math.abs(Common.ColorUtils.contrastRatioAPCA(result.rgba() || [], bg.rgba())); assert.isTrue(Math.round(absContrast) >= test.requiredContrast); } @@ -404,8 +404,8 @@ describe('Color', () => { for (const test of tests) { const fg = Common.Color.Color.parse(test.fgColor); const bg = Common.Color.Color.parse(test.bgColor); - assertNotNull(fg); - assertNotNull(bg); + assertNotNullOrUndefined(fg); + assertNotNullOrUndefined(bg); const result = Common.Color.Color.findFgColorForContrastAPCA(fg, bg, test.requiredContrast); assert.isNull(result); } diff --git a/test/unittests/front_end/core/common/ResourceType_test.ts b/test/unittests/front_end/core/common/ResourceType_test.ts index 5be291acf2..ef58e1b335 100644 --- a/test/unittests/front_end/core/common/ResourceType_test.ts +++ b/test/unittests/front_end/core/common/ResourceType_test.ts @@ -5,7 +5,7 @@ const {assert} = chai; import * as Common from '../../../../../front_end/core/common/common.js'; -import {assertNotNull} from '../../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; import type * as Platform from '../../../../../front_end/core/platform/platform.js'; const ResourceType = Common.ResourceType.ResourceType; @@ -120,7 +120,7 @@ describe('ResourceType class', () => { it('is able to return an wasm resource from the string "application/wasm"', () => { const result = ResourceType.fromMimeTypeOverride('application/wasm'); - assertNotNull(result); + assertNotNullOrUndefined(result); assert.instanceOf(result, ResourceType, 'result type is incorrect'); assert.strictEqual(result.name(), 'wasm', 'name was not set correctly'); assert.strictEqual(result.title(), 'Wasm', 'title was not set correctly'); @@ -131,7 +131,7 @@ describe('ResourceType class', () => { it('is able to return an web bundle resource from the string "application/webbundle"', () => { const result = ResourceType.fromMimeTypeOverride('application/webbundle'); - assertNotNull(result); + assertNotNullOrUndefined(result); assert.instanceOf(result, ResourceType, 'result type is incorrect'); assert.strictEqual(result.name(), 'webbundle', 'name was not set correctly'); assert.strictEqual(result.title(), 'WebBundle', 'title was not set correctly'); @@ -152,7 +152,7 @@ describe('ResourceType class', () => { it('is able to return a resource type from a URL that contains a mapped extension', () => { const result = ResourceType.fromURL('http://www.example.com/test/testFile.js'); - assertNotNull(result); + assertNotNullOrUndefined(result); assert.instanceOf(result, ResourceType, 'result type is incorrect'); assert.strictEqual(result.name(), 'script', 'name was not set correctly'); assert.strictEqual(result.title(), 'Script', 'title was not set correctly'); @@ -163,7 +163,7 @@ describe('ResourceType class', () => { it('is able to return a resource type from a URL that ends in .avif', () => { const result = ResourceType.fromURL('https://host.example/image.avif'); - assertNotNull(result); + assertNotNullOrUndefined(result); assert.instanceOf(result, ResourceType, 'result type is incorrect'); assert.strictEqual(result.name(), 'image', 'name was not set correctly'); assert.strictEqual(result.title(), 'Image', 'title was not set correctly'); @@ -174,7 +174,7 @@ describe('ResourceType class', () => { it('is able to return a resource type from a URL that ends in .jxl', () => { const result = ResourceType.fromURL('https://host.example/image.jxl'); - assertNotNull(result); + assertNotNullOrUndefined(result); assert.instanceOf(result, ResourceType, 'result type is incorrect'); assert.strictEqual(result.name(), 'image', 'name was not set correctly'); assert.strictEqual(result.title(), 'Image', 'title was not set correctly'); @@ -185,7 +185,7 @@ describe('ResourceType class', () => { it('is able to return a resource type from a URL that ends in .woff2', () => { const result = ResourceType.fromURL('https://host.example/image.woff2'); - assertNotNull(result); + assertNotNullOrUndefined(result); assert.instanceOf(result, ResourceType, 'result type is incorrect'); assert.strictEqual(result.name(), 'font', 'name was not set correctly'); assert.strictEqual(result.title(), 'Font', 'title was not set correctly'); @@ -201,7 +201,7 @@ describe('ResourceType class', () => { it('is able to return a resource type from a mapped name', () => { const result = ResourceType.fromName('script'); - assertNotNull(result); + assertNotNullOrUndefined(result); assert.instanceOf(result, ResourceType, 'result type is incorrect'); assert.strictEqual(result.name(), 'script', 'name was not set correctly'); assert.strictEqual(result.title(), 'Script', 'title was not set correctly'); diff --git a/test/unittests/front_end/core/sdk/Cookie_test.ts b/test/unittests/front_end/core/sdk/Cookie_test.ts index 88cf6eaca5..e07ace8eec 100644 --- a/test/unittests/front_end/core/sdk/Cookie_test.ts +++ b/test/unittests/front_end/core/sdk/Cookie_test.ts @@ -5,7 +5,7 @@ const {assert} = chai; import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import {assertNotNull} from '../../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; import * as Protocol from '../../../../../front_end/generated/protocol.js'; describe('Cookie', () => { @@ -205,7 +205,7 @@ describe('Cookie', () => { const expires = Math.floor(now.getTime()) + 3600 * 1000; cookie.addAttribute('Max-Age', '3600'); const expiresDate = cookie.expiresDate(now); - assertNotNull(expiresDate); + assertNotNullOrUndefined(expiresDate); assert.strictEqual(expiresDate.toISOString(), new Date(expires).toISOString()); }); @@ -215,7 +215,7 @@ describe('Cookie', () => { const expires = Math.floor(now.getTime()) + 3600 * 1000; cookie.addAttribute('Expires', expires); const expiresDate = cookie.expiresDate(now); - assertNotNull(expiresDate); + assertNotNullOrUndefined(expiresDate); assert.strictEqual(expiresDate.toISOString(), new Date(expires).toISOString()); }); diff --git a/test/unittests/front_end/core/sdk/SourceMap_test.ts b/test/unittests/front_end/core/sdk/SourceMap_test.ts index 8e4499e2c2..4d99e18d94 100644 --- a/test/unittests/front_end/core/sdk/SourceMap_test.ts +++ b/test/unittests/front_end/core/sdk/SourceMap_test.ts @@ -5,7 +5,7 @@ const {assert} = chai; import * as SDK from '../../../../../front_end/core/sdk/sdk.js'; -import {assertNotNull} from '../../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; const fakeInitiator = { target: null, @@ -77,7 +77,7 @@ describe('TextSourceMap', () => { function assertMapping( actual: SDK.SourceMap.SourceMapEntry|null, expectedSourceURL: string|undefined, expectedSourceLineNumber: number|undefined, expectedSourceColumnNumber: number|undefined) { - assertNotNull(actual); + assertNotNullOrUndefined(actual); assert.strictEqual(actual.sourceURL, expectedSourceURL, 'unexpected source URL'); assert.strictEqual(actual.sourceLineNumber, expectedSourceLineNumber, 'unexpected source line number'); assert.strictEqual(actual.sourceColumnNumber, expectedSourceColumnNumber, 'unexpected source column number'); @@ -86,7 +86,7 @@ describe('TextSourceMap', () => { function assertReverseMapping( actual: SDK.SourceMap.SourceMapEntry|null, expectedCompiledLineNumber: number, expectedCompiledColumnNumber: number) { - assertNotNull(actual); + assertNotNullOrUndefined(actual); assert.strictEqual(actual.lineNumber, expectedCompiledLineNumber, 'unexpected compiled line number'); assert.strictEqual(actual.columnNumber, expectedCompiledColumnNumber, 'unexpected compiled column number'); } @@ -158,7 +158,7 @@ describe('TextSourceMap', () => { assertMapping(sourceMap.findEntry(0, 2), 'example.js', 0, 2); const emptyEntry = sourceMap.findEntry(0, 1); - assertNotNull(emptyEntry); + assertNotNullOrUndefined(emptyEntry); assert.isUndefined(emptyEntry.sourceURL, 'unexpected url present for empty segment'); assert.isUndefined(emptyEntry.sourceLineNumber, 'unexpected source line number for empty segment'); assert.isUndefined(emptyEntry.sourceColumnNumber, 'unexpected source line number for empty segment'); diff --git a/test/unittests/front_end/panels/network/components/RequestTrustTokensView_test.ts b/test/unittests/front_end/panels/network/components/RequestTrustTokensView_test.ts index d848b4f44f..0f0e82d96a 100644 --- a/test/unittests/front_end/panels/network/components/RequestTrustTokensView_test.ts +++ b/test/unittests/front_end/panels/network/components/RequestTrustTokensView_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 {assertNotNull} from '../../../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../../../front_end/core/platform/platform.js'; import * as Protocol from '../../../../../../front_end/generated/protocol.js'; import * as NetworkComponents from '../../../../../../front_end/panels/network/components/components.js'; import {getElementsWithinComponent, getElementWithinComponent, renderElementIntoDOM} from '../../../helpers/DOMHelpers.js'; @@ -58,7 +58,7 @@ describe('RequestTrustTokensView', () => { }; const simpleText = getElementWithinComponent(component, 'span > strong', HTMLElement); - assertNotNull(simpleText); + assertNotNullOrUndefined(simpleText); assert.strictEqual(simpleText.textContent, 'Success'); }); @@ -73,7 +73,7 @@ describe('RequestTrustTokensView', () => { }; const simpleText = getElementWithinComponent(component, 'span > strong', HTMLElement); - assertNotNull(simpleText); + assertNotNullOrUndefined(simpleText); assert.strictEqual(simpleText.textContent, 'Failure'); }); }); diff --git a/test/unittests/front_end/ui/Geometry_test.ts b/test/unittests/front_end/ui/Geometry_test.ts index 99f6d391ec..3e55f97e22 100644 --- a/test/unittests/front_end/ui/Geometry_test.ts +++ b/test/unittests/front_end/ui/Geometry_test.ts @@ -5,7 +5,7 @@ const {assert} = chai; import * as UI from '../../../../front_end/ui/legacy/legacy.js'; -import {assertNotNull} from '../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../front_end/core/platform/platform.js'; describe('Vector', () => { it('can be instantiated without issues', () => { @@ -99,7 +99,7 @@ describe('CubicBezier', () => { it('is able to return a cubic bezier from a valid string', () => { const testText = 'linear'; const cubicBezier = UI.Geometry.CubicBezier.parse(testText); - assertNotNull(cubicBezier); + assertNotNullOrUndefined(cubicBezier); assert.strictEqual(cubicBezier.controlPoints[0].x, 0, 'x value for the first point was not set correctly'); assert.strictEqual(cubicBezier.controlPoints[0].y, 0, 'y value for the first point was not set correctly'); assert.strictEqual(cubicBezier.controlPoints[1].x, 1, 'x value for the second point was not set correctly'); diff --git a/test/unittests/front_end/ui/Treeoutline-keyboard_test.ts b/test/unittests/front_end/ui/Treeoutline-keyboard_test.ts index 21ac50801b..f60ce7a4b2 100644 --- a/test/unittests/front_end/ui/Treeoutline-keyboard_test.ts +++ b/test/unittests/front_end/ui/Treeoutline-keyboard_test.ts @@ -6,7 +6,7 @@ const {assert} = chai; import * as UI from '../../../../front_end/ui/legacy/legacy.js'; -import {assertNotNull} from '../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../front_end/core/platform/platform.js'; import {renderElementIntoDOM} from '../helpers/DOMHelpers.js'; describe('TreeOutline', () => { @@ -26,7 +26,7 @@ describe('TreeOutline', () => { }); const firstChild = treeOutline.firstChild(); - assertNotNull(firstChild); + assertNotNullOrUndefined(firstChild); firstChild.select(false, true); const distance = 25; @@ -74,7 +74,7 @@ describe('TreeOutline', () => { treeOutline.appendChild(treeElementForNestedTree); const innerFirstChild = innerTreeOutline.firstChild(); - assertNotNull(innerFirstChild); + assertNotNullOrUndefined(innerFirstChild); innerFirstChild.select(false, true); sendKey('ArrowRight'); @@ -82,7 +82,7 @@ describe('TreeOutline', () => { function sendKey(key: string) { const deepActiveElement = document.deepActiveElement(); - assertNotNull(deepActiveElement); + assertNotNullOrUndefined(deepActiveElement); const keyEvent = new KeyboardEvent('keydown', {bubbles: true, cancelable: true, key}); deepActiveElement.dispatchEvent(keyEvent); } diff --git a/test/unittests/front_end/ui/components/DataGridController_test.ts b/test/unittests/front_end/ui/components/DataGridController_test.ts index f0730fd88a..9d4d45a1e7 100644 --- a/test/unittests/front_end/ui/components/DataGridController_test.ts +++ b/test/unittests/front_end/ui/components/DataGridController_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 {assertNotNull} from '../../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; import * as DataGrid from '../../../../../front_end/ui/components/data_grid/data_grid.js'; import * as Coordinator from '../../../../../front_end/ui/components/render_coordinator/render_coordinator.js'; import {assertShadowRoot, dispatchClickEvent, renderElementIntoDOM} from '../../helpers/DOMHelpers.js'; @@ -17,7 +17,7 @@ const coordinator = Coordinator.RenderCoordinator.RenderCoordinator.instance(); const getInternalDataGridShadowRoot = (component: DataGrid.DataGridController.DataGridController): ShadowRoot => { assertShadowRoot(component.shadowRoot); const internalDataGrid = component.shadowRoot.querySelector('devtools-data-grid'); - assertNotNull(internalDataGrid); + assertNotNullOrUndefined(internalDataGrid); const internalShadow = internalDataGrid.shadowRoot; assertShadowRoot(internalShadow); return internalShadow; diff --git a/test/unittests/front_end/ui/components/SurveyLink_test.ts b/test/unittests/front_end/ui/components/SurveyLink_test.ts index c18c3f1836..c69af412b7 100644 --- a/test/unittests/front_end/ui/components/SurveyLink_test.ts +++ b/test/unittests/front_end/ui/components/SurveyLink_test.ts @@ -6,7 +6,7 @@ const {assert} = chai; import * as SurveyLink from '../../../../../front_end/ui/components/survey_link/survey_link.js'; import * as Common from '../../../../../front_end/core/common/common.js'; -import {assertNotNull} from '../../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../../front_end/core/platform/platform.js'; import {assertShadowRoot, renderElementIntoDOM} from '../../helpers/DOMHelpers.js'; function canShowSuccessfulCallback(trigger: string, callback: SurveyLink.SurveyLink.CanShowSurveyCallback) { @@ -63,7 +63,7 @@ describe('SurveyLink', async () => { assertShadowRoot(link.shadowRoot); const linkNode = link.shadowRoot.querySelector('button'); - assertNotNull(linkNode); + assertNotNullOrUndefined(linkNode); assert.notInclude(linkNode.textContent?.trim(), '…'); linkNode.click(); @@ -71,7 +71,7 @@ describe('SurveyLink', async () => { // The only output signal we have is the link text which we don't want to assert exactly, so we // assume that the pending state has an elipsis. const pendingLink = link.shadowRoot.querySelector('button'); - assertNotNull(pendingLink); + assertNotNullOrUndefined(pendingLink); assert.include(pendingLink.textContent?.trim(), '…'); }); @@ -87,12 +87,12 @@ describe('SurveyLink', async () => { assertShadowRoot(link.shadowRoot); const linkNode = link.shadowRoot.querySelector('button'); - assertNotNull(linkNode); + assertNotNullOrUndefined(linkNode); linkNode.click(); const successLink = link.shadowRoot.querySelector('button'); - assertNotNull(successLink); + assertNotNullOrUndefined(successLink); assert.include(successLink.textContent?.trim(), 'Thank you'); }); @@ -108,12 +108,12 @@ describe('SurveyLink', async () => { assertShadowRoot(link.shadowRoot); const linkNode = link.shadowRoot.querySelector('button'); - assertNotNull(linkNode); + assertNotNullOrUndefined(linkNode); linkNode.click(); const successLink = link.shadowRoot.querySelector('button'); - assertNotNull(successLink); + assertNotNullOrUndefined(successLink); assert.include(successLink.textContent?.trim(), 'error'); }); }); 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 399022f9e2..934bf5fbd5 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 @@ -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 {assertNotNull} from '../../../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../../../front_end/core/platform/platform.js'; import type * as IssuesManager from '../../../../../../front_end/models/issues_manager/issues_manager.js'; import * as IconButton from '../../../../../../front_end/ui/components/icon_button/icon_button.js'; import * as IssueCounter from '../../../../../../front_end/ui/components/issue_counter/issue_counter.js'; @@ -25,7 +25,7 @@ export const extractIconGroups = const iconButton = shadowRoot.querySelector('icon-button'); assertElement(iconButton, IconButton.IconButton.IconButton); const iconButtonShadowRoot = iconButton.shadowRoot; - assertNotNull(iconButtonShadowRoot); + assertNotNullOrUndefined(iconButtonShadowRoot); const icons = iconButtonShadowRoot.querySelectorAll('.status-icon'); assertElements(icons, IconButton.Icon.Icon); const labels = iconButtonShadowRoot.querySelectorAll('.icon-button-title'); diff --git a/test/unittests/front_end/ui/components/linear_memory_inspector/LinearMemoryInspectorPane_test.ts b/test/unittests/front_end/ui/components/linear_memory_inspector/LinearMemoryInspectorPane_test.ts index ba3a7c6f5e..63adb9cbe6 100644 --- a/test/unittests/front_end/ui/components/linear_memory_inspector/LinearMemoryInspectorPane_test.ts +++ b/test/unittests/front_end/ui/components/linear_memory_inspector/LinearMemoryInspectorPane_test.ts @@ -4,7 +4,7 @@ import {describeWithEnvironment} from '../../../helpers/EnvironmentHelpers.js'; import type * as LinearMemoryInspectorModule from '../../../../../../front_end/ui/components/linear_memory_inspector/linear_memory_inspector.js'; -import {assertNotNull} from '../../../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../../../front_end/core/platform/platform.js'; import {assertElement} from '../../../helpers/DOMHelpers.js'; function createArray() { @@ -46,7 +46,7 @@ describeWithEnvironment('LinearMemoryInspectorPane', () => { instance.create(scriptId, title, arrayWrapper, 10); const tabbedPane = instance.contentElement.querySelector('.tabbed-pane'); - assertNotNull(tabbedPane); + assertNotNullOrUndefined(tabbedPane); const inspector = tabbedPane.querySelector( 'devtools-linear-memory-inspector-inspector'); assertElement(inspector, LinearMemoryInspector.LinearMemoryInspector.LinearMemoryInspector); diff --git a/test/unittests/front_end/ui/legacy/components/inline_editor/CSSVarSwatch_test.ts b/test/unittests/front_end/ui/legacy/components/inline_editor/CSSVarSwatch_test.ts index 065d196ffb..2149226816 100644 --- a/test/unittests/front_end/ui/legacy/components/inline_editor/CSSVarSwatch_test.ts +++ b/test/unittests/front_end/ui/legacy/components/inline_editor/CSSVarSwatch_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 {assertNotNull} from '../../../../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../../../../front_end/core/platform/platform.js'; import * as InlineEditor from '../../../../../../../front_end/ui/legacy/components/inline_editor/inline_editor.js'; import {assertShadowRoot, renderElementIntoDOM} from '../../../../helpers/DOMHelpers.js'; @@ -17,10 +17,10 @@ function assertSwatch(swatch: InlineEditor.CSSVarSwatchImpl.CSSVarSwatch, expect }) { assertShadowRoot(swatch.shadowRoot); const container = swatch.shadowRoot.querySelector('span'); - assertNotNull(container); + assertNotNullOrUndefined(container); const link = container.querySelector('.css-var-link'); - assertNotNull(link); + assertNotNullOrUndefined(link); assert.strictEqual( container.getAttribute('title'), expected.valueTooltip || '', 'The computed values appears as a tooltip'); diff --git a/test/unittests/front_end/ui/legacy/components/inline_editor/ColorSwatch_test.ts b/test/unittests/front_end/ui/legacy/components/inline_editor/ColorSwatch_test.ts index eae996e67c..c081512b11 100644 --- a/test/unittests/front_end/ui/legacy/components/inline_editor/ColorSwatch_test.ts +++ b/test/unittests/front_end/ui/legacy/components/inline_editor/ColorSwatch_test.ts @@ -3,7 +3,7 @@ // found in the LICENSE file. import * as Common from '../../../../../../../front_end/core/common/common.js'; -import {assertNotNull} from '../../../../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../../../../front_end/core/platform/platform.js'; import * as InlineEditor from '../../../../../../../front_end/ui/legacy/components/inline_editor/inline_editor.js'; import {assertElement, assertShadowRoot, dispatchClickEvent, renderElementIntoDOM} from '../../../../helpers/DOMHelpers.js'; @@ -19,7 +19,7 @@ function assertSwatch( const slotEl = swatch.shadowRoot.querySelector('slot'); assertElement(swatchEl, HTMLElement); assertElement(swatchInnerEl, HTMLElement); - assertNotNull(slotEl); + assertNotNullOrUndefined(slotEl); if (expected.backgroundColor) { assert.strictEqual( @@ -41,7 +41,7 @@ function createSwatch(color: Common.Color.Color|string, formatOrUseUserSetting?: } function getClickTarget(swatch: InlineEditor.ColorSwatchImpl.ColorSwatch) { - assertNotNull(swatch.shadowRoot); + assertNotNullOrUndefined(swatch.shadowRoot); return swatch.shadowRoot.querySelector('.color-swatch-inner') as HTMLElement; } diff --git a/test/unittests/front_end/ui/legacy/components/perf_ui/PieChart_test.ts b/test/unittests/front_end/ui/legacy/components/perf_ui/PieChart_test.ts index bb14619d58..aac10c6ecc 100644 --- a/test/unittests/front_end/ui/legacy/components/perf_ui/PieChart_test.ts +++ b/test/unittests/front_end/ui/legacy/components/perf_ui/PieChart_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 {assertNotNull} from '../../../../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../../../../front_end/core/platform/platform.js'; import * as PerfUI from '../../../../../../../front_end/ui/legacy/components/perf_ui/perf_ui.js'; import {assertShadowRoot, renderElementIntoDOM} from '../../../../helpers/DOMHelpers.js'; @@ -36,7 +36,7 @@ describe('PieChart', () => { assertShadowRoot(chart.shadowRoot); const root = chart.shadowRoot.querySelector('[aria-label="Contents of a Pie"]'); - assertNotNull(root); + assertNotNullOrUndefined(root); assert.isTrue(root.classList.contains('root')); }); @@ -93,7 +93,7 @@ describe('PieChart', () => { assertShadowRoot(chart.shadowRoot); const total = chart.shadowRoot.querySelector('.pie-chart-total'); - assertNotNull(total); + assertNotNullOrUndefined(total); assert.strictEqual(total.textContent?.trim(), '100 f'); }); @@ -117,7 +117,7 @@ describe('PieChart', () => { // Chart total display in the center is selected. const total = chart.shadowRoot.querySelector('.pie-chart-total'); - assertNotNull(total); + assertNotNullOrUndefined(total); assert.isTrue(total.classList.contains('selected')); }); @@ -129,7 +129,7 @@ describe('PieChart', () => { assertShadowRoot(chart.shadowRoot); const slice = chart.shadowRoot.querySelector('path'); - assertNotNull(slice); + assertNotNullOrUndefined(slice); assert.strictEqual(slice.tabIndex, -1); }); @@ -141,7 +141,7 @@ describe('PieChart', () => { assertShadowRoot(chart.shadowRoot); const legendName = chart.shadowRoot.querySelector('.pie-chart-name'); - assertNotNull(legendName); + assertNotNullOrUndefined(legendName); legendName.click(); const legendRows = chart.shadowRoot.querySelectorAll('.pie-chart-legend-row'); @@ -156,7 +156,7 @@ describe('PieChart', () => { // Chart total display in the center is not selected. const total = chart.shadowRoot.querySelector('.pie-chart-total'); - assertNotNull(total); + assertNotNullOrUndefined(total); assert.isFalse(total.classList.contains('selected')); }); @@ -168,7 +168,7 @@ describe('PieChart', () => { assertShadowRoot(chart.shadowRoot); const slice = chart.shadowRoot.querySelector('[aria-label="Filling"'); - assertNotNull(slice); + assertNotNullOrUndefined(slice); slice.dispatchEvent(new Event('click')); const legendRows = chart.shadowRoot.querySelectorAll('.pie-chart-legend-row'); @@ -183,7 +183,7 @@ describe('PieChart', () => { // Chart total display in the center is not selected. const total = chart.shadowRoot.querySelector('.pie-chart-total'); - assertNotNull(total); + assertNotNullOrUndefined(total); assert.isFalse(total.classList.contains('selected')); }); @@ -195,7 +195,7 @@ describe('PieChart', () => { assertShadowRoot(chart.shadowRoot); const legendName = chart.shadowRoot.querySelector('.pie-chart-name'); - assertNotNull(legendName); + assertNotNullOrUndefined(legendName); legendName.click(); const legendRow = chart.shadowRoot.querySelector('.pie-chart-legend-row:focus-visible'); @@ -210,7 +210,7 @@ describe('PieChart', () => { assertShadowRoot(chart.shadowRoot); const root = chart.shadowRoot.querySelector('.root'); - assertNotNull(root); + assertNotNullOrUndefined(root); root.dispatchEvent(new KeyboardEvent('keydown', {key: 'ArrowUp'})); const legendRow = chart.shadowRoot.querySelector('.pie-chart-legend-row:focus-visible'); @@ -239,7 +239,7 @@ describe('PieChart', () => { // This is different in no-legend mode! const total = chart.shadowRoot.querySelector('.pie-chart-total'); - assertNotNull(total); + assertNotNullOrUndefined(total); assert.strictEqual(total.tabIndex, 1); }); }); diff --git a/test/unittests/front_end/ui/legacy/components/utils/Linkifier_test.ts b/test/unittests/front_end/ui/legacy/components/utils/Linkifier_test.ts index d713c9f319..3f76b82aac 100644 --- a/test/unittests/front_end/ui/legacy/components/utils/Linkifier_test.ts +++ b/test/unittests/front_end/ui/legacy/components/utils/Linkifier_test.ts @@ -9,7 +9,7 @@ import type * as WorkspaceModule from '../../../../../../../front_end/models/wor import {createTarget} from '../../../../helpers/EnvironmentHelpers.js'; import {describeWithMockConnection, dispatchEvent} from '../../../../helpers/MockConnection.js'; -import {assertNotNull} from '../../../../../../../front_end/core/platform/platform.js'; +import {assertNotNullOrUndefined} from '../../../../../../../front_end/core/platform/platform.js'; const {assert} = chai; @@ -44,18 +44,18 @@ describeWithMockConnection('Linkifier', async () => { const {target, linkifier} = setUpEnvironment(); const debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel); - assertNotNull(debuggerModel); + assertNotNullOrUndefined(debuggerModel); debuggerModel.suspendModel(); const scriptId = 'script'; const lineNumber = 4; const url = ''; const anchor = linkifier.maybeLinkifyScriptLocation(target, scriptId, url, lineNumber); - assertNotNull(anchor); + assertNotNullOrUndefined(anchor); assert.strictEqual(anchor.textContent, '\u200b'); const info = Components.Linkifier.Linkifier.linkInfo(anchor); - assertNotNull(info); + assertNotNullOrUndefined(info); assert.isNull(info.uiLocation); }); @@ -63,7 +63,7 @@ describeWithMockConnection('Linkifier', async () => { const {target, linkifier} = setUpEnvironment(); const debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel); - assertNotNull(debuggerModel); + assertNotNullOrUndefined(debuggerModel); debuggerModel.suspendModel(); const scriptId = 'script'; @@ -71,7 +71,7 @@ describeWithMockConnection('Linkifier', async () => { // Explicitly set url to empty string and let it resolve through the live location. const url = ''; const anchor = linkifier.maybeLinkifyScriptLocation(target, scriptId, url, lineNumber); - assertNotNull(anchor); + assertNotNullOrUndefined(anchor); assert.strictEqual(anchor.textContent, '\u200b'); debuggerModel.resumeModel(); @@ -96,8 +96,8 @@ describeWithMockConnection('Linkifier', async () => { for (const mutation of mutations) { if (mutation.type === 'childList') { const info = Components.Linkifier.Linkifier.linkInfo(anchor); - assertNotNull(info); - assertNotNull(info.uiLocation); + assertNotNullOrUndefined(info); + assertNotNullOrUndefined(info.uiLocation); assert.strictEqual(anchor.textContent, `script.js:${lineNumber + 1}`); observer.disconnect(); done(); @@ -133,17 +133,17 @@ describeWithMockConnection('Linkifier', async () => { // Ask for a link to a script that has not been registered yet, but has the same url. const anchor = linkifier.maybeLinkifyScriptLocation(target, scriptId + '2', url, lineNumber); - assertNotNull(anchor); + assertNotNullOrUndefined(anchor); const callback: MutationCallback = function(mutations: MutationRecord[]) { for (const mutation of mutations) { if (mutation.type === 'childList') { const info = Components.Linkifier.Linkifier.linkInfo(anchor); - assertNotNull(info); - assertNotNull(info.uiLocation); + assertNotNullOrUndefined(info); + assertNotNullOrUndefined(info.uiLocation); // Make sure that a uiSourceCode is linked to that anchor. - assertNotNull(info.uiLocation.uiSourceCode); + assertNotNullOrUndefined(info.uiLocation.uiSourceCode); observer.disconnect(); done(); }