diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7aea2448..760fbb80 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -42,6 +42,10 @@ jobs: - name: Install deps run: yarn + # lint.yaml runs the unit tests on Linux only; path handling differs on Windows and macOS. + - name: Unit tests + run: yarn test + - name: Download binaries run: npm run download-binaries diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index ea310f00..760944ee 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -26,5 +26,5 @@ jobs: - name: Typecheck run: yarn typecheck - - name: Page render test - run: yarn react-test + - name: Unit tests + run: yarn test diff --git a/package.json b/package.json index a328b60e..5dd7dfc3 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "scripts": { "start": "electron-vite dev", "test": "vitest run", - "react-test": "vitest run", + "verify": "yarn -s lint && yarn -s typecheck && yarn -s test", "test:e2e": "yarn build && node node_modules/playwright/cli.js test --config e2e/playwright.config.js", "test:e2e:update-fixtures": "yarn build && node e2e/updateFixtures.js", "test:docs": "node node_modules/playwright/cli.js test --config e2e/docs/playwright.config.js", diff --git a/src/main/parseAlignment.test.ts b/src/main/parseAlignment.test.ts index 99648194..c078b562 100644 --- a/src/main/parseAlignment.test.ts +++ b/src/main/parseAlignment.test.ts @@ -1,3 +1,4 @@ +import path from 'path'; import { expect, it } from 'vitest'; import { parseAlignment } from './parseAlignment'; import type { Alignment } from './parseAlignment'; @@ -80,11 +81,11 @@ it( 'parseAlignment reports the written file when it renames a taxon', async () } ) ); expect( written ).toEqual( { - filePath: '/data/primates_modified.fasta', + filePath: path.join( '/data', 'primates_modified.fasta' ), taxon: 'A_B', } ); expect( parsed.change ).toEqual( { - newFilePath: '/data/primates_modified.fasta', + newFilePath: path.join( '/data', 'primates_modified.fasta' ), format: 'fasta', converted: undefined, modified: true, @@ -94,6 +95,22 @@ it( 'parseAlignment reports the written file when it renames a taxon', async () } ); } ); +it.each( [ + [ '/tmp/abc/abc.fas', path.join( '/tmp/abc', 'abc_modified.fas' ) ], + [ '/tmp/abc ML/abc.fas', path.join( '/tmp/abc ML', 'abc_modified.fas' ) ], +] )( 'parseAlignment writes the modified file beside %s when a parent folder contains its base name', async ( filePath, expected ) => { + const alignment = { sequences: [ { taxon: 'A B', code: 'AAAA' } ] }; + let writtenPath; + const parsed = await parseAlignment( 'align-1', filePath, tools( async () => alignment as Alignment, { + write: async ( writePath ) => { + writtenPath = writePath; + }, + } ) ); + + expect( writtenPath ).toBe( expected ); + expect( parsed.change?.newFilePath ).toBe( expected ); +} ); + it( 'parseAlignment numbers a repeated taxon name', async () => { const alignment = { sequences: [ diff --git a/src/main/parseAlignment.ts b/src/main/parseAlignment.ts index 578dcc25..53e55a39 100644 --- a/src/main/parseAlignment.ts +++ b/src/main/parseAlignment.ts @@ -94,8 +94,8 @@ export async function parseAlignment( taxons.set( sequence.taxon, index ); } ); if ( modified ) { - const baseName = path.basename( actualPath, path.extname( actualPath ) ); - newFilePath = actualPath.replace( baseName, `${baseName}_modified` ); + const { dir, name, ext } = path.parse( actualPath ); + newFilePath = path.join( dir, `${name}_modified${ext}` ); await write( newFilePath, alignment ); } const change = newFilePath