Skip to content

Commit

Permalink
Web tests with Vitest (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensJourney authored Feb 27, 2024
1 parent e472f17 commit 749dc80
Show file tree
Hide file tree
Showing 19 changed files with 2,828 additions and 35 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Ensures packages test correctly
name: Test Packages

on:
push:

jobs:
test:
name: Test Packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 8
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build:packages

- name: Test
run: pnpm test
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"description": "monorepo for powersync javascript sdks",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint .",
"clean": "pnpm run -r clean",
"ci:version": "changeset version && pnpm install --no-frozen-lockfile",
"build:packages": "pnpm run --filter './packages/**' -r build",
"build": "pnpm run -r build",
"ci:publish": "changeset publish && git push --follow-tags",
"docs:start": "pnpm --filter docs start",
"ci:version": "changeset version && pnpm install --no-frozen-lockfile",
"clean": "pnpm run -r clean",
"docs:build": "pnpm --filter docs build",
"build": "pnpm run -r build",
"build:packages": "pnpm run --filter './packages/**' -r build",
"docs:start": "pnpm --filter docs start",
"format": "prettier --write .",
"release": "pnpm build:packages && pnpm changeset publish"
"lint": "eslint .",
"release": "pnpm build:packages && pnpm changeset publish",
"test": "pnpm run -r test"
},
"keywords": [],
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
*
* For the most part, behavior is the same whether querying on the underlying database, or on {@link AbstractPowerSyncDatabase}.
*/
protected get database() {
get database() {
return this.options.database;
}

Expand Down Expand Up @@ -272,6 +272,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
*/
async disconnectAndClear(options = DEFAULT_DISCONNECT_CLEAR_OPTIONS) {
await this.disconnect();
await this.waitForReady();

const { clearLocal } = options;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface ChecksumCache {
export interface SyncLocalDatabaseResult {
ready: boolean;
checkpointValid: boolean;
failures?: string[];
checkpointFailures?: string[];
}

export interface BucketChecksum {
Expand All @@ -34,7 +34,7 @@ export interface BucketChecksum {
/**
* Count of operations - informational only.
*/
count: number;
count?: number;
}

export enum PSInternalTable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { OpId } from './CrudEntry';
import { OpType, OpTypeJSON } from './OpType';

export interface OplogEntryJSON {
checksum: number;
data?: string;
object_id?: string;
object_type?: string;
op_id: string;
op: OpTypeJSON;
object_type: string;
object_id: string;
checksum: number;
data: string;
subkey: string | object;
subkey?: string | object;
}

export class OplogEntry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ export class SqliteBucketStorage implements BucketStorageAdapter {
async syncLocalDatabase(checkpoint: Checkpoint): Promise<SyncLocalDatabaseResult> {
const r = await this.validateChecksums(checkpoint);
if (!r.checkpointValid) {
this.logger.error('Checksums failed for', r.failures);
for (const b of r.failures ?? []) {
this.logger.error('Checksums failed for', r.checkpointFailures);
for (const b of r.checkpointFailures ?? []) {
await this.deleteBucket(b);
}
return { ready: false, checkpointValid: false, failures: r.failures };
return { ready: false, checkpointValid: false, checkpointFailures: r.checkpointFailures };
}

const bucketNames = checkpoint.buckets.map((b) => b.bucket);
Expand Down Expand Up @@ -178,7 +178,7 @@ export class SqliteBucketStorage implements BucketStorageAdapter {
return {
checkpointValid: false,
ready: false,
failures: []
checkpointFailures: []
};
}

Expand All @@ -190,7 +190,7 @@ export class SqliteBucketStorage implements BucketStorageAdapter {
return {
checkpointValid: false,
ready: false,
failures: result['failed_buckets']
checkpointFailures: result['failed_buckets']
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export class SyncDataBucket {
/**
* The `after` specified in the request.
*/
public after: OpId,
public after?: OpId,
/**
* Use this for the next request.
*/
public next_after: OpId
public next_after?: OpId
) {}

toJSON(): SyncDataBucketJSON {
Expand Down
1 change: 1 addition & 0 deletions packages/powersync-sdk-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './client/sync/bucket/CrudTransaction';
export * from './client/sync/bucket/SyncDataBatch';
export * from './client/sync/bucket/SyncDataBucket';
export * from './client/sync/bucket/OpType';
export * from './client/sync/bucket/OplogEntry';
export * from './client/sync/stream/AbstractRemote';
export * from './client/sync/stream/AbstractStreamingSyncImplementation';
export * from './client/sync/stream/streaming-sync-types';
Expand Down
13 changes: 10 additions & 3 deletions packages/powersync-sdk-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"files": [
"lib"
"lib",
"!lib/tests"
],
"repository": "https://github.com/powersync-ja/powersync-js",
"bugs": {
Expand All @@ -20,7 +21,7 @@
"build": "tsc --build",
"clean": "rm -rf dist tsconfig.tsbuildinfo",
"watch": "tsc --build -w",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "pnpm build && vitest"
},
"keywords": [
"data sync",
Expand All @@ -35,7 +36,13 @@
"@journeyapps/wa-sqlite": "~0.1.1",
"@types/lodash": "^4.14.200",
"@types/uuid": "^9.0.6",
"typescript": "^5.2.2"
"@vitest/browser": "^1.3.1",
"typescript": "^5.2.2",
"vite": "^5.1.1",
"vite-plugin-top-level-await": "^1.4.1",
"vite-plugin-wasm": "^3.3.0",
"vitest": "^1.3.1",
"webdriverio": "^8.32.3"
},
"peerDependencies": {
"@journeyapps/wa-sqlite": "~0.1.1"
Expand Down
Loading

0 comments on commit 749dc80

Please sign in to comment.