Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

main.ts

139 lines3.4 KB

1import { createNativeTauriSQLiteTestDatabase } from './native-tauri-sql-test-db'
2import { registerTauriNativeE2ESuite } from './register-tauri-e2e-suite'
3import {
4 getRegisteredTestCount,
5 resetRegisteredTests,
6 runRegisteredTests,
7} from './runtime-vitest'
8​
9const statusElement = document.querySelector(`#status`) as HTMLParagraphElement
10const detailsElement = document.querySelector(`#details`) as HTMLPreElement
11const runtimeRunId =
12 import.meta.env.VITE_TANSTACK_DB_TAURI_E2E_RUN_ID ?? Date.now().toString(36)
13const reportUrl = import.meta.env.VITE_TANSTACK_DB_TAURI_E2E_REPORT_URL
14​
15function setStatus(status: string, details?: unknown): void {
16 statusElement.textContent = status
17 if (details !== undefined) {
18 detailsElement.textContent = JSON.stringify(details, null, 2)
19 }
21​
22async function postHarnessMessage(
23 payload: Record<string, unknown>,
24): Promise<void> {
25 if (!reportUrl) {
26 return
27 }
28​
29 await fetch(reportUrl, {
30 method: `POST`,
31 headers: {
32 'content-type': `application/json`,
33 },
34 body: JSON.stringify(payload),
35 })
37​
38async function reportRunResult(result: {
39 status: `passed` | `failed`
40 payload: unknown
41}): Promise<void> {
42 await postHarnessMessage({
43 kind: `result`,
44 ...result,
45 })
47​
48async function reportStatus(phase: string, details?: unknown): Promise<void> {
49 await postHarnessMessage({
50 kind: `status`,
51 phase,
52 details,
53 })
55​
56async function run(): Promise<void> {
57 setStatus(`Starting Tauri e2e runtime`)
58​
59 try {
60 await reportStatus(`starting`, { runId: runtimeRunId })
61 const database = await createNativeTauriSQLiteTestDatabase({
62 runId: runtimeRunId,
63 })
64 await reportStatus(`database-loaded`)
65​
66 resetRegisteredTests()
67 registerTauriNativeE2ESuite({
68 suiteName: `tauri persisted collection conformance`,
69 database,
70 runId: runtimeRunId,
71 })
72 await reportStatus(`suite-registered`)
73​
74 const totalTests = getRegisteredTestCount()
75 setStatus(`Running Tauri e2e suite`, {
76 totalTests,
77 runId: runtimeRunId,
78 })
79 await reportStatus(`tests-starting`, {
80 totalTests,
81 })
82​
83 const result = await runRegisteredTests({
84 onTestStart: ({ index, name, total }) => {
85 setStatus(`Running test ${String(index)}/${String(total)}`, {
86 currentTest: name,
87 })
88 },
89 })
90 await reportStatus(`tests-finished`, {
91 total: result.total,
92 failed: result.failed,
93 })
94​
95 const failedResults = result.results.filter(
96 (entry) => entry.status === `failed`,
97 )
98 const summary = {
99 passed: result.passed,
100 failed: result.failed,
101 skipped: result.skipped,
102 total: result.total,
103 failures: failedResults.slice(0, 10),
104 }
105​
106 if (result.failed > 0) {
107 await reportRunResult({
108 status: `failed`,
109 payload: summary,
110 })
111 setStatus(`Tauri e2e failed`, summary)
112 return
113 }
114​
115 await reportRunResult({
116 status: `passed`,
117 payload: summary,
118 })
119 setStatus(`Tauri e2e passed`, summary)
120 } catch (error) {
121 const message = error instanceof Error ? error.message : String(error)
122 const payload = {
123 error: message,
124 runId: runtimeRunId,
125 step: statusElement.textContent,
126 }
127​
128 try {
129 await reportRunResult({
130 status: `failed`,
131 payload,
132 })
133 } catch {}
134​
135 setStatus(`Tauri e2e failed: ${message}`, payload)
136 }
138​
139void run()