Skip to content

Commit 73c3219

Browse files
committed
feat: implement integration tests
- Sanity tests for the TS to Tauri commands - Tests for wrapper.rs, to which the commands directly delegate - Remove (up til now) unused code from lib.rs - Configure to run all tests in CI
1 parent 757ce9f commit 73c3219

9 files changed

Lines changed: 4491 additions & 2143 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,8 @@ jobs:
5959
- name: Run cargo check
6060
run: cargo check --workspace --all-targets
6161

62-
- name: Run cargo tests
62+
- name: Run Rust tests
6363
run: cargo test --workspace
64+
65+
- name: Run TypeScript tests
66+
run: npm test

Cargo.lock

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ sqlx-sqlite-conn-mgr = { path = "crates/sqlx-sqlite-conn-mgr" }
3333

3434
[build-dependencies]
3535
tauri-plugin = { version = "2.5.1", features = ["build"] }
36+
37+
[dev-dependencies]
38+
tempfile = "3.23.0"
39+
tokio = { version = "1.48.0", features = ["rt-multi-thread", "macros"] }

guest-js/index.test.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Sanity check to test the bridge between TypeScript and the Tauri commands.
3+
*/
4+
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
5+
import { mockIPC, clearMocks } from '@tauri-apps/api/mocks'
6+
import Database from './index'
7+
8+
let lastCmd = ''
9+
let lastArgs: Record<string, unknown> = {}
10+
11+
beforeEach(() => {
12+
mockIPC((cmd, args) => {
13+
lastCmd = cmd
14+
lastArgs = args as Record<string, unknown>
15+
if (cmd === 'plugin:sqlite|load') return (args as { db: string }).db
16+
if (cmd === 'plugin:sqlite|execute') return [1, 1]
17+
if (cmd === 'plugin:sqlite|execute_transaction') return []
18+
if (cmd === 'plugin:sqlite|fetch_all') return []
19+
if (cmd === 'plugin:sqlite|fetch_one') return null
20+
if (cmd === 'plugin:sqlite|close') return true
21+
if (cmd === 'plugin:sqlite|close_all') return undefined
22+
if (cmd === 'plugin:sqlite|remove') return true
23+
return undefined
24+
})
25+
})
26+
27+
afterEach(() => clearMocks())
28+
29+
describe('Database commands', () => {
30+
it('load', async () => {
31+
await Database.load('test.db')
32+
expect(lastCmd).toBe('plugin:sqlite|load')
33+
expect(lastArgs.db).toBe('test.db')
34+
})
35+
36+
it('execute', async () => {
37+
await Database.get('t.db').execute('INSERT INTO t VALUES ($1)', [1])
38+
expect(lastCmd).toBe('plugin:sqlite|execute')
39+
expect(lastArgs).toMatchObject({ db: 't.db', query: 'INSERT INTO t VALUES ($1)', values: [1] })
40+
})
41+
42+
it('execute_transaction', async () => {
43+
await Database.get('t.db').executeTransaction([['DELETE FROM t']])
44+
expect(lastCmd).toBe('plugin:sqlite|execute_transaction')
45+
expect(lastArgs.statements).toEqual([{ query: 'DELETE FROM t', values: [] }])
46+
})
47+
48+
it('fetch_all', async () => {
49+
await Database.get('t.db').fetchAll('SELECT * FROM t')
50+
expect(lastCmd).toBe('plugin:sqlite|fetch_all')
51+
expect(lastArgs).toMatchObject({ db: 't.db', query: 'SELECT * FROM t' })
52+
})
53+
54+
it('fetch_one', async () => {
55+
await Database.get('t.db').fetchOne('SELECT * FROM t WHERE id = $1', [1])
56+
expect(lastCmd).toBe('plugin:sqlite|fetch_one')
57+
expect(lastArgs).toMatchObject({ db: 't.db', values: [1] })
58+
})
59+
60+
it('close', async () => {
61+
await Database.get('t.db').close()
62+
expect(lastCmd).toBe('plugin:sqlite|close')
63+
expect(lastArgs.db).toBe('t.db')
64+
})
65+
66+
it('close_all', async () => {
67+
await Database.closeAll()
68+
expect(lastCmd).toBe('plugin:sqlite|close_all')
69+
})
70+
71+
it('remove', async () => {
72+
await Database.get('t.db').remove()
73+
expect(lastCmd).toBe('plugin:sqlite|remove')
74+
expect(lastArgs.db).toBe('t.db')
75+
})
76+
})

0 commit comments

Comments
 (0)