Skip to content

Commit 3b5bdfc

Browse files
use getSourceTables test for both web and native
1 parent 1116795 commit 3b5bdfc

File tree

5 files changed

+61
-36
lines changed

5 files changed

+61
-36
lines changed

lib/src/web/web_sqlite_open_factory.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ Map<String, FutureOr<WebSqlite>> webSQLiteImplementations = {};
1212
/// Web implementation of [AbstractDefaultSqliteOpenFactory]
1313
class DefaultSqliteOpenFactory
1414
extends AbstractDefaultSqliteOpenFactory<CommonDatabase> {
15-
// todo: For users with multiple databases, the WebSqlite should be shared
16-
// between the different paths.
1715
final Future<WebSqlite> _initialized;
1816

1917
DefaultSqliteOpenFactory(

test/native/watch_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ void main() {
2121
await testUtils.cleanDb(path: path);
2222
});
2323

24+
generateSourceTableTests(testUtils.findSqliteLibraries(), () => path);
25+
2426
test('watch in isolate', () async {
2527
final db = await testUtils.setupDatabase(path: path);
2628
await createTables(db);

test/utils/web_test_utils.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class TestUtils extends AbstractTestUtils {
5858

5959
@override
6060
List<String> findSqliteLibraries() {
61-
// Maintains consistency with native tests
6261
return ['sqlite3.wasm'];
6362
}
6463
}

test/watch_test.dart

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,50 @@ createTables(SqliteDatabase db) async {
2121
});
2222
}
2323

24-
void main() {
25-
group('Query Watch Tests', () {
26-
late String path;
27-
List<String> sqlitePaths = [];
24+
// Web and native have different requirements for `sqlitePaths`.
25+
void generateSourceTableTests(
26+
List<String> sqlitePaths, String Function() getPath) {
27+
for (var sqlite in sqlitePaths) {
28+
test('getSourceTables - $sqlite', () async {
29+
final db = SqliteDatabase.withFactory(
30+
await testUtils.testFactory(path: getPath(), sqlitePath: sqlite));
31+
await db.initialize();
32+
await createTables(db);
2833

29-
setUp(() async {
30-
path = testUtils.dbPath();
31-
sqlitePaths = testUtils.findSqliteLibraries();
32-
await testUtils.cleanDb(path: path);
33-
});
34+
var versionRow = await db.get('SELECT sqlite_version() as version');
35+
print('Testing SQLite ${versionRow['version']} - $sqlite');
3436

35-
for (var sqlite in sqlitePaths) {
36-
test('getSourceTables - $sqlite', () async {
37-
final db = SqliteDatabase.withFactory(
38-
await testUtils.testFactory(path: path, sqlitePath: sqlite));
39-
await db.initialize();
40-
await createTables(db);
37+
final tables = await getSourceTables(db,
38+
'SELECT * FROM assets INNER JOIN customers ON assets.customer_id = customers.id');
39+
expect(tables, equals({'assets', 'customers'}));
4140

42-
var versionRow = await db.get('SELECT sqlite_version() as version');
43-
print('Testing SQLite ${versionRow['version']} - $sqlite');
41+
final tables2 = await getSourceTables(db,
42+
'SELECT count() FROM assets INNER JOIN "other_customers" AS oc ON assets.customer_id = oc.id AND assets.make = oc.name');
43+
expect(tables2, equals({'assets', 'other_customers'}));
4444

45-
final tables = await getSourceTables(db,
46-
'SELECT * FROM assets INNER JOIN customers ON assets.customer_id = customers.id');
47-
expect(tables, equals({'assets', 'customers'}));
45+
final tables3 = await getSourceTables(db, 'SELECT count() FROM assets');
46+
expect(tables3, equals({'assets'}));
4847

49-
final tables2 = await getSourceTables(db,
50-
'SELECT count() FROM assets INNER JOIN "other_customers" AS oc ON assets.customer_id = oc.id AND assets.make = oc.name');
51-
expect(tables2, equals({'assets', 'other_customers'}));
48+
final tables4 =
49+
await getSourceTables(db, 'SELECT count() FROM assets_alias');
50+
expect(tables4, equals({'assets'}));
5251

53-
final tables3 = await getSourceTables(db, 'SELECT count() FROM assets');
54-
expect(tables3, equals({'assets'}));
52+
final tables5 =
53+
await getSourceTables(db, 'SELECT sqlite_version() as version');
54+
expect(tables5, equals(<String>{}));
55+
});
56+
}
57+
}
5558

56-
final tables4 =
57-
await getSourceTables(db, 'SELECT count() FROM assets_alias');
58-
expect(tables4, equals({'assets'}));
59+
void main() {
60+
// Shared tests for watch
61+
group('Query Watch Tests', () {
62+
late String path;
5963

60-
final tables5 =
61-
await getSourceTables(db, 'SELECT sqlite_version() as version');
62-
expect(tables5, equals(<String>{}));
63-
});
64-
}
64+
setUp(() async {
65+
path = testUtils.dbPath();
66+
await testUtils.cleanDb(path: path);
67+
});
6568

6669
test('watch', () async {
6770
final db = await testUtils.setupDatabase(path: path);

test/web/watch_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@TestOn('browser')
2+
import 'package:test/test.dart';
3+
4+
import '../utils/test_utils_impl.dart';
5+
import '../watch_test.dart';
6+
7+
final testUtils = TestUtils();
8+
9+
void main() {
10+
// Shared tests for watch
11+
group('Web Query Watch Tests', () {
12+
late String path;
13+
14+
setUp(() async {
15+
path = testUtils.dbPath();
16+
await testUtils.cleanDb(path: path);
17+
});
18+
19+
/// Can't use testUtils instance here since it requires spawnHybridUri
20+
/// which is not available when declaring tests
21+
generateSourceTableTests(['sqlite3.wasm'], () => path);
22+
});
23+
}

0 commit comments

Comments
 (0)