Skip to content

Commit 34ce9fd

Browse files
authored
Issue2228 (#2229)
* Fix broken test framework in addons/dexie-cloud * Repro of #2228 * Fix #2228
1 parent 0c4d820 commit 34ce9fd

File tree

6 files changed

+64
-4
lines changed

6 files changed

+64
-4
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"demoUsers": {
33
4-
4+
5+
56
}
67
}

addons/dexie-cloud/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"karma-chrome-launcher": "*",
8787
"karma-firefox-launcher": "*",
8888
"karma-qunit": "*",
89+
"karma-webdriver-launcher": "*",
8990
"qunit": "2.10.0",
9091
"qunitjs": "1.23.1",
9192
"lib0": "^0.2.97",

addons/dexie-cloud/src/sync/listClientChanges.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,18 @@ function removeRedundantUpdateOps(muts: DBOperation[]) {
9292
// Only apply optimization to update mutations that are single-key
9393
if (mut.type !== 'update') return true;
9494
if (mut.keys.length !== 1 || mut.changeSpecs.length !== 1) return true;
95+
96+
// Check if this has PropModifications - if so, skip optimization
97+
const changeSpecs = mut.changeSpecs[0];
98+
if (Object.values(changeSpecs).some(v => typeof v === "object" && v && "@@propmod" in v)) {
99+
return true; // Cannot optimize if any PropModification is present
100+
}
101+
95102
// Keep track of properties that aren't overlapped by later transactions
96103
const unoverlappedProps = new Set(Object.keys(mut.changeSpecs[0]));
97104
const strKey = '' + mut.keys[0];
98-
const keyCoverage = updateCoverage.get(strKey)!;
105+
const keyCoverage = updateCoverage.get(strKey);
106+
if (!keyCoverage) return true; // No coverage info - cannot optimize
99107

100108
for (let i = keyCoverage.length - 1; i >= 0; --i) {
101109
const { txid, updateSpec } = keyCoverage[i];

addons/dexie-cloud/test/unit/karma.conf.cjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ module.exports = function (config) {
2121
'addons/dexie-cloud/test/unit/bundle.js',
2222
{ pattern: 'addons/dexie-cloud/test/*.map', watched: false, included: false },
2323
{ pattern: 'addons/dexie-cloud/dist/*.map', watched: false, included: false }
24-
])
24+
]),
25+
// Override plugins to exclude karma-webdriver-launcher for local testing
26+
plugins: [
27+
'karma-qunit',
28+
'karma-mocha-reporter',
29+
'karma-chrome-launcher',
30+
'karma-firefox-launcher'
31+
]
2532
});
2633

2734
cfg.hostname = 'localhost';

addons/dexie-cloud/test/unit/tests-github-issues.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,51 @@ import {
1010
deepEqual,
1111
} from 'qunit';
1212
import { promisedTest } from '../promisedTest';
13-
import Dexie from 'dexie';
13+
import Dexie, { add, remove } from 'dexie';
1414
import dexieCloud, { DexieCloudOptions, DexieCloudTable, getTiedRealmId } from '../../src/dexie-cloud-client';
1515

16+
const DBURL = 'https://zv8n7bwcs.dexie.cloud'; // Shall exist in cloud.
17+
1618
module('github-issues');
1719

20+
promisedTest('https://github.com/dexie/Dexie.js/issues/2228', async () => {
21+
const DBNAME = 'Issue2228_DB';
22+
const db = new Dexie(DBNAME, { addons: [dexieCloud] }) as Dexie & {
23+
items2228: DexieCloudTable<{ id: string; drinks: string[] }, 'id'>;
24+
};
25+
db.version(1).stores({ items2228: '@id' });
26+
db.cloud.configure({
27+
databaseUrl: DBURL,
28+
requireAuth: { email: '[email protected]', grant_type: 'demo' }
29+
});
30+
await db.open();
31+
32+
ok(true, 'Cleared existing items in items2228 table');
33+
await db.items2228.clear();
34+
ok(true, 'Now syncing to cloud');
35+
await db.cloud.sync({purpose: 'push', wait: true });
36+
37+
await db.items2228.update('nonExistingId', { drinks: add(['coffee']) });
38+
await db.items2228.update('nonExistingId', { drinks: remove(['coffee']) });
39+
40+
ok(true, 'Now syncing to cloud after adding and removing from non-existing item');
41+
await db.cloud.sync({purpose: 'push', wait: true });
42+
43+
const itemId = await db.items2228.add({ drinks: ['coffee', 'tea'] });
44+
ok(true, `Added item with id ${itemId} and drinks ['coffee', 'tea']`);
45+
46+
await db.items2228.update(itemId, { drinks: add(['milk']) });
47+
await db.items2228.update(itemId, { drinks: remove(['milk']) });
48+
49+
ok(true, 'Now syncing to cloud after adding and removing from existing item');
50+
await db.cloud.sync({purpose: 'push', wait: true });
51+
52+
ok(true, 'Test completed successfully');
53+
db.close();
54+
await Dexie.delete(DBNAME);
55+
console.log('Database deleted successfully');
56+
});
57+
1858
/** Dexie issue #2185
1959
*
2060
* Here are the steps to reproduce the issue:

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)