Skip to content

Commit e33a6d0

Browse files
add opsqlite async iterator tests
1 parent 658e439 commit e33a6d0

File tree

6 files changed

+257
-230
lines changed

6 files changed

+257
-230
lines changed

pnpm-lock.yaml

Lines changed: 211 additions & 217 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
module.exports = {
22
presets: ['module:@react-native/babel-preset'],
33
plugins: [
4+
'@babel/plugin-transform-async-generator-functions',
45
'@babel/plugin-transform-class-static-block',
56
[
67
'module-resolver',
78
{
89
alias: {
9-
stream: 'stream-browserify',
10-
},
11-
},
12-
],
13-
],
10+
stream: 'stream-browserify'
11+
}
12+
}
13+
]
14+
]
1415
};

tools/powersynctests/ios/Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PODS:
88
- hermes-engine (0.78.0):
99
- hermes-engine/Pre-built (= 0.78.0)
1010
- hermes-engine/Pre-built (0.78.0)
11-
- op-sqlite (11.4.9):
11+
- op-sqlite (11.4.8):
1212
- DoubleConversion
1313
- glog
1414
- hermes-engine
@@ -31,7 +31,7 @@ PODS:
3131
- ReactCommon/turbomodule/bridging
3232
- ReactCommon/turbomodule/core
3333
- Yoga
34-
- powersync-op-sqlite (0.5.4):
34+
- powersync-op-sqlite (0.6.0):
3535
- DoubleConversion
3636
- glog
3737
- hermes-engine
@@ -1829,8 +1829,8 @@ SPEC CHECKSUMS:
18291829
fmt: a40bb5bd0294ea969aaaba240a927bd33d878cdd
18301830
glog: eb93e2f488219332457c3c4eafd2738ddc7e80b8
18311831
hermes-engine: b417d2b2aee3b89b58e63e23a51e02be91dc876d
1832-
op-sqlite: d07002ecca5c39575deb7c4abd9e5310da6aa07d
1833-
powersync-op-sqlite: ce90a0e44924deea3901d06892d2d687e6eaf0c1
1832+
op-sqlite: 060f3d3902e6a49657051505a9c93f2688ef4943
1833+
powersync-op-sqlite: f2cacb147e29212f3f76ce44f50d7cac20949a5b
18341834
powersync-sqlite-core: ef06642c8110680fcddce8a8c0dd2696daaf672d
18351835
RCT-Folly: 36fe2295e44b10d831836cc0d1daec5f8abcf809
18361836
RCTDeprecation: b2eecf2d60216df56bc5e6be5f063826d3c1ee35
@@ -1897,4 +1897,4 @@ SPEC CHECKSUMS:
18971897

18981898
PODFILE CHECKSUM: a15b54e8d191759ce7fcccb262b8753851ec9fde
18991899

1900-
COCOAPODS: 1.15.2
1900+
COCOAPODS: 1.16.2

tools/powersynctests/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"start": "react-native start"
1010
},
1111
"dependencies": {
12+
"@azure/core-asynciterator-polyfill": "^1.0.2",
1213
"@op-engineering/op-sqlite": "^11.4.8",
1314
"@powersync/common": "workspace:*",
1415
"@powersync/op-sqlite": "workspace:*",
@@ -30,6 +31,7 @@
3031
},
3132
"devDependencies": {
3233
"@babel/core": "^7.25.2",
34+
"@babel/plugin-transform-async-generator-functions": "^7.27.1",
3335
"@babel/plugin-transform-class-static-block": "^7.26.0",
3436
"@babel/preset-env": "^7.25.3",
3537
"@babel/runtime": "^7.25.0",

tools/powersynctests/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @format
66
*/
7-
7+
import '@azure/core-asynciterator-polyfill';
88
import React from 'react';
99
import { SafeAreaView, ScrollView, StatusBar, useColorScheme } from 'react-native';
1010

@@ -17,7 +17,7 @@ function App(): React.JSX.Element {
1717
const isDarkMode = useColorScheme() === 'dark';
1818

1919
const backgroundStyle = {
20-
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
20+
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter
2121
};
2222

2323
const [] = React.useState(registerBaseTests());
@@ -40,7 +40,7 @@ function App(): React.JSX.Element {
4040
/>
4141
<ScrollView style={backgroundStyle}>
4242
{/* <PowerSyncIndicator /> */}
43-
{rootSuite.suites.map(suite => (
43+
{rootSuite.suites.map((suite) => (
4444
<SuitWidget key={suite.title} suit={suite} />
4545
))}
4646
</ScrollView>

tools/powersynctests/src/tests/queries.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,36 @@ export function registerBaseTests() {
528528
await watched;
529529
});
530530

531+
it('Should reflect writeTransaction updates on read connections (iterator)', async () => {
532+
const watched = new Promise<void>(async (resolve) => {
533+
for await (const result of db.watchWithAsyncGenerator('SELECT COUNT(*) as count FROM users', [])) {
534+
if (result.rows?.item(0).count == 1) {
535+
resolve();
536+
}
537+
}
538+
});
539+
540+
await db.writeTransaction(async (tx) => {
541+
return createTestUser(tx);
542+
});
543+
544+
// The watched query should have updated
545+
await watched;
546+
});
547+
548+
it('Should throw for async iterator watch errors', async () => {
549+
let error: Error | undefined;
550+
try {
551+
// The table here does not exist, so it should throw an error
552+
for await (const result of db.watchWithAsyncGenerator('SELECT COUNT(*) as count FROM faketable', [])) {
553+
}
554+
} catch (ex) {
555+
error = ex as Error;
556+
}
557+
558+
expect(error!.message).to.include('no such table: faketable');
559+
});
560+
531561
it('Should reflect writeLock updates on read connections ', async () => {
532562
const numberOfUsers = 1000;
533563

0 commit comments

Comments
 (0)