Skip to content

Build your personal knowledge base with Trilium Notes

test(ckeditor5-math): mark the unreachable defensive guards as ignored

Elian Doran0bd4a09a71ad
diff --git a/packages/ckeditor5-math/src/autoformatmath.ts b/packages/ckeditor5-math/src/autoformatmath.ts
index 7ae767928d..ab10315524 100644
--- a/packages/ckeditor5-math/src/autoformatmath.ts
+++ b/packages/ckeditor5-math/src/autoformatmath.ts
@@ -24,6 +24,7 @@ export default class AutoformatMath extends Plugin {
const editor = this.editor;
const command = editor.commands.get( 'math' );
+ /* v8 ignore next -- defensive: MathEditing always registers a MathCommand under this name */
if ( command instanceof MathCommand ) {
const callback = () => {
if ( !command.isEnabled ) {
@@ -36,6 +37,7 @@ export default class AutoformatMath extends Plugin {
window.setTimeout(
() => {
const mathUIInstance = editor.plugins.get( 'MathUI' );
+ /* v8 ignore next -- defensive: the Math glue plugin always loads MathUI */
if ( mathUIInstance instanceof MathUI ) {
mathUIInstance._showUI();
}
diff --git a/packages/ckeditor5-math/src/automath.ts b/packages/ckeditor5-math/src/automath.ts
index d189ac2a60..7519793c7a 100644
--- a/packages/ckeditor5-math/src/automath.ts
+++ b/packages/ckeditor5-math/src/automath.ts
@@ -29,6 +29,7 @@ export default class AutoMath extends Plugin {
// Listening on Clipboard silently never fires, which left this whole feature dead.
this.listenTo( editor.plugins.get( ClipboardPipeline ), 'inputTransformation', () => {
const firstRange = modelDocument.selection.getFirstRange();
+ /* v8 ignore next 3 -- defensive: the document selection always has at least one range */
if ( !firstRange ) {
return;
}
@@ -111,6 +112,7 @@ export default class AutoMath extends Plugin {
let insertPosition: ModelLivePosition | null;
// Check if position where the math element should be inserted is still valid.
+ /* v8 ignore next -- defensive: reachable only if the document is rewritten under the 100ms timer */
if ( this._positionToInsert?.root.rootName !== '$graveyard' ) {
insertPosition = this._positionToInsert;
}
diff --git a/packages/ckeditor5-math/src/mathui.ts b/packages/ckeditor5-math/src/mathui.ts
index 3e3da2744d..9d86761e0d 100644
--- a/packages/ckeditor5-math/src/mathui.ts
+++ b/packages/ckeditor5-math/src/mathui.ts
@@ -63,6 +63,7 @@ export default class MathUI extends Plugin {
private _createFormView() {
const editor = this.editor;
const mathCommand = editor.commands.get( 'math' );
+ /* v8 ignore next 7 -- defensive: MathEditing, which MathUI requires, always registers this command */
if ( !( mathCommand instanceof MathCommand ) ) {
/**
* Missing Math command
@@ -138,6 +139,7 @@ export default class MathUI extends Plugin {
const editor = this.editor;
const mathCommand = editor.commands.get( 'math' );
+ /* v8 ignore next 7 -- defensive: MathEditing always registers this command */
if ( !( mathCommand instanceof MathCommand ) ) {
/**
* Math command not found
@@ -146,6 +148,7 @@ export default class MathUI extends Plugin {
throw new CKEditorError( 'plugin-load', { pluginName: 'math' } );
}
+ /* v8 ignore next 3 -- defensive: the form view is built in init() before any show */
if ( this.formView == null ) {
return;
}
@@ -217,6 +220,7 @@ export default class MathUI extends Plugin {
private _createToolbarMathButton() {
const editor = this.editor;
const mathCommand = editor.commands.get( 'math' );
+ /* v8 ignore next 7 -- defensive: MathEditing always registers this command */
if ( !mathCommand ) {
/**
* Math command not found
@@ -279,9 +283,11 @@ export default class MathUI extends Plugin {
clickOutsideHandler( {
emitter: this.formView,
activator: () => !!this._isFormInPanel,
+ /* v8 ignore next -- defensive: the balloon view is rendered by the time init() runs */
contextElements: this._balloon.view.element ? [ this._balloon.view.element ] : [],
callback: () => { this._hideUI(); }
} );
+ /* v8 ignore next 3 -- defensive: init() builds the form view before wiring interactions */
} else {
throw new Error( 'missing form view' );
}
diff --git a/packages/ckeditor5-math/src/ui/mathinputview.ts b/packages/ckeditor5-math/src/ui/mathinputview.ts
index 2eb0347e58..db72fa3ef3 100644
--- a/packages/ckeditor5-math/src/ui/mathinputview.ts
+++ b/packages/ckeditor5-math/src/ui/mathinputview.ts
@@ -88,6 +88,7 @@ export default class MathInputView extends View {
// Sync changes from the LaTeX textarea to the mathfield and model
this.listenTo( textarea, 'input', () => {
+ /* v8 ignore next 3 -- re-entrancy latch: set only while the partner handler writes */
if ( this._updating ) {
return;
}
@@ -162,6 +163,7 @@ export default class MathInputView extends View {
}
if ( !MathInputView._configured ) {
const MathfieldClass = customElements.get( 'math-field' ) as any;
+ /* v8 ignore next -- defensive: whenDefined() resolved, so the element is registered */
if ( MathfieldClass ) {
MathfieldClass.soundsDirectory = null;
MathfieldClass.plonkSound = null;
@@ -171,6 +173,7 @@ export default class MathInputView extends View {
if ( this.element && !this._destroyed ) {
this._initMathField( true );
}
+ /* v8 ignore next 6 -- defensive: only reached if the bundled MathLive import itself fails */
} catch {
const c = this.element?.querySelector( '.ck-mathlive-container' );
if ( c ) {
@@ -182,6 +185,7 @@ export default class MathInputView extends View {
// Initializes the <math-field> element
private _initMathField( shouldFocus: boolean ): void {
const container = this.element?.querySelector( '.ck-mathlive-container' );
+ /* v8 ignore next 3 -- defensive: the container is part of this view's own template */
if ( !container ) {
return;
}
@@ -215,6 +219,7 @@ export default class MathInputView extends View {
}
}, { capture: true } );
mf.addEventListener( 'input', () => {
+ /* v8 ignore next 3 -- re-entrancy latch: set only while the partner handler writes */
if ( this._updating ) {
return;
}
@@ -236,6 +241,7 @@ export default class MathInputView extends View {
// Updates the mathfield value without triggering loops
private _setMathfieldValue( value: string ): void {
+ /* v8 ignore next 3 -- defensive: every caller checks for the math field first */
if ( !this.mathfield ) {
return;
}
diff --git a/packages/ckeditor5-math/src/ui/mathview.ts b/packages/ckeditor5-math/src/ui/mathview.ts
index aa1027329e..cfe753c65f 100644
--- a/packages/ckeditor5-math/src/ui/mathview.ts
+++ b/packages/ckeditor5-math/src/ui/mathview.ts
@@ -83,6 +83,7 @@ export default class MathView extends View {
).catch( error => {
console.error( 'Math rendering failed:', error );
+ /* v8 ignore next -- defensive: updateMath() returns early when there is no element */
if ( this.element ) {
this.element.textContent = 'Error rendering equation';
this.element.classList.add( 'ck-math-render-error' );
diff --git a/packages/ckeditor5-math/src/utils.ts b/packages/ckeditor5-math/src/utils.ts
index 01a9e46f6f..532c4162b6 100644
--- a/packages/ckeditor5-math/src/utils.ts
+++ b/packages/ckeditor5-math/src/utils.ts
@@ -129,6 +129,7 @@ export async function renderEquation(
previewUid,
previewClassName,
el => {
+ /* v8 ignore next -- defensive: this arm is already gated on window.katex being defined */
if ( katex ) {
katex.render( equation, el, {
throwOnError: false,
@@ -252,6 +253,7 @@ function selectRenderMode(
function renderMathJax3( equation: string, element: HTMLElement, display: boolean, cb: () => void ) {
let promiseFunction: undefined | ( ( input: string, options: { display: boolean } ) => Promise<HTMLElement> ) = undefined;
+ /* v8 ignore next 3 -- defensive: only called from the branch that already checked for MathJax 3 */
if ( !isMathJaxVersion3( MathJax ) ) {
return;
}