File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,22 @@ import { yankiModels } from '../../src/lib/model/model'
44import { requestPermission } from '../../src/lib/utilities/anki-connect'
55import { PLATFORM } from '../../src/lib/utilities/platform'
66
7+ /**
8+ * Launches Anki
9+ */
10+ export async function openAnki ( ) : Promise < void > {
11+ if ( PLATFORM !== 'mac' ) {
12+ throw new Error ( 'This function only works on Mac' )
13+ }
14+
15+ const client = new YankiConnect ( {
16+ autoLaunch : 'immediately' ,
17+ } )
18+
19+ // Sanity
20+ await client . miscellaneous . version ( )
21+ }
22+
723/**
824 * Closes Anki by sending a quit command to the application.
925 * This function will wait until Anki is unreachable.
@@ -30,14 +46,16 @@ export async function closeAnki(): Promise<void> {
3046 await execa ( 'sh' , [
3147 '-c' ,
3248 "launchctl stop $(launchctl list | grep ankiweb | awk '{print $3}')" ,
33- ] )
49+ ] ) . catch ( ( ) => {
50+ // Ignore
51+ } )
3452 } )
3553 }
3654
3755 // Spin until it's done...
3856 while ( permissionStatus !== 'ankiUnreachable' ) {
3957 await new Promise ( ( resolve ) => {
40- setTimeout ( resolve , 1000 )
58+ setTimeout ( resolve , 250 )
4159 } )
4260 permissionStatus = await requestPermission ( client )
4361 }
Original file line number Diff line number Diff line change 1+ import { closeAnki , openAnki } from './anki-connect'
2+
3+ /**
4+ * Ensure Anki is running before tests run
5+ */
6+ export async function setup ( ) {
7+ await openAnki ( )
8+ }
9+
10+ /**
11+ * Clean up
12+ */
13+ export async function teardown ( ) {
14+ await closeAnki ( )
15+ }
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export default defineConfig({
1515 // Running tests concurrently across files can create race conditions in
1616 // total note counts that will cause assertions to fail.
1717 fileParallelism : false ,
18+ globalSetup : './test/utilities/global-setup.ts' ,
1819 maxConcurrency : 1 ,
1920 maxWorkers : 1 ,
2021 projects : [
You can’t perform that action at this time.
0 commit comments