Skip to content

Commit 749dc80

Browse files
Web tests with Vitest (#76)
1 parent e472f17 commit 749dc80

File tree

19 files changed

+2828
-35
lines changed

19 files changed

+2828
-35
lines changed

.github/workflows/test.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Ensures packages test correctly
2+
name: Test Packages
3+
4+
on:
5+
push:
6+
7+
jobs:
8+
test:
9+
name: Test Packages
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
persist-credentials: false
15+
16+
- name: Setup NodeJS
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version-file: '.nvmrc'
20+
21+
- uses: pnpm/action-setup@v2
22+
name: Install pnpm
23+
with:
24+
version: 8
25+
run_install: false
26+
27+
- name: Get pnpm store directory
28+
shell: bash
29+
run: |
30+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
31+
32+
- uses: actions/cache@v3
33+
name: Setup pnpm cache
34+
with:
35+
path: ${{ env.STORE_PATH }}
36+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
37+
restore-keys: |
38+
${{ runner.os }}-pnpm-store-
39+
40+
- name: Install dependencies
41+
run: pnpm install
42+
43+
- name: Build
44+
run: pnpm build:packages
45+
46+
- name: Test
47+
run: pnpm test

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
"description": "monorepo for powersync javascript sdks",
66
"main": "index.js",
77
"scripts": {
8-
"test": "echo \"Error: no test specified\" && exit 1",
9-
"lint": "eslint .",
10-
"clean": "pnpm run -r clean",
11-
"ci:version": "changeset version && pnpm install --no-frozen-lockfile",
8+
"build:packages": "pnpm run --filter './packages/**' -r build",
9+
"build": "pnpm run -r build",
1210
"ci:publish": "changeset publish && git push --follow-tags",
13-
"docs:start": "pnpm --filter docs start",
11+
"ci:version": "changeset version && pnpm install --no-frozen-lockfile",
12+
"clean": "pnpm run -r clean",
1413
"docs:build": "pnpm --filter docs build",
15-
"build": "pnpm run -r build",
16-
"build:packages": "pnpm run --filter './packages/**' -r build",
14+
"docs:start": "pnpm --filter docs start",
1715
"format": "prettier --write .",
18-
"release": "pnpm build:packages && pnpm changeset publish"
16+
"lint": "eslint .",
17+
"release": "pnpm build:packages && pnpm changeset publish",
18+
"test": "pnpm run -r test"
1919
},
2020
"keywords": [],
2121
"type": "module",

packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
135135
*
136136
* For the most part, behavior is the same whether querying on the underlying database, or on {@link AbstractPowerSyncDatabase}.
137137
*/
138-
protected get database() {
138+
get database() {
139139
return this.options.database;
140140
}
141141

@@ -272,6 +272,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
272272
*/
273273
async disconnectAndClear(options = DEFAULT_DISCONNECT_CLEAR_OPTIONS) {
274274
await this.disconnect();
275+
await this.waitForReady();
275276

276277
const { clearLocal } = options;
277278

packages/powersync-sdk-common/src/client/sync/bucket/BucketStorageAdapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface ChecksumCache {
2121
export interface SyncLocalDatabaseResult {
2222
ready: boolean;
2323
checkpointValid: boolean;
24-
failures?: string[];
24+
checkpointFailures?: string[];
2525
}
2626

2727
export interface BucketChecksum {
@@ -34,7 +34,7 @@ export interface BucketChecksum {
3434
/**
3535
* Count of operations - informational only.
3636
*/
37-
count: number;
37+
count?: number;
3838
}
3939

4040
export enum PSInternalTable {

packages/powersync-sdk-common/src/client/sync/bucket/OplogEntry.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { OpId } from './CrudEntry';
22
import { OpType, OpTypeJSON } from './OpType';
33

44
export interface OplogEntryJSON {
5+
checksum: number;
6+
data?: string;
7+
object_id?: string;
8+
object_type?: string;
59
op_id: string;
610
op: OpTypeJSON;
7-
object_type: string;
8-
object_id: string;
9-
checksum: number;
10-
data: string;
11-
subkey: string | object;
11+
subkey?: string | object;
1212
}
1313

1414
export class OplogEntry {

packages/powersync-sdk-common/src/client/sync/bucket/SqliteBucketStorage.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ export class SqliteBucketStorage implements BucketStorageAdapter {
121121
async syncLocalDatabase(checkpoint: Checkpoint): Promise<SyncLocalDatabaseResult> {
122122
const r = await this.validateChecksums(checkpoint);
123123
if (!r.checkpointValid) {
124-
this.logger.error('Checksums failed for', r.failures);
125-
for (const b of r.failures ?? []) {
124+
this.logger.error('Checksums failed for', r.checkpointFailures);
125+
for (const b of r.checkpointFailures ?? []) {
126126
await this.deleteBucket(b);
127127
}
128-
return { ready: false, checkpointValid: false, failures: r.failures };
128+
return { ready: false, checkpointValid: false, checkpointFailures: r.checkpointFailures };
129129
}
130130

131131
const bucketNames = checkpoint.buckets.map((b) => b.bucket);
@@ -178,7 +178,7 @@ export class SqliteBucketStorage implements BucketStorageAdapter {
178178
return {
179179
checkpointValid: false,
180180
ready: false,
181-
failures: []
181+
checkpointFailures: []
182182
};
183183
}
184184

@@ -190,7 +190,7 @@ export class SqliteBucketStorage implements BucketStorageAdapter {
190190
return {
191191
checkpointValid: false,
192192
ready: false,
193-
failures: result['failed_buckets']
193+
checkpointFailures: result['failed_buckets']
194194
};
195195
}
196196
}

packages/powersync-sdk-common/src/client/sync/bucket/SyncDataBucket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export class SyncDataBucket {
3232
/**
3333
* The `after` specified in the request.
3434
*/
35-
public after: OpId,
35+
public after?: OpId,
3636
/**
3737
* Use this for the next request.
3838
*/
39-
public next_after: OpId
39+
public next_after?: OpId
4040
) {}
4141

4242
toJSON(): SyncDataBucketJSON {

packages/powersync-sdk-common/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export * from './client/sync/bucket/CrudTransaction';
1010
export * from './client/sync/bucket/SyncDataBatch';
1111
export * from './client/sync/bucket/SyncDataBucket';
1212
export * from './client/sync/bucket/OpType';
13+
export * from './client/sync/bucket/OplogEntry';
1314
export * from './client/sync/stream/AbstractRemote';
1415
export * from './client/sync/stream/AbstractStreamingSyncImplementation';
1516
export * from './client/sync/stream/streaming-sync-types';

packages/powersync-sdk-web/package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "lib/src/index.js",
66
"types": "lib/src/index.d.ts",
77
"files": [
8-
"lib"
8+
"lib",
9+
"!lib/tests"
910
],
1011
"repository": "https://github.com/powersync-ja/powersync-js",
1112
"bugs": {
@@ -20,7 +21,7 @@
2021
"build": "tsc --build",
2122
"clean": "rm -rf dist tsconfig.tsbuildinfo",
2223
"watch": "tsc --build -w",
23-
"test": "echo \"Error: no test specified\" && exit 1"
24+
"test": "pnpm build && vitest"
2425
},
2526
"keywords": [
2627
"data sync",
@@ -35,7 +36,13 @@
3536
"@journeyapps/wa-sqlite": "~0.1.1",
3637
"@types/lodash": "^4.14.200",
3738
"@types/uuid": "^9.0.6",
38-
"typescript": "^5.2.2"
39+
"@vitest/browser": "^1.3.1",
40+
"typescript": "^5.2.2",
41+
"vite": "^5.1.1",
42+
"vite-plugin-top-level-await": "^1.4.1",
43+
"vite-plugin-wasm": "^3.3.0",
44+
"vitest": "^1.3.1",
45+
"webdriverio": "^8.32.3"
3946
},
4047
"peerDependencies": {
4148
"@journeyapps/wa-sqlite": "~0.1.1"

0 commit comments

Comments
 (0)