mirror of https://github.com/AMT-Cheif/drift.git
Basic support for running unit tests on web again
This commit is contained in:
parent
3db32be42b
commit
0984e52dc7
|
@ -175,7 +175,7 @@ class DriftProtocol {
|
|||
case _tag_ExecuteQuery:
|
||||
final method = StatementMethod.values[readInt(1)];
|
||||
final sql = fullMessage![2] as String;
|
||||
final args = fullMessage[3] as List;
|
||||
final args = (fullMessage[3] as List).map(_decodeDbValue).toList();
|
||||
final executorId = readNullableInt(4);
|
||||
return ExecuteQuery(method, sql, args, executorId);
|
||||
case _tag_ExecuteBatchedStatement:
|
||||
|
@ -251,6 +251,14 @@ class DriftProtocol {
|
|||
return variable;
|
||||
}
|
||||
}
|
||||
|
||||
Object? _decodeDbValue(Object? wire) {
|
||||
if (wire is List) {
|
||||
return wire.cast<int>();
|
||||
} else {
|
||||
return wire;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Message {}
|
||||
|
|
|
@ -15,7 +15,7 @@ dependencies:
|
|||
js: ^0.6.3
|
||||
meta: ^1.3.0
|
||||
stream_channel: ^2.1.0
|
||||
sqlite3: ^1.5.1
|
||||
sqlite3: ^1.6.0
|
||||
|
||||
dev_dependencies:
|
||||
build_test: ^2.0.0
|
||||
|
|
|
@ -164,7 +164,7 @@ void main() {
|
|||
await db
|
||||
.update(db.categories)
|
||||
.write(const CategoriesCompanion(description: Value('changed')));
|
||||
});
|
||||
}, onPlatform: needsAdaptionForWeb());
|
||||
|
||||
test('custom expressions can introduces new tables to watch', () async {
|
||||
final custom = CustomExpression<int>('1', watchedTables: [db.sharedTodos]);
|
||||
|
@ -174,5 +174,5 @@ void main() {
|
|||
|
||||
expect(stream, emitsInOrder([1, 1]));
|
||||
db.markTablesUpdated({db.sharedTodos});
|
||||
});
|
||||
}, onPlatform: needsAdaptionForWeb());
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
@TestOn('vm')
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:sqlite3/sqlite3.dart';
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
@Tags(['integration'])
|
||||
@TestOn('vm')
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift/isolate.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
@TestOn('vm') // because of skips.dart
|
||||
import 'package:drift/drift.dart' hide isNull;
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
@TestOn('vm') // because of skips.dart
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
|
|
|
@ -27,5 +27,5 @@ void main() {
|
|||
updates: someTables, updateKind: UpdateKind.update);
|
||||
|
||||
expect(await watchValue().first, 2);
|
||||
});
|
||||
}, onPlatform: needsAdaptionForWeb());
|
||||
}
|
||||
|
|
|
@ -34,6 +34,6 @@ void main() {
|
|||
throwsA(isA<StateError>().having((e) => e.message, 'message',
|
||||
contains("Can't re-open a database after closing it."))),
|
||||
);
|
||||
});
|
||||
}, onPlatform: needsAdaptionForWeb());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
@Tags(['integration'])
|
||||
@TestOn('vm')
|
||||
import 'package:drift/isolate.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
|
|
@ -27,5 +27,5 @@ void main() {
|
|||
..orderBy([(_) => OrderingTerm.random()]))
|
||||
.get();
|
||||
expect(rows.isSorted((a, b) => a.id.compareTo(b.id)), isFalse);
|
||||
});
|
||||
}, onPlatform: needsAdaptionForWeb());
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ import 'package:drift/drift.dart';
|
|||
import 'package:drift/remote.dart';
|
||||
import 'package:test/scaffolding.dart';
|
||||
|
||||
// At some point, we should use a `WasmDatabase` here since it was compiled
|
||||
// in a reasonable way and will be must more reliable than proxying to a VM,
|
||||
// but this is the easiest setup for now.
|
||||
DatabaseConnection testInMemoryDatabase() {
|
||||
return remote(spawnHybridUri('/test/test_utils/sqlite_server.dart'));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
import 'package:test/test.dart';
|
||||
|
||||
export 'database_stub.dart'
|
||||
if (dart.library.ffi) 'database_vm.dart'
|
||||
if (dart.library.js) 'database_web.dart';
|
||||
export 'matchers.dart';
|
||||
export 'mocks.dart';
|
||||
|
||||
Map<String, dynamic> needsAdaptionForWeb() {
|
||||
return const {
|
||||
'browser': Skip('TODO: This test needs adaptions to work on the web.')
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue