Basic support for running unit tests on web again

This commit is contained in:
Simon Binder 2022-04-03 00:39:13 +02:00
parent 3db32be42b
commit 0984e52dc7
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
13 changed files with 31 additions and 7 deletions

View File

@ -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 {}

View File

@ -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

View File

@ -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());
}

View File

@ -1,3 +1,4 @@
@TestOn('vm')
import 'package:drift/drift.dart';
import 'package:drift/native.dart';
import 'package:sqlite3/sqlite3.dart';

View File

@ -1,4 +1,5 @@
@Tags(['integration'])
@TestOn('vm')
import 'package:drift/drift.dart';
import 'package:drift/isolate.dart';
import 'package:test/test.dart';

View File

@ -1,3 +1,4 @@
@TestOn('vm') // because of skips.dart
import 'package:drift/drift.dart' hide isNull;
import 'package:test/test.dart';

View File

@ -1,3 +1,4 @@
@TestOn('vm') // because of skips.dart
import 'package:drift/drift.dart';
import 'package:test/test.dart';

View File

@ -27,5 +27,5 @@ void main() {
updates: someTables, updateKind: UpdateKind.update);
expect(await watchValue().first, 2);
});
}, onPlatform: needsAdaptionForWeb());
}

View File

@ -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());
}
}

View File

@ -1,4 +1,5 @@
@Tags(['integration'])
@TestOn('vm')
import 'package:drift/isolate.dart';
import 'package:rxdart/rxdart.dart';
import 'package:test/test.dart';

View File

@ -27,5 +27,5 @@ void main() {
..orderBy([(_) => OrderingTerm.random()]))
.get();
expect(rows.isSorted((a, b) => a.id.compareTo(b.id)), isFalse);
});
}, onPlatform: needsAdaptionForWeb());
}

View File

@ -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'));
}

View File

@ -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.')
};
}