diff --git a/src/app/AlignmentCard.tsx b/src/app/AlignmentCard.tsx index f2aa8cb6..3cad9542 100644 --- a/src/app/AlignmentCard.tsx +++ b/src/app/AlignmentCard.tsx @@ -29,7 +29,7 @@ interface CardModelExtra { value: string; onChange: ( value: string ) => void; notAvailable: boolean; - hoverInfo: string; + hoverInfo?: string; error: unknown; } diff --git a/src/app/Input.tsx b/src/app/Input.tsx index 233eb792..fa5161de 100644 --- a/src/app/Input.tsx +++ b/src/app/Input.tsx @@ -33,7 +33,7 @@ type InputRun = PartitionFileCardProps['run'] & { inputIsAlignment: boolean; alignments: ( AlignmentCardProps['alignment'] & { path: string } )[]; inputIsTree: boolean; - astralTree: AstralTreeCardProps['astralTree']; + astralTree: AstralTreeCardProps['astralTree'] | null | undefined; canLoadAlignment: boolean; haveAlignments: boolean; canLoadPartitionFile: boolean; @@ -60,7 +60,7 @@ function droppedPath( file: File ): string { } const Input = ( { run }: InputProps ): React.JSX.Element => { - // run.hasAstralTree is the condition on which to show an astral tree card + // run.astralTree (hasAstralTree) is the condition on which to show an astral tree card // For some reason when changed in the mobx store a rerender is not triggered with this boolean with the conditional below alone // With this if the component rerenders as should be if ( run.hasAstralTree ) { @@ -143,7 +143,7 @@ const Input = ( { run }: InputProps ): React.JSX.Element => { /> ) ) : null} - {run.inputIsTree && run.hasAstralTree + {run.inputIsTree && run.astralTree ? ( ) diff --git a/src/app/components/ErrorDialog.test.tsx b/src/app/components/ErrorDialog.test.tsx index 01616ab0..f7e55493 100644 --- a/src/app/components/ErrorDialog.test.tsx +++ b/src/app/components/ErrorDialog.test.tsx @@ -24,7 +24,7 @@ it( 'the reload action reloads the window', () => { } ); const button = Array.from( document.body.querySelectorAll( 'button' ) ) - .find( ( item ) => item.textContent === 'Ignore and reload' ); + .find( ( item ) => item.textContent === 'Ignore and reload' )!; act( () => { button.click(); } ); @@ -55,7 +55,7 @@ function renderDialog( error: Error ) { div, button( label: string ) { return Array.from( document.body.querySelectorAll( 'button, a' ) ) - .find( ( item ) => item.textContent === label ); + .find( ( item ) => item.textContent === label )!; }, }; } @@ -94,7 +94,7 @@ Locale: en-US`; const url = new URL( openExternal.mock.calls[0][0] ); expect( `${url.origin}${url.pathname}` ).toBe( 'https://github.com/AntonelliLab/raxmlGUI/issues/new' ); expect( url.searchParams.get( 'title' ) ).toBe( 'Error: boom' ); - const body = url.searchParams.get( 'body' ); + const body = url.searchParams.get( 'body' )!; expect( body.startsWith( 'Autogenerated report:' ) ).toBe( true ); expect( body ).toContain( 'boom' ); expect( body ).toContain( 'raxml -s primates.fasta' ); diff --git a/src/app/components/OptionCheck.tsx b/src/app/components/OptionCheck.tsx index 906b5719..4da4e0af 100644 --- a/src/app/components/OptionCheck.tsx +++ b/src/app/components/OptionCheck.tsx @@ -9,7 +9,7 @@ export interface OptionCheckOptionLike { value: boolean; setValue: ( value: boolean ) => void; notAvailable: boolean; - hoverInfo: string; + hoverInfo?: string; } export interface OptionCheckProps { diff --git a/src/app/components/OptionSelect.tsx b/src/app/components/OptionSelect.tsx index 2b4235ee..9a8ef716 100644 --- a/src/app/components/OptionSelect.tsx +++ b/src/app/components/OptionSelect.tsx @@ -14,7 +14,7 @@ export interface OptionSelectChoice { export interface OptionSelectOptionLike { notAvailable?: boolean; title: string; - hoverInfo: string; + hoverInfo?: string; options: readonly OptionSelectChoice[]; value: Value; setValue: ( value: Value ) => void; diff --git a/src/app/components/OptionTextField.tsx b/src/app/components/OptionTextField.tsx index 850fb3c2..cd8f7803 100644 --- a/src/app/components/OptionTextField.tsx +++ b/src/app/components/OptionTextField.tsx @@ -7,7 +7,7 @@ export interface OptionTextFieldOptionLike { value: string | number | boolean; setValue: ( value: string ) => void; notAvailable: boolean; - hoverInfo: string; + hoverInfo?: string; haveError: boolean; disabled?: boolean; placeholder?: string; diff --git a/src/app/droppedFile.test.tsx b/src/app/droppedFile.test.tsx index 9dadcc80..2983ee76 100644 --- a/src/app/droppedFile.test.tsx +++ b/src/app/droppedFile.test.tsx @@ -52,11 +52,11 @@ function mountInput( run: object ) { } function button( div: HTMLElement, text: string ) { - return Array.from( div.querySelectorAll( 'button' ) ).find( ( node ) => node.textContent.trim() === text ); + return Array.from( div.querySelectorAll( 'button' ) ).find( ( node ) => node.textContent.trim() === text )!; } async function drop( target: Element, name: string ) { - const input = target.closest( '[role="presentation"]' ).querySelector( 'input[type="file"]' ); + const input = target.closest( '[role="presentation"]' )!.querySelector( 'input[type="file"]' )!; const file = new File( ['x'], name ); Object.defineProperty( input, 'files', { configurable: true, @@ -79,7 +79,7 @@ it( 'each drop target keeps the dropped file path', async () => { 'cats.fasta': '/tmp/drop-6', 'dogs.fasta': '/tmp/drop-7', 'genes.part': '/tmp/drop-8', - }[file.name]; + }[file.name]!; }, } ); @@ -109,7 +109,7 @@ it( 'each drop target keeps the dropped file path', async () => { } ); const secondView = mountInput( second ); await drop( - secondView.div.querySelector( 'button[title="Concatenate new alignments and create partition"]' ), + secondView.div.querySelector( 'button[title="Concatenate new alignments and create partition"]' )!, 'cats.fasta', ); expect( second.addAlignments ).toHaveBeenCalledWith( [{ path: '/tmp/drop-6' }] ); @@ -122,7 +122,7 @@ it( 'each drop target keeps the dropped file path', async () => { } ); const thirdView = mountInput( third ); await drop( - thirdView.div.querySelector( 'button[title="Concatenate new alignments and automatically generate a partition"]' ), + thirdView.div.querySelector( 'button[title="Concatenate new alignments and automatically generate a partition"]' )!, 'dogs.fasta', ); await drop( button( thirdView.div, 'Load partition' ), 'genes.part' ); diff --git a/src/app/store/AlignmentOptions.test.ts b/src/app/store/AlignmentOptions.test.ts index 2f650eee..c8450ca3 100644 --- a/src/app/store/AlignmentOptions.test.ts +++ b/src/app/store/AlignmentOptions.test.ts @@ -25,7 +25,7 @@ function useOtherBinary( run: Run ) { runInAction( () => { run.binary.value = run.binary.options.find( ( o ) => !o.value.includes( 'raxml-ng' ), - ).value; + )!.value; } ); } diff --git a/src/app/store/Part.test.ts b/src/app/store/Part.test.ts index 76e16b1b..0ac607bc 100644 --- a/src/app/store/Part.test.ts +++ b/src/app/store/Part.test.ts @@ -38,7 +38,7 @@ function makeAlignment( if ( !ng ) { run.binary.value = run.binary.options .map( ( o ) => o.value ) - .find( ( v ) => /raxml/i.test( v ) && !v.includes( 'raxml-ng' ) ); + .find( ( v ) => /raxml/i.test( v ) && !v.includes( 'raxml-ng' ) )!; } // 'dna' is the dead case of #269; the store still maps it to DNA. alignment.dataType = dataType as DataType; diff --git a/src/app/store/Run.computeds.test.ts b/src/app/store/Run.computeds.test.ts index 8ff8d7a7..8d4a4de1 100644 --- a/src/app/store/Run.computeds.test.ts +++ b/src/app/store/Run.computeds.test.ts @@ -11,7 +11,9 @@ import type AstralTree from './AstralTree'; import Run from './Run'; import { analysisOptions, binaries } from './RunOptions'; -const modeltestName = binaries.find( ( b ) => b.type === 'modeltest' ).name; +type RunParent = ConstructorParameters[0]; + +const modeltestName = binaries.find( ( b ) => b.type === 'modeltest' )!.name; let checkOutput: Mock; let stops: ( () => void )[] = []; @@ -22,7 +24,7 @@ beforeEach( () => { checkOutput = vi.fn( async ( { outputName } ) => ( { ok: true, outputNameUnused: outputName, - resultFilenames: [], + resultFilenames: [] as string[], } as CheckOutputResult ) ); installBridge( { checkOutput, getVersion: () => Promise.resolve( '2.0.0' ) } ); } ); @@ -49,7 +51,7 @@ const nucleotide = ( over: Record = {} ): Alignment => ( { } as unknown as Alignment ); function makeRun( { alignments = [nucleotide()], binary = 'raxmlHPC', outputDir = '/out' } = {} ) { - const run = new Run( null, 1 ); + const run = new Run( {} as RunParent, 1 ); runInAction( () => { run.binary.value = binary; run.outputDir = outputDir; @@ -62,7 +64,7 @@ function makeRun( { alignments = [nucleotide()], binary = 'raxmlHPC', outputDir // outputNameAvailable only settles inside a reaction, so reads that touch it go through here. function read( fn: () => T ): T { - let value: T; + let value!: T; autorun( () => { value = fn(); } )(); @@ -219,7 +221,7 @@ describe( 'Run alignment computeds', () => { describe( 'Run state computeds', () => { it( 'missing asks for a tree only for an analysis that needs one', () => { const run = makeRun( { binary: 'raxmlHPC' } ); - const needsTree = analysisOptions.find( ( o ) => o.params.includes( 'tree' ) ); + const needsTree = analysisOptions.find( ( o ) => o.params.includes( 'tree' ) )!; run.analysis.setValue( 'FT' ); expect( run.missing ).toBe( '' ); run.analysis.setValue( needsTree.value ); diff --git a/src/app/store/RunSimpleOptions.test.ts b/src/app/store/RunSimpleOptions.test.ts index 01dd1b02..583a94a9 100644 --- a/src/app/store/RunSimpleOptions.test.ts +++ b/src/app/store/RunSimpleOptions.test.ts @@ -5,8 +5,10 @@ import type Alignment from './Alignment'; import Run from './Run'; import { binaries, MAX_NUM_CPUS } from './RunOptions'; -const threaded = binaries.find( ( b ) => /PTHREADS/.test( b.name ) ); -const plain = binaries.find( ( b ) => b.type === 'raxml' && !/PTHREADS|-ng/.test( b.name ) ); +type RunParent = ConstructorParameters[0]; + +const threaded = binaries.find( ( b ) => /PTHREADS/.test( b.name ) )!; +const plain = binaries.find( ( b ) => b.type === 'raxml' && !/PTHREADS|-ng/.test( b.name ) )!; // Run.analysis is a computed that builds a new option on each evaluation, so an // unobserved run forgets a set analysis value. A kept-alive reaction models the page. @@ -15,7 +17,7 @@ afterEach( () => stops.splice( 0 ).forEach( ( stop ) => stop() ) ); // The initial binary is raxml-ng on some hosts; most tests start from classic RAxML. const newRun = () => { - const run = new Run( null, 1 ); + const run = new Run( {} as RunParent, 1 ); stops.push( autorun( () => run.analysis ) ); runInAction( () => { run.binary.value = plain.name; @@ -42,8 +44,8 @@ const addAlignment = ( run: Run, dataType: string ) => runInAction( () => { describe( 'Binary', () => { it( 'defaults to the initial binary and offers every binary', () => { - const run = new Run( null, 1 ); - expect( run.binary.value ).toBe( binaries.find( ( b ) => b.initial ).name ); + const run = new Run( {} as RunParent, 1 ); + expect( run.binary.value ).toBe( binaries.find( ( b ) => b.initial )!.name ); expect( run.binary.options.map( ( o ) => o.value ) ).toEqual( binaries.map( ( b ) => b.name ), ); @@ -51,7 +53,7 @@ describe( 'Binary', () => { it( 'derives version and type from the chosen binary and updates reactions', () => { const run = newRun(); - const modeltest = binaries.find( ( b ) => b.type === 'modeltest' ); + const modeltest = binaries.find( ( b ) => b.type === 'modeltest' )!; const { seen, stop } = track( () => [run.binary.version, run.binary.type] ); set( run.binary, modeltest.name ); stop(); diff --git a/src/app/store/alignmentStore.test.ts b/src/app/store/alignmentStore.test.ts index 2a0bbe09..a25d7ead 100644 --- a/src/app/store/alignmentStore.test.ts +++ b/src/app/store/alignmentStore.test.ts @@ -117,7 +117,7 @@ describe( 'Alignment observable fields update the page store', () => { runInAction( () => { run.binary.value = run.binary.options.find( ( { value } ) => !value.includes( 'raxml-ng' ), - ).value; + )!.value; } ); expect( run.usesRaxmlNg ).toBe( false ); const { seen, stop } = track( () => [ @@ -144,14 +144,14 @@ describe( 'Alignment observable fields update the page store', () => { it( 'aaMatrixName updates partitionType and modelExtra, and onChangeAAMatrixName sets it', () => { const { run, alignment } = setup(); set( run.binary, { - value: run.binary.options.find( ( { value } ) => !value.includes( 'raxml-ng' ) ).value, + value: run.binary.options.find( ( { value } ) => !value.includes( 'raxml-ng' ) )!.value, } ); set( alignment, { dataType: 'protein' } ); const { seen, stop } = track( () => [ alignment.partitionType, alignment.modelExtra?.value, ] ); - alignment.modelExtra.onChange( 'WAG' ); + alignment.modelExtra!.onChange( 'WAG' ); expect( alignment.aaMatrixName ).toBe( 'WAG' ); expect( seen[seen.length - 1] ).toEqual( ['WAG', 'WAG'] ); stop(); @@ -160,8 +160,8 @@ describe( 'Alignment observable fields update the page store', () => { it( 'modelExtra is null for protein with raxml-ng', () => { const { run, alignment } = setup(); set( alignment, { dataType: 'protein' } ); - const ng = run.binary.options.find( ( { value } ) => value.includes( 'raxml-ng' ) ); - const old = run.binary.options.find( ( { value } ) => !value.includes( 'raxml-ng' ) ); + const ng = run.binary.options.find( ( { value } ) => value.includes( 'raxml-ng' ) )!; + const old = run.binary.options.find( ( { value } ) => !value.includes( 'raxml-ng' ) )!; set( run.binary, { value: old.value } ); const { seen, stop } = track( () => alignment.modelExtra?.value ); set( run.binary, { value: ng.value } ); @@ -187,8 +187,8 @@ describe( 'Alignment observable fields update the page store', () => { it( 'dataType, length and aaMatrixName update partitionFileContent', () => { const { run, alignment } = setup(); set( alignment, { dataType: 'nucleotide', length: 10 } ); - const ng = run.binary.options.find( ( { value } ) => value.includes( 'raxml-ng' ) ); - const old = run.binary.options.find( ( { value } ) => !value.includes( 'raxml-ng' ) ); + const ng = run.binary.options.find( ( { value } ) => value.includes( 'raxml-ng' ) )!; + const old = run.binary.options.find( ( { value } ) => !value.includes( 'raxml-ng' ) )!; set( run.binary, { value: old.value } ); const { seen, stop } = track( () => alignment.partitionFileContent ); set( alignment, { length: 12 } ); @@ -239,7 +239,7 @@ describe( 'Alignment observable fields update the page store', () => { it( 'hasInvariantSites updates ascertainment bias availability', () => { const { run, alignment } = setup(); - const ng = run.binary.options.find( ( { value } ) => value.includes( 'raxml-ng' ) ); + const ng = run.binary.options.find( ( { value } ) => value.includes( 'raxml-ng' ) )!; set( run.binary, { value: ng.value } ); const { seen, stop } = track( () => alignment.ngAscertainmentBias.notAvailable ); set( alignment, { hasInvariantSites: true } ); @@ -518,10 +518,10 @@ describe( 'Alignment model selection', () => { it( 'dispose stops listening and cancels a running model selection', () => { const { alignment } = setup(); set( alignment, { modeltestLoading: true } ); - const before = listeners[runEvents.onModelSelectionSuccess].length; + const before = listeners[runEvents.onModelSelectionSuccess]!.length; alignment.dispose(); expect( bridge.cancelModelSelection ).toHaveBeenCalledWith( alignment.id ); - expect( listeners[runEvents.onModelSelectionSuccess].length ).toBe( before - 1 ); + expect( listeners[runEvents.onModelSelectionSuccess]!.length ).toBe( before - 1 ); } ); it( 'remove disposes and removes the alignment from the run', () => { diff --git a/src/app/store/astral.test.ts b/src/app/store/astral.test.ts index 0b715272..e2d15801 100644 --- a/src/app/store/astral.test.ts +++ b/src/app/store/astral.test.ts @@ -24,7 +24,7 @@ function bridge( extra: Partial = {} ) { stops.push( 'success' ); }; }, - checkOutput: async () => ( { ok: true, resultFilenames: [] } as CheckOutputResult ), + checkOutput: async () => ( { ok: true, resultFilenames: [] as string[] } as CheckOutputResult ), parseAlignment: () => new Promise( () => {} ), ...extra, } ); diff --git a/src/app/store/loadAstralTree.test.ts b/src/app/store/loadAstralTree.test.ts index c7c4152a..78fc6687 100644 --- a/src/app/store/loadAstralTree.test.ts +++ b/src/app/store/loadAstralTree.test.ts @@ -18,7 +18,7 @@ it( 'the ASTRAL file picker adds the chosen file', async () => { await run.loadAstralTree(); expect( selectAstralFile ).toHaveBeenCalledWith( 7 ); - expect( run.astralTree.path ).toBe( '/data/trees.tre' ); + expect( run.astralTree!.path ).toBe( '/data/trees.tre' ); } ); it( 'cancel leaves the ASTRAL file unchanged', async () => { @@ -30,7 +30,7 @@ it( 'cancel leaves the ASTRAL file unchanged', async () => { await run.loadAstralTree(); expect( selectAstralFile ).toHaveBeenCalledWith( 7 ); - expect( run.astralTree.path ).toBe( '/data/already.tre' ); + expect( run.astralTree!.path ).toBe( '/data/already.tre' ); } ); it( 'a dialog failure fails the ASTRAL file choice', async () => { @@ -43,5 +43,5 @@ it( 'a dialog failure fails the ASTRAL file choice', async () => { } ); await expect( run.loadAstralTree() ).rejects.toThrow( 'dialog failed' ); - expect( run.astralTree.path ).toBe( '/data/already.tre' ); + expect( run.astralTree!.path ).toBe( '/data/already.tre' ); } ); diff --git a/src/app/store/parseAlignment.test.ts b/src/app/store/parseAlignment.test.ts index 77907995..1a0a62ce 100644 --- a/src/app/store/parseAlignment.test.ts +++ b/src/app/store/parseAlignment.test.ts @@ -107,5 +107,5 @@ it( 'a failed parse removes the alignment', async () => { await pending.catch( () => {} ); expect( run.alignments ).toEqual( [] ); - expect( run.error.message ).toBe( 'unrecognized format' ); + expect( run.error!.message ).toBe( 'unrecognized format' ); } ); diff --git a/src/app/store/runInputActions.test.ts b/src/app/store/runInputActions.test.ts index 4df0c0f5..3ec1625a 100644 --- a/src/app/store/runInputActions.test.ts +++ b/src/app/store/runInputActions.test.ts @@ -27,7 +27,7 @@ const stayParsed = async (): Promise => ( { const checkOutput = vi.fn( async ( { outputName } ) => ( { ok: true, outputNameUnused: outputName, - resultFilenames: [], + resultFilenames: [] as string[], } as CheckOutputResult ) ); const flush = () => new Promise( ( resolve ) => setTimeout( resolve, 0 ) ); @@ -209,9 +209,9 @@ describe( 'ASTRAL tree', () => { run.addAstralFiles( { path: '/data/second.tre' } ); dispose(); - expect( run.astralTree.path ).toBe( '/data/trees.tre' ); - expect( run.outputName ).toBe( run.astralTree.name ); - expect( run.outputDir ).toBe( run.astralTree.dir ); + expect( run.astralTree!.path ).toBe( '/data/trees.tre' ); + expect( run.outputName ).toBe( run.astralTree!.name ); + expect( run.outputDir ).toBe( run.astralTree!.dir ); expect( seen ).toEqual( [ false, true ] ); } ); @@ -229,7 +229,7 @@ describe( 'ASTRAL tree', () => { describe( 'partition file', () => { it( 'loadPartitionFile shows the path and content after the read resolves', async () => { - let finishRead: ( content: string ) => void; + let finishRead!: ( content: string ) => void; const readFile = vi.fn( () => new Promise( ( resolve ) => { finishRead = resolve; } ), ); diff --git a/src/app/store/runLifecycle.test.ts b/src/app/store/runLifecycle.test.ts index 97a7f95d..bde44270 100644 --- a/src/app/store/runLifecycle.test.ts +++ b/src/app/store/runLifecycle.test.ts @@ -83,7 +83,7 @@ describe( 'start', () => { bridge.checkOutput = vi.fn( async () => ( { ok: false, outputNameUnused: 'primates_2', - resultFilenames: [], + resultFilenames: [] as string[], } as CheckOutputResult ) ); const name = track( () => run.outputName ); const safe = track( () => run.outputNameSafe ); @@ -273,7 +273,7 @@ describe( 'cancel', () => { it( 'stops a start that is still writing files from starting the run', async () => { const { run } = makeRun(); - let release: () => void; + let release!: () => void; bridge.writeFile = vi.fn( () => new Promise( ( resolve ) => { release = resolve; diff --git a/src/app/store/startRun.test.ts b/src/app/store/startRun.test.ts index 076ddad0..721a9b91 100644 --- a/src/app/store/startRun.test.ts +++ b/src/app/store/startRun.test.ts @@ -37,7 +37,7 @@ function bridge( extra: Partial = {} ) { [runEvents.onRunFinished]: subscribe( 'finished' ), [runEvents.onRunError]: subscribe( 'error' ), parseAlignment: () => new Promise( () => {} ), - checkOutput: async () => ( { ok: true, resultFilenames: [] } as CheckOutputResult ), + checkOutput: async () => ( { ok: true, resultFilenames: [] as string[] } as CheckOutputResult ), writeFile: async () => {}, async cancelRun() {}, ...extra, diff --git a/src/app/store/substitutionOptions.test.ts b/src/app/store/substitutionOptions.test.ts index 1330eefe..3fa56490 100644 --- a/src/app/store/substitutionOptions.test.ts +++ b/src/app/store/substitutionOptions.test.ts @@ -20,7 +20,7 @@ type RunParent = ConstructorParameters[0]; const parent = { onError() {} } as Partial as RunParent; const binaryNamed = ( run: Run, prefix: string ) => run.binary.options - .map( ( o ) => o.value ).find( ( v: string ) => v.startsWith( prefix ) ); + .map( ( o ) => o.value ).find( ( v: string ) => v.startsWith( prefix ) )!; const ngName = () => binaryNamed( new Run( parent, 1 ), 'raxml-ng' ); // The default binary depends on the host platform, so pin a classic RAxML one. diff --git a/src/app/store/treeFileOptions.test.ts b/src/app/store/treeFileOptions.test.ts index 62b641c7..172bfb2a 100644 --- a/src/app/store/treeFileOptions.test.ts +++ b/src/app/store/treeFileOptions.test.ts @@ -40,7 +40,7 @@ beforeEach( () => { run = new Run( {} as Partial as RunParent, 3 ); disposers = []; // The default binary is raxml-ng; these tests use the classic RAxML analyses. - run.binary.setValue( run.binary.options.find( ( { value } ) => value.includes( 'raxmlHPC' ) ).value ); + run.binary.setValue( run.binary.options.find( ( { value } ) => value.includes( 'raxmlHPC' ) )!.value ); observe( () => run.analysis.value ); } ); @@ -50,7 +50,7 @@ afterEach( () => { describe.each( files )( '%s file', ( key, filePath ) => { const option = () => run[key]; - const filename = filePath.split( '/' ).pop(); + const filename = filePath.split( '/' ).pop()!; const stem = filename.replace( /\.\w+$/, '' ); it( 'starts without a file', () => { diff --git a/src/app/unhandledError.test.tsx b/src/app/unhandledError.test.tsx index 69721975..5ebf095a 100644 --- a/src/app/unhandledError.test.tsx +++ b/src/app/unhandledError.test.tsx @@ -35,7 +35,7 @@ it( 'the page shows an unhandled error title and error', () => { } ); } ); - expect( document.getElementById( 'error-dialog-title' ).textContent ).toBe( 'Unhandled Error' ); + expect( document.getElementById( 'error-dialog-title' )!.textContent ).toBe( 'Unhandled Error' ); expect( document.body.textContent ).toContain( 'disk full' ); act( () => { diff --git a/src/app/updateDownload.test.tsx b/src/app/updateDownload.test.tsx index d2a3cde3..e8011422 100644 --- a/src/app/updateDownload.test.tsx +++ b/src/app/updateDownload.test.tsx @@ -43,15 +43,15 @@ it( 'the page follows the update download in a dialog that cannot be dismissed', hear( payload ); } ); expect( title() ).toBe( 'Downloading update' ); - const dialog = document.querySelector( '[role="dialog"]' ); + const dialog = document.querySelector( '[role="dialog"]' )!; expect( dialog.textContent ).toContain( percent ); expect( dialog.textContent ).toContain( status ); expect( dialog.querySelector( 'button' ) ).toBeNull(); } act( () => { - document.querySelector( '[role="dialog"]' ).dispatchEvent( new KeyboardEvent( 'keydown', { key: 'Escape', bubbles: true } ) ); - document.querySelector( '.MuiBackdrop-root' ).click(); + document.querySelector( '[role="dialog"]' )!.dispatchEvent( new KeyboardEvent( 'keydown', { key: 'Escape', bubbles: true } ) ); + document.querySelector( '.MuiBackdrop-root' )!.click(); } ); expect( title() ).toBe( 'Downloading update' ); @@ -79,7 +79,7 @@ it( 'a page that starts mid-download shows the dialog with no event pushed', asy root.render( ); } ); expect( title() ).toBe( 'Downloading update' ); - expect( document.querySelector( '[role="dialog"]' ).textContent ).toContain( '37%' ); + expect( document.querySelector( '[role="dialog"]' )!.textContent ).toContain( '37%' ); act( () => { root.unmount(); diff --git a/src/main/getActiveState.test.ts b/src/main/getActiveState.test.ts index 83bbe9c6..7b2bd5c3 100644 --- a/src/main/getActiveState.test.ts +++ b/src/main/getActiveState.test.ts @@ -23,7 +23,7 @@ const { getActiveState } = await import( './getActiveState' ); const { STATE_REPORT, STATE_REPORT_RESULT } = await import( '../constants/ipc' ); it( 'asks the active window and resolves the matching report', async () => { - let onResult: ( event: unknown, payload: unknown ) => void; + let onResult!: ( event: unknown, payload: unknown ) => void; mockOn.mockImplementation( ( channel, listener ) => { expect( channel ).toBe( STATE_REPORT_RESULT ); onResult = listener; diff --git a/src/main/parseAlignment.test.ts b/src/main/parseAlignment.test.ts index c078b562..9053bbab 100644 --- a/src/main/parseAlignment.test.ts +++ b/src/main/parseAlignment.test.ts @@ -126,7 +126,7 @@ it( 'parseAlignment numbers a repeated taxon name', async () => { 'Homo', 'Homo_1', ] ); - expect( parsed.change.modificationMessages ).toEqual( [ + expect( parsed.change!.modificationMessages ).toEqual( [ 'Identical sequence names: 1 and 2 = Homo', ] ); } ); @@ -141,7 +141,7 @@ it( 'parseAlignment shortens a taxon name past 256 characters', async () => { } ) ); expect( alignment.sequences[0].taxon ).toBe( 'A'.repeat( 253 ) ); - expect( parsed.change.modificationMessages ).toEqual( [ + expect( parsed.change!.modificationMessages ).toEqual( [ `Taxon name is too long: '${taxon}'.`, ] ); } ); diff --git a/src/pack.test.ts b/src/pack.test.ts index ece2efea..15731c50 100644 --- a/src/pack.test.ts +++ b/src/pack.test.ts @@ -17,7 +17,7 @@ function included( filter: ( file: string, stat: typeof fileStat ) => boolean, r async function packFilters() { const config = await getConfig( root, null, null ); - const buildResourcesDir = config.directories.buildResources; + const buildResourcesDir = config.directories!.buildResources!; const macroExpander = ( pattern: string ) => pattern; const info = { isPrepackedAppAsar: false, @@ -49,7 +49,7 @@ it( 'packs the built shell and the production dependencies', async () => { const { config, buildResourcesDir, main, modules, } = await packFilters(); - const patterns = ( config.files as FileSet[] ).flatMap( ( set ) => set.filter ); + const patterns = ( config.files as FileSet[] ).flatMap( ( set ) => set.filter! ); const icons = path.join( root, buildResourcesDir ); expect( patterns.every( ( pattern ) => pattern.startsWith( '!' ) ) ).toBe( true ); @@ -75,7 +75,7 @@ it( 'packs the built shell and the production dependencies', async () => { expect( config.publish ).toEqual( { provider: 'github' } ); expect( config.extraMetadata ).toBeUndefined(); expect( config.extraResources ).toEqual( [ { filter: [ 'assets/' ] } ] ); - expect( config.mac.extraResources ).toEqual( [ + expect( config.mac!.extraResources ).toEqual( [ { from: 'static/bin/Mac', to: 'static/bin', @@ -86,13 +86,13 @@ it( 'packs the built shell and the production dependencies', async () => { filter: [ '*.txt' ], }, ] ); - expect( config.win.extraResources ).toEqual( [ + expect( config.win!.extraResources ).toEqual( [ { from: 'static/bin/Windows', to: 'static/bin', }, ] ); - expect( config.linux.extraResources ).toEqual( [ + expect( config.linux!.extraResources ).toEqual( [ { from: 'static/bin/Linux', to: 'static/bin', diff --git a/src/preload.test.ts b/src/preload.test.ts index ce1521c4..79cfbed8 100644 --- a/src/preload.test.ts +++ b/src/preload.test.ts @@ -29,7 +29,7 @@ function loadPreloadConfig() { throw new Error( result.stderr || result.stdout ); } const line = result.stdout.split( '\n' ).find( ( item ) => item.startsWith( 'PRELOAD_CONFIG ' ) ); - return JSON.parse( line.slice( 'PRELOAD_CONFIG '.length ) ); + return JSON.parse( line!.slice( 'PRELOAD_CONFIG '.length ) ); } function buildShell() { diff --git a/src/sourceMaps.test.ts b/src/sourceMaps.test.ts index 05c1b456..76cc70f4 100644 --- a/src/sourceMaps.test.ts +++ b/src/sourceMaps.test.ts @@ -16,7 +16,7 @@ interface ShellPlugins { rendererRelease: string | null; } -function shellBuild( command: string, env: Record ): ShellPlugins { +function shellBuild( command: string, env: NodeJS.ProcessEnv ): ShellPlugins { const childEnv = { ...process.env }; [ 'SENTRY_ORG', 'SENTRY_AUTH_TOKEN', 'SENTRY_PROJECT', 'SENTRY_RELEASE', 'SENTRY_URL' ].forEach( ( key ) => { delete childEnv[ key ]; @@ -49,7 +49,7 @@ function shellBuild( command: string, env: Record ): ShellPlugin throw new Error( result.stderr || result.stdout ); } const line = result.stdout.split( '\n' ).find( ( item ) => item.startsWith( 'SOURCE_MAPS ' ) ); - return JSON.parse( line.slice( 'SOURCE_MAPS '.length ) ); + return JSON.parse( line!.slice( 'SOURCE_MAPS '.length ) ); } const credentials = { SENTRY_ORG: 'antonelli-lab', SENTRY_AUTH_TOKEN: 'token' }; diff --git a/src/test/installBridge.test.ts b/src/test/installBridge.test.ts index e1ba449d..510b421e 100644 --- a/src/test/installBridge.test.ts +++ b/src/test/installBridge.test.ts @@ -28,7 +28,7 @@ test( 'the defaults the setup stubs are still there', () => { } ); test( 'a supplied host getter is installed without being read', () => { - const original = Object.getOwnPropertyDescriptor( window.rendererBridge, 'host' ); + const original = Object.getOwnPropertyDescriptor( window.rendererBridge, 'host' )!; const read = vi.fn( () => original.value ); installBridge( Object.defineProperty( {}, 'host', { configurable: true, enumerable: true, get: read } ) ); diff --git a/src/test/setup.ts b/src/test/setup.ts index ef5800d2..78502072 100644 --- a/src/test/setup.ts +++ b/src/test/setup.ts @@ -42,8 +42,9 @@ function withBridgeEvents( next: TestBridge ): TestBridge { next.provideStateReport = () => {}; } // The page store calls getVersion while it is constructed. + // It resolves undefined, not '', so settings text matches what tests captured before it settles. if ( typeof next.getVersion !== 'function' ) { - next.getVersion = () => Promise.resolve( undefined ); + next.getVersion = () => Promise.resolve( undefined as unknown as string ); } // The run list seeds the update download when it listens. if ( typeof next.getUpdateDownload !== 'function' ) { diff --git a/src/test/storeBridge.ts b/src/test/storeBridge.ts index ade65909..da1e507d 100644 --- a/src/test/storeBridge.ts +++ b/src/test/storeBridge.ts @@ -24,7 +24,7 @@ export function stubBridge( extra: Partial = {} ): StubbedBridge events[name] = ( listener: Listener ) => { ( listeners[name] ||= [] ).push( listener ); return () => { - listeners[name] = listeners[name].filter( ( l ) => l !== listener ); + listeners[name] = listeners[name]!.filter( ( l ) => l !== listener ); }; }; } diff --git a/tsconfig.json b/tsconfig.json index 37dc311b..d3742b2a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,14 +11,10 @@ "useDefineForClassFields": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, - "strict": false, - "noImplicitAny": true, - "noImplicitThis": true, + "strict": true, "noImplicitReturns": true, "noUnusedLocals": true, "noUnusedParameters": true, - "strictBindCallApply": true, - "strictFunctionTypes": true, "skipLibCheck": true }, "include": ["src", "e2e/helpers/**/*.test.ts"]