Skip to content

Commit 81a946a

Browse files
test
1 parent e13e2d5 commit 81a946a

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

packages/web/tests/crud.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('CRUD Tests', () => {
7979
expect(await powersync.get('SELECT count(*) AS count FROM assets')).deep.equals({ count: 1 });
8080

8181
// Make sure uniqueness is enforced
82-
expect(powersync.execute('INSERT INTO assets(id, description) VALUES(?, ?)', [testId, 'test3'])).rejects.toThrow(
82+
await expect(powersync.execute('INSERT INTO assets(id, description) VALUES(?, ?)', [testId, 'test3'])).rejects.toThrow(
8383
/UNIQUE constraint failed/
8484
);
8585
});
@@ -154,7 +154,7 @@ describe('CRUD Tests', () => {
154154

155155
it('UPSERT not supported', async () => {
156156
// Just shows that we cannot currently do this
157-
expect(
157+
await expect(
158158
powersync.execute('INSERT INTO assets(id, description) VALUES(?, ?) ON CONFLICT DO UPDATE SET description = ?', [
159159
testId,
160160
'test2',

packages/web/tests/stream.test.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,32 @@ describe('Streaming', () => {
147147
});
148148

149149
itWithGenerators('Should trigger upload connector when connected', async (createConnectedDatabase) => {
150+
console.log('connecting');
150151
const { powersync, uploadSpy } = await createConnectedDatabase();
152+
console.log('connected')
151153
expect(powersync.connected).toBe(true);
152154

153155
// do something which should trigger an upload
154156
await powersync.execute('INSERT INTO users (id, name) VALUES (uuid(), ?)', ['name']);
157+
console.log('executed a statement');
155158
// It should try and upload
156159
await vi.waitFor(
157160
() => {
158161
// to-have-been-called seems to not work after failing the first check
162+
console.log('number of calls, ', uploadSpy.mock.calls.length)
159163
expect(uploadSpy.mock.calls.length).equals(1);
160164
},
161165
{
162-
timeout: UPLOAD_TIMEOUT_MS
166+
timeout: UPLOAD_TIMEOUT_MS,
167+
interval: 500
163168
}
164169
);
165170

171+
console.log('disconnecting');
166172
await powersync.disconnectAndClear();
173+
console.log('disconnected');
167174
await powersync.close();
175+
console.log('closed');
168176
});
169177

170178
itWithGenerators('Should retry failed uploads when connected', async (createConnectedDatabase) => {
@@ -193,7 +201,8 @@ describe('Streaming', () => {
193201
expect(uploadSpy.mock.calls.length).equals(throwCounter + 1);
194202
},
195203
{
196-
timeout: UPLOAD_TIMEOUT_MS
204+
timeout: UPLOAD_TIMEOUT_MS,
205+
interval: 500
197206
}
198207
);
199208

@@ -202,29 +211,41 @@ describe('Streaming', () => {
202211
});
203212

204213
itWithGenerators('Should upload after reconnecting', async (createConnectedDatabase) => {
214+
console.log('connecting');
205215
const { connect, powersync, uploadSpy } = await createConnectedDatabase();
216+
console.log('connected');
206217
expect(powersync.connected).toBe(true);
207218

219+
console.log('disconnecting');
208220
await powersync.disconnect();
221+
console.log('disconnected');
209222

210223
// do something (offline) which should trigger an upload
211224
await powersync.execute('INSERT INTO users (id, name) VALUES (uuid(), ?)', ['name']);
212225

226+
console.log('connecting again');
213227
await connect();
228+
console.log('done connecting');
214229

215230
// It should try and upload
216231
await vi.waitFor(
217232
() => {
218233
// to-have-been-called seems to not work after failing a check
234+
console.log('upload has been called times: ', uploadSpy.mock.calls.length)
219235
expect(uploadSpy.mock.calls.length).equals(1);
220236
},
221237
{
222-
timeout: UPLOAD_TIMEOUT_MS
238+
timeout: UPLOAD_TIMEOUT_MS,
239+
interval: 500
223240
}
224241
);
225242

243+
console.log('cleanup');
244+
226245
await powersync.disconnectAndClear();
227246
await powersync.close();
247+
console.log('cleanup done');
248+
228249
});
229250

230251
itWithGenerators('Should update status when uploading', async (createConnectedDatabase) => {
@@ -253,7 +274,8 @@ describe('Streaming', () => {
253274
expect(powersync.currentStatus.dataFlowStatus.uploading).false;
254275
},
255276
{
256-
timeout: UPLOAD_TIMEOUT_MS
277+
timeout: UPLOAD_TIMEOUT_MS,
278+
interval: 500
257279
}
258280
);
259281

0 commit comments

Comments
 (0)