Skip to content

Commit

Permalink
compile worker only once
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensJourney committed Feb 1, 2024
1 parent 23e211a commit e591cdc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ jobs:
./scripts/install_sqlite.sh ${{ matrix.sqlite_version }} ${{ matrix.sqlite_url }}
mkdir -p assets && curl -LJ https://github.com/simolus3/sqlite3.dart/releases/download/sqlite3-2.3.0/sqlite3.wasm -o assets/sqlite3.wasm
- name: Compile WebWorker
run: dart compile -o assets/drift_worker.js -O0 lib/src/web/worker/drift_worker.dart

- name: Run Tests
run: |
Expand Down
31 changes: 15 additions & 16 deletions test/server/worker_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,24 @@ Future<void> hybridMain(StreamChannel<Object?> channel) async {

// Copy sqlite3.wasm file expected by the worker
final sqliteOutputPath = p.join(directory, 'sqlite3.wasm');
if (!(await File(sqliteOutputPath).exists())) {
await File('assets/sqlite3.wasm').copy(sqliteOutputPath);
}
await File('assets/sqlite3.wasm').copy(sqliteOutputPath);

final driftWorkerPath = p.join(directory, 'drift_worker.js');
if (!(await File(driftWorkerPath).exists())) {
// And compile worker code
final process = await Process.run(Platform.executable, [
'compile',
'js',
'-o',
driftWorkerPath,
'-O0',
'lib/src/web/worker/drift_worker.dart',
]);
if (process.exitCode != 0) {
fail('Could not compile worker');
}
// And compile worker code
final process = await Process.run(Platform.executable, [
'compile',
'js',
'-o',
driftWorkerPath,
'-O0',
'lib/src/web/worker/drift_worker.dart',
]);
if (process.exitCode != 0) {
fail('Could not compile worker');
}

print('compiled worker');

final server = await HttpServer.bind('localhost', 0);

final handler = const Pipeline()
Expand All @@ -45,6 +43,7 @@ Future<void> hybridMain(StreamChannel<Object?> channel) async {

channel.sink.add(server.port);
await channel.stream.listen(null).asFuture<void>().then<void>((_) async {
print('closing server');
await server.close();
await Directory(directory).delete();
});
Expand Down
14 changes: 6 additions & 8 deletions test/utils/web_test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,20 @@ class TestUtils extends AbstractTestUtils {
}

Future<void> _init() async {
final channel = spawnHybridUri('/test/server/worker_server.dart');
final channel = spawnHybridUri('/test/server/asset_server.dart');
final port = await channel.stream.first as int;
print('configure tests');
final sqliteWasmUri = Uri.parse('http://localhost:$port/sqlite3.wasm');

final sqliteWasmUri = 'http://localhost:$port/sqlite3.wasm';
// Cross origin workers are not supported, but we can supply a Blob
var sqliteDriftUri =
Uri.parse('http://localhost:$port/drift_worker.js').toString();
var sqliteDriftUri = 'http://localhost:$port/drift_worker.js';

print('Using $sqliteDriftUri and $sqliteDriftUri');
final blob = Blob(<String>['importScripts("$sqliteDriftUri");'],
'application/javascript');
sqliteDriftUri = _createObjectURL(blob);

webOptions = SqliteOptions(
webSqliteOptions: WebSqliteOptions(
wasmUri: sqliteWasmUri.toString(),
workerUri: sqliteDriftUri.toString()));
wasmUri: sqliteWasmUri.toString(), workerUri: sqliteDriftUri));
}

@override
Expand Down

0 comments on commit e591cdc

Please sign in to comment.