mirror of https://github.com/AMT-Cheif/drift.git
Add integration tests for web migrations
This commit is contained in:
parent
d1d2b7ffe5
commit
54e205af51
|
@ -162,6 +162,17 @@ class DriftWebDriver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> setSchemaVersion(int version) async {
|
||||||
|
final result = await driver.executeAsync(
|
||||||
|
'set_schema_version(arguments[0], arguments[1])',
|
||||||
|
[version.toString()],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result != true) {
|
||||||
|
throw 'Could not set schema version';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> deleteDatabase(WebStorageApi storageApi, String name) async {
|
Future<void> deleteDatabase(WebStorageApi storageApi, String name) async {
|
||||||
await driver.executeAsync('delete_database(arguments[0], arguments[1])', [
|
await driver.executeAsync('delete_database(arguments[0], arguments[1])', [
|
||||||
json.encode([storageApi.name, name]),
|
json.encode([storageApi.name, name]),
|
||||||
|
|
|
@ -12,5 +12,13 @@ class TestDatabase extends _$TestDatabase {
|
||||||
TestDatabase(super.e);
|
TestDatabase(super.e);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get schemaVersion => 1;
|
MigrationStrategy get migration => MigrationStrategy(
|
||||||
|
onUpgrade: (m, from, to) async {
|
||||||
|
await into(testTable).insert(
|
||||||
|
TestTableCompanion.insert(content: 'from onUpgrade migration'));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
int schemaVersion = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,11 @@ enum Browser {
|
||||||
|
|
||||||
Future<Process> spawnDriver() async {
|
Future<Process> spawnDriver() async {
|
||||||
return switch (this) {
|
return switch (this) {
|
||||||
firefox => Process.start('geckodriver', []),
|
firefox => Process.start('geckodriver', []).then((result) async {
|
||||||
|
// geckodriver seems to take a while to initialize
|
||||||
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
|
return result;
|
||||||
|
}),
|
||||||
chrome =>
|
chrome =>
|
||||||
Process.start('chromedriver', ['--port=4444', '--url-base=/wd/hub']),
|
Process.start('chromedriver', ['--port=4444', '--url-base=/wd/hub']),
|
||||||
};
|
};
|
||||||
|
@ -156,6 +160,20 @@ void main() {
|
||||||
final finalImpls = await driver.probeImplementations();
|
final finalImpls = await driver.probeImplementations();
|
||||||
expect(finalImpls.existing, isEmpty);
|
expect(finalImpls.existing, isEmpty);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('migrations', () async {
|
||||||
|
await driver.openDatabase(entry);
|
||||||
|
await driver.insertIntoDatabase();
|
||||||
|
await driver.waitForTableUpdate();
|
||||||
|
|
||||||
|
await driver.closeDatabase();
|
||||||
|
await driver.driver.refresh();
|
||||||
|
|
||||||
|
await driver.setSchemaVersion(2);
|
||||||
|
await driver.openDatabase(entry);
|
||||||
|
// The migration adds a row
|
||||||
|
expect(await driver.amountOfRows, 2);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
group(
|
group(
|
||||||
|
|
|
@ -18,6 +18,7 @@ TestDatabase? openedDatabase;
|
||||||
StreamQueue<void>? tableUpdates;
|
StreamQueue<void>? tableUpdates;
|
||||||
|
|
||||||
InitializationMode initializationMode = InitializationMode.none;
|
InitializationMode initializationMode = InitializationMode.none;
|
||||||
|
int schemaVersion = 1;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
_addCallbackForWebDriver('detectImplementations', _detectImplementations);
|
_addCallbackForWebDriver('detectImplementations', _detectImplementations);
|
||||||
|
@ -32,6 +33,10 @@ void main() {
|
||||||
initializationMode = InitializationMode.values.byName(arg!);
|
initializationMode = InitializationMode.values.byName(arg!);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
_addCallbackForWebDriver('set_schema_version', (arg) async {
|
||||||
|
schemaVersion = int.parse(arg!);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
_addCallbackForWebDriver('delete_database', (arg) async {
|
_addCallbackForWebDriver('delete_database', (arg) async {
|
||||||
final result = await WasmDatabase.probe(
|
final result = await WasmDatabase.probe(
|
||||||
sqlite3Uri: sqlite3WasmUri,
|
sqlite3Uri: sqlite3WasmUri,
|
||||||
|
@ -158,7 +163,8 @@ Future<void> _open(String? implementationName) async {
|
||||||
connection = result.resolvedExecutor;
|
connection = result.resolvedExecutor;
|
||||||
}
|
}
|
||||||
|
|
||||||
final db = openedDatabase = TestDatabase(connection);
|
final db =
|
||||||
|
openedDatabase = TestDatabase(connection)..schemaVersion = schemaVersion;
|
||||||
|
|
||||||
// Make sure it works!
|
// Make sure it works!
|
||||||
await db.customSelect('SELECT database_host()').get();
|
await db.customSelect('SELECT database_host()').get();
|
||||||
|
|
Loading…
Reference in New Issue